; ASM implementation of a while loop ; ; while (condition) { ; body ; } ; 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 ecx, 1 ; sum while: jo end_while ; end loop if OF flag is set ;body of loop mov eax, ecx ; move value to EAX to print call print_int ; print our value call print_nl add ecx, ecx ; add number jmp while ; continue loop end_while: dump_regs 0; ; verify OF flga ; 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