; File: double4.asm ; ; Using C printf function to print double values ; Checking out floating point arithmetic ; ; Declare some external functions ; extern printf ; the C function, we'll call SECTION .data ; Data section msg: db "Answer: %f", 10, 0 ; The string to print. 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 sub esp, 8 push DWORD msg ; address of ctrl string fld QWORD [dv1] fld QWORD [dv2] fadd st0, st1 ; floating point add fstp QWORD [esp+4] call printf ; Call C function ; note that 1.111 is still on the FPU stack fld QWORD [dv3] fsubp st1, st0 ; st1 := st1 - st0, pop fstp QWORD [esp+4] call printf ; Call C function ; note that FPU stack is at bottom fld QWORD [dv3] fld QWORD [dv4] fmulp st1, st0 ; f.p. multiply + pop fstp QWORD [esp+4] call printf fld QWORD [dv6] fld QWORD [dv3] fdivp st1, st0 ; f.p. divide + pop fstp QWORD [esp+4] call printf fld QWORD [dv7] fsqrt ; Compute the square root fstp QWORD [esp+4] call printf ; Call C function add esp, 12 ; pop 2 args from stack ; return from main mov esp, ebp ; takedown stack frame pop ebp ; same as "leave" op ret