如何解决计算汇编代码中的表达式
我觉得代码过于复杂了。如果可以以更简单的方式完成相同的操作,则需要建议。
我计算 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 举报,一经查实,本站将立刻删除。