MARIE模拟器;如何检查添加的数字是否太大而无法保存在累加器中

时间:2015-03-18 11:47:14

标签: assembly accumulator marie

我必须在MARIE模拟器中编写一个程序(我认为它只使用普通的汇编语言),它从输入寄存器中获取10个数字并将它们加在一起。

我还必须每次检查添加量是否太大而无法保存在累加器中,如果是这样,程序必须停止。 MARIE中的累加器是16位,因此可以保持的最大数是十六进制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,但程序结束就好像是一个错误,但我不明白为什么。

我感谢所有回答的人。为了回答Jim Mischel,为这个错误道歉,我不会再这样了。

0 个答案:

没有答案