Does this MARIE code find the lowest number in an array?

3.6k Views Asked by At

I believe i did this correct, can anyone double check on the work. And if it is correct where should I look to verify that it is picking the right number. So i am trying to give the array and see which one is the smallest number out of that array.

    Org 100     /Find minimum
    Load    Start
    Add Num
    Subt    One
    Store   Loc
    Loadi   Loc
    Store   Min 
    Load    Num
    Subt    One
    Store   J
Loop,   Load    J
    Skipcond 00
    Jump    After
    Jump    Done
After,  Load    Loc
    Subt    One
    Store   Loc
    Subt    Min
    Skipcond 00
    Jump    After2
    Loadi   Loc
    Store   Min
After2, Load    J
    Subt    One
    Store   J
    Jump    Loop
Done,   Load    Min
    Halt

Min,    Dec 0  /where we save the min
Num,    Dec 10 /Numbers of value in array
One,    Dec 1 
J,  Dec 0  /Loop variable
Loc,    Dec 0
Start,  Hex 121 /Be sure to start off values in array
Array,  Dec 5
    Dec 20
    Dec 11
    Dec 15
    Dec 83
    Dec 2
    Dec 7
    Dec 1
    Dec 13
    Dec 15
1

There are 1 best solutions below

1
On

This looks suspicious:

   Loadi   Loc
    Store   Min 

What do you have at zero address?

[edit] Ah that was right, but another thing: doesn't it skip the 9th array element?

I understand it initializes by : storing the 10th element as (current) min, sets ptr to 9th element and sets loop count to 9.

Then the first thing in the loop - after checking the loop counter, it decrements the pointer again before checking the "next" element.

Or did I understand something wrong?

[edit #2]

Ahah, the Marie behind the link I gave didn't understand the indirect instructions. This does. http://computerscience.jbpub.com/ecoa/3e/simulators.aspx

It looks like there is something else wrong too:

This doesn't make sense:

After,  Load    Loc
    Subt    One
    Store   Loc
    Subt    Min / here 'Min' is subtracted from the element's address
    Skipcond 00

I guess the program is supposed to find the minimum, but it doesn't work at all.