Created
April 18, 2014 01:45
-
-
Save psyomn/11020720 to your computer and use it in GitHub Desktop.
Simple asm
This file contains hidden or 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
| ; Me dicking around with 64bit nasm. Depending on the number of arguments given | |
| ; we print a number of dots. Does not do much, but should help the asm | |
| ; beginner just as it did me. | |
| ; | |
| ; author: Simon Symeonidis | |
| section .data | |
| message: db ". ", 0 | |
| nl: db 0xA | |
| counter: dd 0 | |
| section .bss | |
| section .text | |
| global _start | |
| _start: | |
| pop rax ; get argc | |
| mov [counter], rax | |
| .countdown: | |
| call print_dot | |
| ;; Decrease the counter | |
| mov eax, [counter] | |
| dec eax | |
| mov [counter], eax | |
| ;; check to see if done | |
| cmp eax, 0 | |
| jge .countdown | |
| call newline | |
| ; syscall - exit, ret 0 | |
| mov rax, 60 | |
| mov rdi, 0 | |
| syscall | |
| print_dot: | |
| mov eax, 4 | |
| mov ebx, 1 | |
| mov ecx, message | |
| mov edx, 3 | |
| int 80h | |
| ret | |
| newline: | |
| mov rax, 4 ;syscall - write | |
| mov rdi, 1 ;stdout | |
| mov ecx, nl ;message address | |
| mov edx, 1 ;length | |
| syscall | |
| ret | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment