计算汇编代码中的表达式

问题描述

我写了一个汇编代码来计算下面公式中提到的面积

enter image description here

我觉得代码过于复杂了。如果可以以更简单的方式完成相同的操作,则需要建议。 我计算 5 的 sqrt 比 mul 乘以 2。每件事都在单独的一行中完成。
有没有办法用一行或更短的方式做到这一点

INCLUDE Irvine32.inc


.data
testString BYTE "test",0

invalidValueString BYTE "invalid value entered for length of edge!",0
enterEdgeLength BYTE "Enter the length of the edge e : ",0
areaString BYTE "Area : ",0
volumeString BYTE "Volume : ",0
radiusString  BYTE "Midsphere Radius : ",0
edgeLength real4 ?
five real4 5.0
four real4 4.0
two real4 2.0
six real4 6.0
three real4 3.0
fortySeven real4 47.0
ninetyNine  real4 99.0
twelve real4 12.0


.code

call crlf

start:
mov edx,offset enterEdgeLength
call writestring
call readfloat            ; reads the edge length into ST(0)
fstp edgeLength           ; edgeLength variable will contain the length entered
cmp edgeLength,0         ; comparing with 0 
jl negativeValue          ; if it's less than 0 print error msg and loop to start
cmp edgeLength,0
je stop                   ; if length entered is 0 exit the program
jmp properValue

negativeValue: 
     mov edx,offset invalidValueString   
     call writestring
     call crlf
     jmp start
properValue:                   ; call each method one by one to calculate
    call area                  ; area,volume and radius
    call volume 
    call radius
    call crlf
    fstp ST(0)                 ; clear the stack before looping again
    jmp start
    stop:
    exit

area proc
finit                     
fld five                ; calculating the constant that is to be multiplied
fsqrt                   ; with edgelength squared
fmul two
fld five
fadd
fsqrt
fmul six
fld three
fsqrt
fadd
fmul five
                        ; the constant expression is in ST(0)
fmul edgeLength              
fmul edgeLength         ; multiply the edgelength squared to ST(0) to get area

call crlf
mov edx,offset areaString
call writestring
call writefloat
fstp ST(0)
area endp

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...