Skip to content

Instantly share code, notes, and snippets.

@Allen-B1
Last active October 24, 2018 01:45
Show Gist options
  • Save Allen-B1/409986367c07fc74de965829515fd1d8 to your computer and use it in GitHub Desktop.
Save Allen-B1/409986367c07fc74de965829515fd1d8 to your computer and use it in GitHub Desktop.
Write integer to stdout in assembly
; 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