Last active
October 24, 2018 01:45
-
-
Save Allen-B1/409986367c07fc74de965829515fd1d8 to your computer and use it in GitHub Desktop.
Write integer to stdout in assembly
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
; usage | |
; mov eax, NUMBER | |
; call writeint | |
writeint: | |
mov ecx, 10 | |
.pushloop: | |
mov ebx, 10 | |
xor edx, edx | |
div ebx | |
push edx | |
loop .pushloop | |
mov ecx, 10 | |
.poploop: | |
pop eax | |
add eax, '0' | |
push ecx | |
push eax | |
mov eax, 4 | |
mov ebx, 1 | |
mov ecx, esp | |
mov edx, 1 | |
int 0x80 | |
pop eax | |
pop ecx | |
loop .poploop | |
.newline: | |
; print newline | |
mov eax, `\n` | |
push eax | |
mov eax, 4 | |
mov ebx, 1 | |
mov ecx, esp | |
mov edx, 1 | |
int 0x80 | |
pop eax | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment