Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Convert number to string
# (number, buffer) => buffer
.type itoa, @function
itoa:
pushl %ebp
movl %esp, %ebp
movl $12, %edi
leal (%esp, %edi, 1), %ebx # buffer
movl 8(%esp), %eax # number
movl $0, %edi # counter
pushl $0x0
jmp itoa_loop
itoa_loop:
movl $0, %edx
movl $10, %ecx
div %ecx
addl $48, %edx
pushl %edx
movb (%esp), %cl
movb %cl, (%ebx, %edi, 1) # append byte to buffer
test %eax, %eax
je itoa_end
dec %edi
jmp itoa_loop
itoa_end:
leal (%ebx, %edi, 1), %eax # pointer to start of buffer
movl %ebp, %esp
popl %ebp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment