.section .data newline: .asciz "\n" .section .text /* esp - stack pointer eax - number we want to print ebx - memory address of the current character ecx - 10 (the base of the number as we intend to print it) edx - used for part of the operand in division, also the reminder saved instruction pointer ---- esp started here 4 3 2 1 ----- esp after enlarging the stack, final value of ebx */ /* Beginning of print_number function */ .global print_number print_number: movl $10, %ecx movl %esp, %ebp char_loop_top: /* Put one ascii character in memory */ subl $1, %esp movl $0, %edx div %ecx add $48, %edx movb %dl, (%esp) /* Set up for the next iteration */ cmp $0, %eax jne char_loop_top /* Call write to print out our number */ movl $4, %eax movl $1, %ebx movl %esp, %ecx movl %ebp, %edx subl %esp, %edx int $0x80 /* Call write to write a newline */ movl $4, %eax movl $1, %ebx movl $newline, %ecx movl $1, %edx int $0x80 /* Restore the stack pointer and return */ mov %ebp, %esp ret /* End of print_number function */