; ASM implementation of 'loop' command (reverse loop) ; ; sum = 0 ; for (i = 10; i > 0; i--) ; sum += i; ; ; include directives global asm_main %include "../lib/asm_io.inc" segment .data ; DX directives (read only, static data) segment .bss ; RESX directives (writable data) segment .text asm_main: ; entry point (called from driver.c) ; instructions enter 0,0 ; Initialize register EBP pusha ; Push register contents to the stack ; mov eax, 0 ; eax is the sum mov ecx, 10 ; ecx is i loop_start: add eax, ecx ; sum += i call print_int ; print the values for feedback call print_nl ; loop loop_start ; if i > 0 then go to loop_start ; popa ; Restore register data from the stack mov eax, 0 ; flush EAX of data leave ; restore the stack ret ; Return from main back into C library wrapper