2

I have to write a program in the MARIE simulator (which I think just uses ordinary assembly language) that takes in 10 numbers from the input register and adds them together.

I also have to check each time if the addition is too big to be held in the accumulator, and if so, the program must stop. The accumulator in MARIE is 16 bits, so the maximum number that can be held is hex FFFF.

I have gotten the first part done but cannot figure out how to go about the second part.

EDIT: I have tried to figure it out, and this is my code now:

        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

It seems to work in a few ways that I've tried; for example, if I enter the hex numbers 0002 and FFFF, it adds them together and gets 0001, which is detected as a mistake and the program ends.

It doesn't work when the added sum is FFFF. I added 0002 and FFFD to get the result FFFF, but the program then ended as if it was a mistake, but I don't understand why.

I thank all who answered. And to reply to Jim Mischel, apologies for the mistake, I won't make it again.

Scott Kelly
  • 21
  • 1
  • 4
  • There's no such thing as "ordinary assembly language." Assembly language is typically processor specific. – Jim Mischel Mar 18 '15 at 14:30
  • You should show the code that didn't work, along with the sequence of inputs that caused it to fail. – Weather Vane Mar 18 '15 at 16:53
  • With further testing the program doesn't work with a lot of summations; the example above, with 0002 and FFFF works, but when I add FFF0, 000E and 1111, it doesn't detect that it has run over the available memory. I can't see what I have done wrong – Scott Kelly Mar 20 '15 at 14:01

0 Answers0