1 ; ifint_64.asm code ifint_64.c for nasm 2 ; /* ifint_64.c an 'if' statement that will be coded for nasm */ 3 ; #include 4 ; int main() 5 ; { 6 ; long int a=1; 7 ; long int b=2; 8 ; long int c=3; 9 ; if(ac) 14 ; printf("wrong on b > c \n"); 15 ; else 16 ; printf("false b > c \n"); 17 ; return 0; 18 ;} 19 ; result of executing both "C" and assembly is: 20 ; true a < b 21 ; false b > c 22 23 global main ; define for linker 24 extern printf ; tell linker we need this C function 25 section .data ; Data section, initialized variables 26 00000000 0100000000000000 a: dq 1 27 00000008 0200000000000000 b: dq 2 28 00000010 0300000000000000 c: dq 3 29 00000018 747275652061203C20- fmt1: db "true a < b ",10,0 30 00000021 62200A00 31 00000025 77726F6E67206F6E20- fmt2: db "wrong on a < b ",10,0 32 0000002E 61203C2062200A00 33 00000036 77726F6E67206F6E20- fmt3: db "wrong on b > c ",10,0 34 0000003F 62203E2063200A00 35 00000047 66616C73652062203E- fmt4: db "false b > c ",10,0 36 00000050 2063200A00 37 38 section .text 39 00000000 55 main: push rbp ; set up stack 40 00000001 488B0425[00000000] mov rax,[a] ; a 41 00000009 483B0425[08000000] cmp rax,[b] ; compare a to b 42 00000011 7D11 jge false1 ; choose jump to false part 43 ; a < b sign is set 44 00000013 48BF- mov rdi, fmt1 ; printf("true a < b \n"); 45 00000015 [1800000000000000] 46 0000001D E8(00000000) call printf 47 00000022 EB0F jmp exit1 ; jump over false part 48 false1: ; a < b is false 49 00000024 48BF- mov rdi, fmt2 ; printf("wrong on a < b \n"); 50 00000026 [2500000000000000] 51 0000002E E8(00000000) call printf 52 exit1: ; finished 'if' statement 53 54 00000033 488B0425[08000000] mov rax,[b] ; b 55 0000003B 483B0425[10000000] cmp rax,[c] ; compare b to c 56 00000043 7E11 jle false2 ; choose jump to false part 57 ; b > c sign is not set 58 00000045 48BF- mov rdi, fmt3 ; printf("wrong on b > c \n"); 59 00000047 [3600000000000000] 60 0000004F E8(00000000) call printf 61 00000054 EB0F jmp exit2 ; jump over false part 62 false2: ; a < b is false 63 00000056 48BF- mov rdi, fmt4 ; printf("false b > c \n"); 64 00000058 [4700000000000000] 65 00000060 E8(00000000) call printf 66 exit2: ; finished 'if' statement 67 68 00000065 5D pop rbp ; restore stack 69 00000066 B800000000 mov rax,0 ; normal, no error, return value 70 0000006B C3 ret ; return 0;