; =================================================================== ; Program: if_then_else_v1_nasm.asm ; Date: July 2020 ; Author: Jean-Michel Richer ; Email: jean-michel.richer@univ-angers.fr ; =================================================================== ; Description: ; This program shows how to code a if-then-else statement ; ; =================================================================== global main extern printf ; =================================================================== ; ##### ## ##### ## ; # # # # # # # ; # # # # # # # ; # # ###### # ###### ; # # # # # # # ; ##### # # # # # ; =================================================================== section .data a: dd 1 b: dd 2 msg_inf: db "a < b", 10, 0 msg_supe: db "a >= b", 10, 0 ; =================================================================== ; #### #### ##### ###### ; # # # # # # # ; # # # # # ##### ; # # # # # # ; # # # # # # # ; #### #### ##### ###### ; =================================================================== section .text ; ------------------------------------------------------------------- ; SUBPROGRAM ; ; int main(int argc, char *argv[]) ; ; DESCRIPTION ; ; Main subprogram that compares variables 'a' and 'b' ; ; PARAMETERS ; ; argc int number of arguments of the program ; argv char *[] array of arguments as strings ; ; RETURN VALUE ; ; 0 if everything is ok, ; >0 if error ; ; VARIABLES / REGISTERS ; ; a int first operand eax ; b int second operand ebx ; ; ------------------------------------------------------------------- main: push ebp mov ebp, esp push ebx mov eax, [a] mov ebx, [b] .if: cmp eax, ebx jge .else .then: push dword msg_inf call printf add esp, 4 jmp .endif .else: push dword msg_supe call printf add esp, 4 .endif: pop ebx xor eax, eax ; 0 of return 0 mov esp, ebp pop ebp ret