Created
July 16, 2015 21:51
-
-
Save 1995eaton/abd3eb4e9f054d50a33d to your computer and use it in GitHub Desktop.
Argv printer in 64 bit assembly (System-V)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.intel_syntax noprefix | |
.text | |
.globl strlen; strlen: | |
xor rcx, rcx | |
mov rsi, rdi | |
jmp 0f | |
1: | |
inc rcx | |
0: | |
lodsb | |
test al, al | |
jne 1b | |
mov rax, rcx | |
ret | |
.globl puts; puts: | |
call strlen | |
mov rdx, rax | |
mov rsi, rdi | |
mov rax, 1 | |
mov rdi, 1 | |
syscall | |
mov rax, 1 | |
mov rsi, offset newline | |
mov rdx, 1 | |
syscall | |
ret | |
.globl _start; _start: | |
mov rdi, rsp | |
mov ecx, [rdi] | |
jmp 0f | |
1: | |
add rdi, 8 | |
push rdi | |
push rcx | |
mov rdi, [rdi] | |
call puts | |
pop rcx | |
pop rdi | |
dec ecx | |
0: | |
test ecx, ecx | |
jne 1b | |
mov rax, 60 | |
xor rdi, rdi | |
syscall | |
.section .rodata | |
newline: .byte '\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment