Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text
- global _start
- %include "includes/print.asm" ; syscall to print to screen function
- %include "includes/leave.asm" ; syscall to exit program
- itoa:
- push ebp
- mov ebp, esp
- mov ebx, 0 ; i = 0
- itoa_start:
- mov esi, [ebp+8]
- mov edi, [ebp+12]
- xor edx, edx ; clear edx
- mov eax, esi
- mov ecx, 10 ; move 10 into ecx (divisor)
- div ecx ; div ecx (ex. 1234 / 10 = 1234.5)
- mov [ebp+8], eax
- add edx, '0' ; add '0' (48) to remainder to convert into ASCII (5 -> '5')
- mov [edi + ebx], dl
- cmp eax, 0 ; compare remainder (edx ex. .5) to 0
- je itoa_end ; if remainder == 0 jump to end label
- add ebx, 1 ; increase ebx value by 1
- jmp itoa_start
- itoa_end:
- add ebx, 1 ; increase ebx value by 1 for terminating string
- mov dword [edi + ebx], 0
- mov eax, edi
- mov esp, ebp
- pop ebp
- ret
- _start:
- push res
- push num
- call itoa
- pop ebx
- mov ecx, eax
- mov edx, 5
- call print ; print res string
- call leave
- section .data
- num dd 12345 ; Defining word num with value 12345
- section .bss
- res resd 6 ; Reserving double word of 6 for res variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement