-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemcpy.asm
More file actions
46 lines (36 loc) · 820 Bytes
/
memcpy.asm
File metadata and controls
46 lines (36 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;;
;; EPITECH PROJECT, 2025
;; B-ASM-400-LYN-4-1-asmminilibc-spencer.pay
;; File description:
;; memcpy
;;
BITS 64
section .text
global memcpy
memcpy:
; Prologue: Save the base pointer and the rcx register
push rbp
mov rbp, rsp
push rcx ; Save rcx
; Set rax to the destination pointer (rdi)
mov rax, rdi
; If the length (rdx) is 0, jump to the end
cmp rdx, 0
je end
copy_loop:
; Copy byte from source (rsi) to destination (rdi)
mov cl, byte [rsi]
mov byte [rdi], cl
; Increment source and destination pointers
inc rsi
inc rdi
; Decrement the length counter
dec rdx
; If length counter is not zero, repeat the loop
jnz copy_loop
end:
; Epilogue
pop rcx ; Restore rcx
mov rsp, rbp
pop rbp
ret