loopssimulationmultiplicationskipmarie

3 Number multiplication in MARIE Sim


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


Solution

  • 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.