我必须在 MARIE 模拟器(我认为它只是使用普通的汇编语言)中编写一个程序,该程序从输入寄存器中获取 10 个数字并将它们加在一起。
我还必须每次检查加法是否太大而无法保存在累加器中,如果是,程序必须停止。MARIE 中的累加器是 16 位的,所以可以保存的最大数是 hex FFFF。
我已经完成了第一部分,但不知道如何进行第二部分。
编辑:我试图弄清楚,这是我现在的代码:
ORG 100
Load Num /Load the number of items to be added
Subt One /decrement it
Subt One /twice
Store Ctr /Store the value in the loop counter variable
Input /enter a number
Store Sum /store that first number into the sum
Store Check /store the same value in check
Loop, Input /take in another input
Store Inp /store the input
Load Sum /Load the sum of the numbers so far into the accumulator
Add Inp /Add the inputted value to sum
Output /Checking each sum to see if it is correct, ie outputting AC value
Store Sum /Store the result in sum
Load Check /Load it to compare
Subt Sum /Take away sum
Store Check /if bigger than zero, sum was too large to be held
Skipcond 000 /skip if it's less than zero
Jump Then
Load Sum /if the sum was not too big
Store Check /store the value in check
Load Ctr /Load the counter variable into the AC
Subt One /Decrement it, as one number has been added
Store Ctr /Overwrite ctr with the new decremented value
Skipcond 000 /if ctr < 0, then skip the next instruction, ie end the loop
Jump Loop /Go back to the start of the loop
Halt /Terminate program
Then, Load End /Load the end variable
Output /output it to the screen
Halt /end program
Num, Dec 10 /Number of values to be added
Check, Dec 0 /variable used to check the next sum
End, Hex FFFF /value to be printed to the screen if sum is too large
Sum, Dec 0 /The sum made after addition of two numbers
Ctr, Hex 0 /loop control variable
One, Dec 1 /used to increment and decrement values
Inp, Dec 0 /variable which holds the inputted value
它似乎以我尝试过的几种方式起作用;例如,如果我输入十六进制数字 0002 和 FFFF,它将它们相加并得到 0001,这被检测为错误并且程序结束。
当添加的总和为 FFFF 时,它不起作用。我添加了 0002 和 FFFD 得到结果 FFFF,但是程序然后就好像出错了一样结束了,但我不明白为什么。
我感谢所有回答的人。并且回复吉姆米歇尔,为这个错误道歉,我不会再犯了。