Loops MARIE Sim中的3个数字乘法
我目前正在研究玛丽模拟器,我正试图得到三个输入的小数,并将它们相乘 出于某种原因,我的代码不断给出比预期的答案大得多的答案。例如2x2x2给我18。我一步一步地运行它,似乎Skipcond在每个循环中运行额外的时间。我试图通过将其增加到Skipcond 001并将输入值更改为Hex来调整它,因为我在书中看到了类似的内容,但问题仍然存在。有人有什么想法吗Loops MARIE Sim中的3个数字乘法,loops,simulation,multiplication,skip,marie,Loops,Simulation,Multiplication,Skip,Marie,我目前正在研究玛丽模拟器,我正试图得到三个输入的小数,并将它们相乘 出于某种原因,我的代码不断给出比预期的答案大得多的答案。例如2x2x2给我18。我一步一步地运行它,似乎Skipcond在每个循环中运行额外的时间。我试图通过将其增加到Skipcond 001并将输入值更改为Hex来调整它,因为我在书中看到了类似的内容,但问题仍然存在。有人有什么想法吗 ORG 100 /Starting point // Gustavo Brandao. No Partners Input
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有关,尽管我不确定它是什么看起来您在多行上使用了相同的标签“Loop”。 对于第二个循环,应该使用另一个标签 你的SKIPCOND应该是400,而不是000。 000表示如果为负则跳过 400表示如果0则跳过 所以实际上你的代码计算的是2x3x3,而不是2x2x2 顺便说一句,我不知道你用的是哪个模拟器,但我为一个我甚至不记得的研究生CS课程开发了一个简单的MARIE模拟器iPad应用程序。您可以在这里查看:
这可能有助于可视化代码的运行。看起来您在多行上使用了相同的标签“循环”。 对于第二个循环,应该使用另一个标签 你的SKIPCOND应该是400,而不是000。 000表示如果为负则跳过 400表示如果0则跳过 所以实际上你的代码计算的是2x3x3,而不是2x2x2 顺便说一句,我不知道你用的是哪个模拟器,但我为一个我甚至不记得的研究生CS课程开发了一个简单的MARIE模拟器iPad应用程序。您可以在这里查看:
这可能有助于可视化代码的运行。是的,我使用了循环和循环2。看起来我不小心复制了旧版本的代码。在更正之前,代码无法汇编。在我纠正了循环问题之后,我得到了古怪的答案。还有其他想法吗?所以这件事是今晚午夜到期的。。。我在某个地方看到一个400的问题,决定如果这里没有人回答我的问题,我会试试。谢谢,它成功了!!!而你在我去交卷前7分钟回答了我,哈哈!伟大的我很高兴你按时完成了。是的,我使用了循环和循环2。看起来我不小心复制了旧版本的代码。在更正之前,代码无法汇编。在我纠正了循环问题之后,我得到了古怪的答案。还有其他想法吗?所以这件事是今晚午夜到期的。。。我在某个地方看到一个400的问题,决定如果这里没有人回答我的问题,我会试试。谢谢,它成功了!!!而你在我去交卷前7分钟回答了我,哈哈!伟大的我很高兴你准时到了。