Assembly 用汇编语言求六角棱镜的表面积
我试着用这个方程求表面积。A=6*A*h+3*sqrt(3)*A^2 我不完全理解协处理器指令实际上是如何工作的 这里是当前由子程序生成的Assembly 用汇编语言求六角棱镜的表面积,assembly,x86,floating-point,x87,sasm,Assembly,X86,Floating Point,X87,Sasm,我试着用这个方程求表面积。A=6*A*h+3*sqrt(3)*A^2 我不完全理解协处理器指令实际上是如何工作的 这里是当前由子程序生成的 enter 8,0 mov [ebp-4],dword 2 ; Coprocessor instructions only work with ; memory addresses. So we will store the number
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)
我希望能更好地理解我想做什么,你能告诉我我做错了什么吗有一个指向好的x87教程的链接:。您应该简化此过程,并手动执行
3*sqrt(3)
,将结果放入常量中。无需在运行时执行额外的sqrt和乘法;像编译器一样思考。问题是什么?