[英]How to write an expression in assembly with no operands?
I'm trying to write this expression A = (B × (C + D × (E × F))) ÷ (E × (C + D)) using an instruction set where each instruction has no operands (except for the two that must have one each). 我正在尝试使用一个指令集来编写此表达式A =(B×(C + D×(E×F)))÷(E×(C + D)),其中每个指令都没有操作数(两个指令除外)每个必须有一个)。
This is an example from the book that I've followed: The expression is z = x * y + w * u 这是我遵循的书中的一个示例:表达式为z = x * y + w * u
The code: 编码:
PUSH x
PUSH y
MULT
PUSH w
PUSH u
MULT
ADD
STORE z
What I have done: 我做了什么:
PUSH E
PUSH F
MULT
PUSH D
MULT
PUSH C
ADD
PUSH B
MULT
STORE Z (store the result)
PUSH C
PUSH D
ADD
PUSH E
MULT
PUSH Z
DIVIDE
STORE A
I'm not sure about the way that I stored the result in and the division seems incorrect. 我不确定存储结果的方式,并且该划分似乎不正确。 Is there a better way to write the expression?
有没有更好的方式编写表达式?
Updated: 更新:
PUSH C
PUSH D
ADD
PUSH E
MULT
PUSH E
PUSH F
MULT
PUSH D
MULT
PUSH C
ADD
PUSH B
MULT
DIVIDE
STORE A
You don't need Z
: calculate Ex(C+D)
, then calculate (B×(C+D×(E×F)))
; 您不需要
Z
:计算Ex(C+D)
, 然后计算(B×(C+D×(E×F)))
; now you have the values you need for the final division, which can then be stored in A
. 现在您有了最终除法所需的值,然后可以将其存储在
A
。 In fact, except for avoiding redundant calculations, you should never need to use STORE
until the very end. 实际上,除了避免多余的计算之外,您永远都不需要使用
STORE
。
If your division is incorrect (you don't specify what assembly language this is, so I can't tell), then most likely you have the arguments backwards. 如果您的除法不正确(您没有指定这是什么汇编语言,那么我就无法告诉您),那么很可能您会将参数反过来了。 In that case, you'd want to leave out the first
STORE Z
and the PUSH Z
. 在这种情况下,您可能要忽略第一个
STORE Z
和PUSH Z
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.