diff --git a/strcpy.S b/strcpy.S new file mode 100644 index 0000000..2796c29 --- /dev/null +++ b/strcpy.S @@ -0,0 +1,48 @@ + .intel_syntax noprefix + + .globl _start + + .text + + +# String-copying routine. +# Commented-out lines would also return the starting address of the destination address. +strcpy: +# push rsi +.loop: + movb r10b, [rdi] + cmpb r10b, 0 + je .end + movb [rsi], r10b + inc rdi + inc rsi + jmp .loop +.end: +# pop rax + ret + +_start: + + mov rdi, offset str2 + mov rsi, offset str1 + call strcpy + # mov rsi, rax -- would copy the string start address to rsi + + mov rax, 1 + mov rdi, 1 + mov rsi, offset str1 + mov rdx, 14 + syscall + + # exit + mov rax, 60 + mov rdi, 0 + syscall + + .bss +str1: + .skip 30 + + .data +str2: + .string "Hello, world!\n"