Add strcpy function
This commit is contained in:
parent
4057ac4bcc
commit
0d55f5cbf9
48
strcpy.S
Normal file
48
strcpy.S
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user