From 0d55f5cbf933edc8751c33209d7f4b53fde6b13f Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 24 Jan 2025 18:49:33 +0000 Subject: [PATCH] Add strcpy function --- strcpy.S | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 strcpy.S 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"