assemblymarie

Skipcond in MARIE Assembly Language


I have the following code:

      ORG    100      
LOOP, Load   X
      Add    Z
      Store  X
      Load   Y
      Skipcond 400
      Jump   Q
      Subt   Z
      Store  Y
      Jump   LOOP
Q,    Output X
      Halt
X,    Dec    0
Y,    Dec    10
Z,    Dec    1

Now if I understand it correctly, it would be somewhat equivalent to the following Python code:

x = 0
y = 10
z = 1
while True:
    x += z
    if y > 0:
        y -= 1
    else:
        exit(0)

If that's the case, I'm confused why X = 10 in MARIE and X = 11 in Python upon completion of the looping process. From what I understand in the MARIE code, the skipcond 400 is equivalent to if y > 0. If that's the case, then when x = 10, y = 1 and it will still pass the skipcond to subtract 1 from y and therefore restart the loop and add 1 to x again meaning x = 11 when the loop ends and the data is outputed.

Some help understanding this would be greatly appreciated, thank you.


Solution

  • Your SKIPCOND is "inverted". Condition 400 means skip if AC==0. So this code:

      Load   Y
      Skipcond 400
      Jump   Q
    

    Will in effect do:

    IF (Y != 0) GOTO Q
    

    which seems like the opposite of what you want to do. What you probably want is SKIPCOND 800 (skip if AC > 0).