3 MARIE Sim中的数字乘法
3 Number multiplication in MARIE Sim
我目前正在研究 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 有关,但我不确定它是什么
您似乎在不止一行中使用了相同的标签 "Loop"。
对于第二个循环,您应该使用另一个标签。
你的 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
可视化您的代码 运行 可能会有所帮助。
我目前正在研究 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 有关,但我不确定它是什么
您似乎在不止一行中使用了相同的标签 "Loop"。 对于第二个循环,您应该使用另一个标签。
你的 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 可视化您的代码 运行 可能会有所帮助。