1,105,625 Community Members

x86-64, Linux, NASM: FPU87 Stack

Member Avatar
jdelgado08
Newbie Poster
4 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello guys, i'm trying to compute the area of a triangle using the Floating-Point stack (FPU87), but i'm having an issue outputting my value.

I'm computing the area using Heron's formula:
T = sqrt{s * (s - a ) * (s - b) * (s - c) }
Note: s = (a+b+c) / 2

I'm outputting: s * (s - a ) * (s - b) * (s - c), from the FPU87 stack just to make sure it did the calculations correctly, but i'm getting "-nan". I know it means "not a number", but as a test I inputted a = 1.0, b = 2.0, & c = 3.0 & by these calculations it should just output 0; s = (6)/2 = 3... (3)(3-1)(3-2)(3-3) = (3)(2)(1)(0) = 0.

I did all the calculations on the FPU87 stack then i'm outputting the number like so:

;Copy the number in st0 to memory.
     mov qword rax, 0
     push rax
     push rax
     fstp tword [rsp];Pop what's in st0 to int memory [s * (s - a ) * (s - b) * (s - c)]
     fld tword [rsp]          ;Load the value back to FPU87 stack

;Ouput the "The area of the triangle is: " message
       mov qword rdi, stringformat                         
       mov qword rsi, thearea
       mov qword rax, 0             
       call printf
;
;Output the extended area number
       mov rdi, doubleoutputformat        
       mov qword rsi, [rsp]                
       mov qword rax, 0                   
       call printf    
;
       pop rax
       pop rax

The way i'm outputting the value is the same way I outputted a, b, & c after they were inputted, but for some reason after that whole calculation is done it outputs -nan.

Any help would be appreciated.
Thanks.

Member Avatar
SantaClaus99
Newbie Poster
1 post since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This is professor Holliday. This post has been logged and I am tracking your ip address.

ActiveProfessor
Newbie Poster
1 post since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

This is the real Professor Holiday and I am tracking both your IP address.
I am filing an investigative report to track you #######s down.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: