Compare commits
3 Commits
0d55f5cbf9
...
7498741388
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7498741388 | ||
![]() |
d23173c8de | ||
![]() |
5b95604383 |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.o
|
||||||
|
a.out
|
||||||
|
build
|
@ -1,8 +1,4 @@
|
|||||||
.intel_syntax noprefix
|
.include "lib/alloca.S"
|
||||||
|
|
||||||
.macro alloca size
|
|
||||||
sub rsp, \size
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
@ -1,3 +1,5 @@
|
|||||||
|
.include "lib/strcpy.S"
|
||||||
|
|
||||||
.intel_syntax noprefix
|
.intel_syntax noprefix
|
||||||
|
|
||||||
.globl _start
|
.globl _start
|
||||||
@ -5,22 +7,6 @@
|
|||||||
.text
|
.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:
|
_start:
|
||||||
|
|
||||||
mov rdi, offset str2
|
mov rdi, offset str2
|
5
lib/alloca.S
Normal file
5
lib/alloca.S
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.intel_syntax noprefix
|
||||||
|
|
||||||
|
.macro alloca size
|
||||||
|
sub rsp, \size
|
||||||
|
.endm
|
17
lib/strcpy.S
Normal file
17
lib/strcpy.S
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
.intel_syntax noprefix
|
||||||
|
|
||||||
|
.text
|
||||||
|
|
||||||
|
# String-copying routine. Strings should be null-terminated.
|
||||||
|
# Input: rdi = source string base, rsi = destination string base
|
||||||
|
# No check is done for buffer overflow.
|
||||||
|
strcpy:
|
||||||
|
movb r10b, [rdi]
|
||||||
|
cmpb r10b, 0
|
||||||
|
je .end
|
||||||
|
movb [rsi], r10b
|
||||||
|
inc rdi
|
||||||
|
inc rsi
|
||||||
|
jmp strcpy
|
||||||
|
.end:
|
||||||
|
ret
|
Loading…
Reference in New Issue
Block a user