; ASM implementation of an if-else statement ; ; if (condition) then ; then_block ; else ; else_block ; 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, 4096 ; put test data in EAX mov ecx, 96 ; put test data in ECX cmp eax, ecx, ; compare jg else_block ; jump to else on true condition ; then block sub eax, ecx ; manipulate data call print_int ; 4096 - 96 = 4000 call print_nl jmp end_if ; jump over the else block to end it ; else block else_block: add eax, ecx ; manipulate data call print_int ; 4096 + 96 = 4192 call print_nl end_if: mov eax, 4097 ; Put data back in EAX to show end of if block call print_nl call print_int call print_nl ; 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