1

我目前正在研究 MARIE SIMULATOR,我正在尝试获取三个输入的小数,然后将它们全部相乘。

出于某种原因,我的代码不断吐出比预期大得多的答案。例如 2 x 2 x 2 给了我 18。我一步一步地运行它,似乎 Skipcond 为每个周期运行了额外的时间。我尝试通过将其增加到 Skipcond 001 并将输入值更改为 Hex 来调整它,因为我在我的书中看到了类似的内容,但问题仍然存在。有人有想法么?

ORG 100     /Starting point // Gustavo Brandao. No Partners
    Input       /Request user input for first number
    Store   NumA    /Store the number
    Output      /Display number to screen
    Input       /Request user for a second number
    Store   NumB    /Store number
    Output      /Display number
    Input       /Request user for third number
    Store   NumC    /Show number
    Output      /Display number
Loop,   Load    NumA    /Load the first number, will also loop from here
    Add Sum /Add with zero and location which will save the sum
    Store   Sum /Store the sum
    Load    NumB    /Load the second number for the skip condition control
    Subt    One /decrement the number
    Store   NumB    /Store the number. when 0, code will skip the jump
    Skipcond 000    /Skip when the second number reaches zero
    Jump    Loop    /Used to repeat addition until second number reaches zero
    Load    Sum
    Store   NumA    /Storing sum in NumA slot to make code easier to read
Loop2,   Load    NumA    /Loading the previous sum
    Add FSum    /Adding previous sum to zero and final sum location
    Store   FSum    /Storing final sum
    Load    NumC    /Second skip condition control
    Subt    One /decrememting number
    Store   NumC    /Storing skip condition
    Skipcond 000    /When the third inputed number is zero, loop will end
    Jump    Loop2    /Loops back to second part of code
    Load    FSum    /load the final sum for output
    Output      /Display final sum
    HALT
NumA,   Dec 0   /First number; Will be overwritten with input
NumB,   Dec 0   /Second number
NumC,   Dec 0   /Third number
Sum,    Dec 0   /Stores the sum for the first multiplication process
FSum,   Dec 0   /Stores sum for the second multiplication process
One,    Dec 1   /Used to decrement values

编辑:: 使用旧版本的代码。通过将第二个“Loop”更改为“Loop2”更正了代码。

问题仍然存在,得到的乘法答案不正确。问题似乎与 Skipcond 000 有关,尽管我不确定它是什么

4

1 回答 1

0

看起来您在不止一行上使用了相同的标签“循环”。对于第二个循环,您应该使用另一个标签。

并且您的 SKIPCOND 应该是 400,而不是 000。000 表示如果为负则跳过 400 表示如果为 0 则跳过

所以实际上你的代码计算的是 2 x 3 x 3,而不是 2 x 2 x 2。

顺便说一句,我不知道您使用的是哪个模拟器,但我为我什至不记得的研究生 CS 课程开发了一个简单的 MARIE Simulator iPad 应用程序。您可以在此处查看:https ://github.com/erkanyildiz/MARIESimulator 它可能有助于可视化代码的运行。

于 2016-03-17T02:06:12.507 回答