【问题标题】:How to do multiplication and then addition in Marie simulator如何在玛丽模拟器中进行乘法和加法
【发布时间】:2016-08-20 20:03:47
【问题描述】:

我是玛丽模拟器的新手。我知道如何在模拟器中添加,但不幸的是我不知道如何乘法。 例如,我该如何输入代码:S=x*Y+z 提前致谢

【问题讨论】:

    标签: marie


    【解决方案1】:

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

    这是一个基本算法。

    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(跳转和存储指令)和JUMPI(间接跳转)将其转换为通用例程。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多