section .data STDIN: EQU 0 STDOUT: EQU 1 STDERR: EQU 2 SYS_READ: EQU 0 SYS_WRITE: EQU 1 ; Because my memory is not working ; x /11g $rsp section .bss PRINT_INT_buffer resb 16 section .text global PRINT_INT PRINT_INT: ; this is a leaf routine, so we don't need to mess with the stack. ; Parameter: rdi, the number to print mov rax, rdi lea edi, [PRINT_INT_buffer + 15] mov byte [edi], 0x0A PRINT_INT_convert: dec edi ; edi scratch mov edx, 0 ; edx scratch mov ecx, 10 ; ecx scratch div ecx ; eax = edx:eax/ecx edx = edx:eax%ecx ; carter page 44 add dl, '0' ; dl + '0' add ascii 0 to the digit mov [edi], dl ; store the new character in edi buffer[14] = digit test eax, eax ; check for any bits of eax not zero ; carter page 51 jnz PRINT_INT_convert mov esi, edi ; edi needs the start position of the string. lea edx, [PRINT_INT_buffer+16] ; edx needs the length of the string ; the last character in the buffer. sub edx, edi ; starting poisition - end position mov eax, SYS_WRITE mov edi, STDOUT ; set the destination to stdout syscall ret