; File: double5.asm ; ; Using C printf function to print double values ; Checking out comparisons ; ; Declare some external functions ; extern printf ; the C function, we'll call SECTION .data ; Data section ; Strings to print msg1: db "dv2 > dv1", 10, 0 msg2: db "dv2 <= dv1", 10, 0 msg3: db "dv3 < dv2", 10, 0 msg4: db "dv3 >= dv2", 10, 0 msg5: db "dv5 == dv2 + dv4", 10, 0 msg6: db "dv5 != dv2 + dv4", 10, 0 dv1: dq 1.111 dv2: dq 2.222 dv3: dq -3.333 dv4: dq 4.444 dv5: dq 5.555 dv6: dq 6.666 dv7: dq 7.777 SECTION .text ; Code section. global main main: push ebp ; set up stack frame mov ebp,esp fld QWORD [dv1] fld QWORD [dv2] fcompp ; compare then 2x pop fstsw ax ; store status of comp test ax, 4500H ; logial AND jz st0_gt_st1 push DWORD msg2 call printf add esp, 4 jmp done1 st0_gt_st1: push DWORD msg1 call printf add esp, 4 done1: fld QWORD [dv2] fld QWORD [dv3] fcompp ; compare then 2x pop fstsw ax ; store status of comp test ax, 0100H ; logial AND jnz st0_lt_st1 ; note the 'n' in jnz push DWORD msg4 call printf add esp, 4 jmp done2 st0_lt_st1: push DWORD msg3 call printf add esp, 4 done2: fld QWORD [dv2] fld QWORD [dv4] faddp st1, st0 fld QWORD [dv5] fcompp fstsw ax test ax, 4000H ; logial AND jnz st0_eq_st1 ; note the 'n' in jnz push DWORD msg6 call printf add esp, 4 jmp done3 st0_eq_st1: push DWORD msg5 call printf add esp, 4 done3: ; return from main mov esp, ebp ; takedown stack frame pop ebp ; same as "leave" op ret