0

I am trying to find the surface area using this equation. A = 6*a*h+3*sqrt(3)*a^2 I do not fully understand how co-processor instructions actually work.

Here is currently by subprogram

enter       8,0
mov         [ebp-4],dword 2 ; Coprocessor instructions only work with
                            ; memory addresses. So we will store the number
                            ; 2 in a local variable on the stack (which
                            ; is the address ebp-4).

mov         [ebp-8],dword 6 ; ebp-8 = 6

;A = 6*a*h+3*sqrt(3)*a^2 where a is the base edge and h is height
fld         qword[ebp+8]    ; ST0 = a
fld         qword[ebp+16]   ; ST1 = a; ST0 = h
fmulp       st1     ; ST0 = h*a
mov         [ebp-8],dword 6 
fild        dword[ebp-8]        ; ST1 = h*a; ST0 = 6
fmulp       st1,st0     ; ST0 = h*a*6

fld         dword[ebp+8]    ; ST0 = a
fmul            st0                 ; ST0 = a^2
fild            dword[ebp-8]    ; ST1 = (a^2); ST0 = 3
fld         st0                 ; ST2 = (a^2); ST1 = 3; ST0 = 3   
fsqrt                               ; ST2 = (a^2); ST1 = 3; ST0 = sqrt(3)
fmulp       st1                 ; ST1 = (a^2); ST0 = 3*sqrt(3)
fmulp       st1                 ; ST0 = ((a^2)*3*sqrt(3)

I am looking for a better understanding on how I want to go about this and can you tell me what I am doing wrong

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
21 Average
  • 27
  • 7
  • https://stackoverflow.com/tags/x86/info has a link to a good x87 tutorial: http://www.ray.masmcode.com/tutorial/index.html. You should simplify this and do `3*sqrt(3)` by hand, putting the result in a constant. No need to do extra sqrt and multiply at runtime; think like a compiler. – Peter Cordes Dec 03 '19 at 07:38
  • What is the question/problem ? – dash-o Dec 05 '19 at 06:21

0 Answers0