%include "IO_DEFS.asm" ; Because my memory is not working ; x /11g $rsp section .data limit dq 9 output db `The top of the stack was x\n` size equ $ - output section .bss section .text global _start _start: ; r10d will hold the address of the space to write to in the output buffer ; r8 will be used to push values onto the stack ;******************************************************** ;for(r8 = 9; r8 > 0; --r8) ; push(r8) ;******************************************************** mov r8, [limit] top_push_loop: push r8 dec r8 test r8, r8 jnz top_push_loop ; some book keeping for the loop. ; we don't need to do this every time in the loop. lea esi, [output] ; the base address of the string mov edx, size ; the size of the string mov edi, STDOUT ; destination lea r10d, [output+size-2] ;******************************************************** ; do ; r9 = pop() ; cout << "The top of the stack was " << r9 << endl; ; while r9 != 9 ;******************************************************** top_pop_loop: ; r9 will hold values removed from the stack ; bx will be used to convert the value to a character pop r9 ; convert this to ascii ; rdi holds the mov rbx, r9 add bl, '0' mov [r10d], bl ; print the value ; remember, eax gets overwritten by the number of characters read ; so it needs to be restored each time mov eax, SYS_WRITE syscall cmp r9, [limit] jne top_pop_loop ; Exit mov eax, SYS_EXIT mov edx, SUCCESS syscall