; ifflt_64.asm code ifflt_64.c for nasm ; /* ifflt_64.c an 'if' statement that will be coded for nasm */ ; #include ; int main() ; { ; double a=1.0; ; double b=2.0; ; double c=3.0; ; printf("a=%f b=%f c=%f \n",a,b,c) ; if(ac) ; printf("wrong on b > c \n"); ; else ; printf("false b > c \n"); ; return 0; ;} ; result of executing both "C" and assembly is: ; true a < b ; false b > c ;; to make code like "C" ;; do opposite compare, if this true jump to false ;; do code for true ;; jump to exit ;; false label: ;; do code for false, the else part ;; exit label: ;; ;; You may to the compare, if true jump to code for true ;; do code for false, jump to exit global main ; define for linker extern printf ; tell linker we need this C function section .data ; Data section, initialized variables a: dq 1.0 ; "C" double b: dq 2.0 c: dq 3.0 fmtabc: db "a=%f b=%f c=%f", 10, 0 fmtlt: db "true a < b ",10,0 fmtgt: db "true a > b ",10,0 fmtle: db "true a <= b ",10,0 fmtge: db "true a >= b ",10,0 fmtteq: db "true a == a ",10,0 fmttne: db "true a != b ",10,0 fmt2: db "wrong on a < b ",10,0 fmt3: db "wrong on b > c ",10,0 fmt4: db "false b > c ",10,0 section .text main: push rbp ; set up stack mov rdi,fmtabc movq xmm0,qword[a] movq xmm1,qword[b] movq xmm2,qword[c] mov rax,3 ; three doubles call printf fld qword [b] ; b into st0 fld qword [a] ; a into st0, pushes b into st1 fcompp ; compare and pop both jl falselt ; choose jump to false part ; a < b sign is set mov rdi, fmtlt ; printf("true a < b \n"); mov rax, 0 call printf jmp exitlt ; jump over false part falselt: ; a < b is false mov rdi, fmt2 ; printf("wrong on a < b \n"); mov rax, 0 call printf exitlt: ; finished 'if lt' statement fld qword [c] ; c into st0 fld qword [b] ; b into st0, pushes c into st1 fcompp ; compare and pop both jg falsegt ; choose jump to false part ; b > c sign is not set mov rdi, fmt3 ; printf("wrong on b > c \n"); mov rax, 0 call printf jmp exitgt ; jump over false part falsegt: ; b > c is false mov rdi, fmt4 ; printf("false b > c \n"); mov rax, 0 call printf exitgt: ; finished 'if' statement pop rbp ; restore stack mov rax,0 ; normal, no error, return value ret ; return 0;