1

我是玛丽模拟器的新手。我知道如何在模拟器中添加,但不幸的是我不知道如何乘法。例如,我怎样才能为此输入代码: S=x*Y+z 在此先感谢

4

1 回答 1

0

您可以使用重复加法来实现乘法。

这是一个基本算法。

For positive integers use the algorithm:
    Result = Result - Multiplier
    Multiplicand = Multiplicand - 1
For negative integers use the algorithm:
    Result = Result + Multiplier
    Multiplicand = Multiplicand + 1

在伪代码中:

while Multiplicand != 0
    if Multiplicand > 0
        Result = Result - Multiplier
        Multiplicand = Multiplicand - 1
    else
        Result = Result + Multiplier
        Multiplicand = Multiplicand + 1

这需要两个变量来保存乘数和被乘数。JNS此外,您可以使用(Jump-and-Store 指令) 和JUMPI(Jump Indirect)将其转换为通用例程。

JNS Multiply

/ Somewhere else
/ Define Multiply as a variable
/ JNS will store the current HEX address
/ in Multiply and start executing the next
/ line

Multiply, DEC 0

/ *** Multiply Body *** /

/ Lastly use JUMPI to Jump Indirectly
/ back to where Multiply was
/ executed from

JUMPI Multiply
于 2016-11-13T03:15:18.637 回答