1

I am currently working on the MARIE SIMULATOR and I am attempting to get three inputted decimals, and multiply all of them together.

For some reason my code keeps spitting out answers that are way larger then expected. For instance 2 x 2 x 2 gives me 18. I ran it step by step and it seems like the Skipcond is running an extra time for each cycle. I tried tweaking it by incrementing it to Skipcond 001 and changing the input values to Hex since I saw something similar in my book but the issue persists. Anyone have any ideas?

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

Edit:: Used older version of code. Corrected code by changing second "Loop" to "Loop2".

Issue persists with getting the incorrect answer to the multiplication. The issue appears to be with the Skipcond 000 although Im not sure what it is

Cigaro
  • 51
  • 1
  • 7

1 Answers1

0

It looks like you are using the same label "Loop" on more than one line. For the second loop you should use another label.

And your SKIPCOND should be 400, not 000. 000 means skip if negative 400 means skip if 0

So actually your code calculates 2 x 3 x 3, instead of 2 x 2 x 2.

By the way, I do not know which simulator you use, but I have developed a simple MARIE Simulator iPad app for one of the graduate CS classes I even do not remember. You can check it here: https://github.com/erkanyildiz/MARIESimulator It might help to visualize running of your code.

erkanyildiz
  • 13,044
  • 6
  • 50
  • 73
  • Yeah I did using Loop and Loop 2. Looks like I accidentally copied an older version of the code. Before the correction the code wouldn't assemble. After I corrected the loop issue was when I was getting the wacky answers. Any other ideas? – Cigaro Mar 17 '16 at 15:06
  • So this thing was due tonight at midnight... I saw a question somewhere that used 400 and decided I would try that if no one answered my here. Thanks it worked!!! And you answered me 7 minutes before I went to turn it in haha! – Cigaro Mar 18 '16 at 02:02
  • Great! I am glad that you made it on time. – erkanyildiz Mar 18 '16 at 02:03