We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,263 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

x86-64, Linux, NASM: FPU87 Stack

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.

3
Contributors
2
Replies
2 Weeks
Discussion Span
1 Year Ago
Last Updated
3
Views
jdelgado08
Newbie Poster
4 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

SantaClaus99
Newbie Poster
1 post since Mar 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

ActiveProfessor
Newbie Poster
1 post since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5135 seconds using 2.65MB