-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathyes.S
34 lines (32 loc) · 1.39 KB
/
yes.S
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
.text
.globl _start
_start:
pop %rcx # argc
loop arg # argc == 1 will cause no jump
noarg:
push $0x79 # place y\0 on stack
push %rsp # push then pop is 2 bytes, while movq is 3
push %rsp # garbage to be discarded
arg:
pop %rsi # Discard Program Name
pop %rsi # Get First Argument
lenloop:
incl %edx # Starts at 0 at prog start
cmpb %al, -1(%rsi,%rdx,1) # Check for end of string (al is 0)
jne lenloop
movb $10, -1(%rsi,%rdx,1) # Set the 0 to a newline (ASCII 10)
printloop:
incl %eax # Set eax to 1 = SYS_WRITE (started at 0)
# Perform the system call. At this point %rsi contains the string pointer
# %rdx contains the string length, %rdi contains 0 (STDOUT), as it was
# never set, and %rax contains 1 (SYS_WRITE)
syscall # Registers except %rax persist across call
subl %edx, %eax # Reset eax to 0, and check for failure
je printloop # on failure continue, else loop
# Exit program with status 130
push $60 # Push/pop is 3 bytes instead of 5
pop %rax
push $0xffffffffffffff82 # Don't care about upper bytes,
# so set them to 1 to get 2 byte push imm
pop %rdi
syscall