Created
November 2, 2020 15:32
-
-
Save sebbekarlsson/8ea3ab60e41fb5a0d2a58338b65a332c 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
.section .data | |
divtable: | |
.long 100, 10, 1, 0 | |
.section .bss | |
.lcomm buffer, 16 | |
.section .text | |
.globl _start | |
_start: | |
pushl $256 | |
call to_str | |
addl $4, %esp | |
movl $1, %eax | |
movl $0, %ebx | |
int $0x80 | |
.type to_str, @function | |
to_str: | |
pushl %ebp | |
movl %esp, %ebp | |
movl $0, %edi | |
movl divtable, %edx | |
movl 8(%esp), %eax | |
pushl $0x0 | |
jmp to_str_loop | |
to_str_loop: | |
movl divtable(, %edi, 4), %ebx | |
cmpl $3, %edi | |
jge to_str_end | |
movl $0, %edx | |
div %ebx | |
cmpl $0, %eax | |
jle to_str_end | |
addl $48, %eax | |
pushl %eax | |
cmpl $0, %edx | |
jle to_str_end | |
movl %edx, %eax | |
jmp to_str_next | |
to_str_next: | |
addl $1, %edi | |
jmp to_str_loop | |
to_str_end: | |
jmp strcpy | |
strcpy: | |
movl %esp, %esi | |
movl $buffer, %edi | |
jmp strcpy_loop | |
strcpy_loop: | |
movb (%esi), %al | |
movb %al, (%edi) | |
addl $4, %esi | |
incl %edi | |
test %al, %al | |
jnz strcpy_loop | |
jmp strcpy_end | |
strcpy_end: | |
movl %ebp, %esp | |
popl %ebp | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment