Created
November 9, 2020 18:11
-
-
Save sebbekarlsson/a0fbeda7fc107eabe0bfeb7d78be8a02 to your computer and use it in GitHub Desktop.
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
# 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