%include "IO_DEFS.asm" section .data message1 db "Enter a positive integer: " message1_length equ $ - message1 section .bss phrase resb 100 section .text global _start _start: ; prompt the user mov rax, SYS_WRITE mov rdi, STDOUT mov rsi, message1 mov rdx, message1_length syscall ;read a number mov rax, SYS_READ mov rdi, STDIN lea rsi, [phrase] mov rdx, 100 syscall ;eax will be the constructed number ;r9d will be the lcv ;r10 will be the address of the next character ;r10d will be the end address of the string ;r11 will be the character ; r8 = 0 ; r9 = start pos of string ; ; while r9 != 0 ; r8 = r8 * 10 ; load the character at the pos r9 into r11 ; add that to r8 ; subtract '0' from r8 ; increment r9 ; jump if r9 is not equal to r10 mov r9d, eax add r9d, -1 mov r11, 0 mov ecx, 10 mov eax, 0 lea r10, [phrase] top: mul ecx mov byte r11b, [r10] inc r10 sub r11, '0' add eax, r11d dec r9 test r9,r9 jnz top ; Exit mov eax, SYS_EXIT mov edx, SUCCESS syscall