I'm working on a homework assignment, and want to print a 80-bit double extended precision number via printf. The number is calculated by some scaling function and using gdb i see it calculates the right number. I point to the block of 10 bytes using a some pointer named var1 defined in section bss as: var1: rest 1 then var1 points to a block of 10 bytes in the memory.
So far i tried to push the 10 bytes into the stack and then printing the number with format %f or %lf, both failed to print the number, also i noticed using qword and pushing 4 bytes twice into the stack (part of the number worked well), but i'm required using tword definition.
scale_number:
push ebp ;; Pushing Base pointer (contains address of current activation frame
;; which is actually the return address of the caller) to the stack
mov ebp, esp ;; Overrides ebp value to Stack pointer's value which contains the
;; address of last used dword in the stack.
pushad ;; Push all significant registers (8 general purpose registers)
;; onto the stack (backup registers values)
mov ebx, [ebp + 12] ;; Upper bound
sub dword ebx, [ebp + 8] ;; Substruct ebx with the Lower bound
mov ecx, [ebp + 16] ;; get the pointer of the result contianer
finit
mov eax, dword [seed]
mul ebx
push eax
fild dword [esp]
add esp, 4
push 0x0000FFFF
fidiv dword [esp]
add esp, 4
fiadd dword [ebp + 8]
fstp tword [ecx]
ffree
popad
return_from_function ; macro for quiting the function
right now ecx points to var1
the rest of the code:
push dword var1
push 100
push 40
call scale_number
;; Floating point tester TWORD
sub esp, 10
mov ebx, 0
.loop4:
mov eax, [var1 + ebx]
mov [esp + ebx], eax
inc ebx
cmp ebx, 10
jne .loop4
push format_fp ;; using "%f" , 10, 0 as the format_fp
call printf
add esp, 14
jmp exit
the output i have is -0.000000, but my expected output is 80. something..
User contributions licensed under CC BY-SA 3.0