1

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.

basica
  • 67
  • 1
  • 2
  • 11
  • Shouldn't you be using `SKIPCOND 800` (skip if AC>0)? `SKIPCOND 400` means "skip if AC==0", so you're currently doing something like `IF (Y != 0) GOTO Q` – Michael Apr 03 '13 at 08:29
  • Thank you for pointing that out. Such a silly mistake. I realized that I made that mistake and also that I didn't load X again before outputing it in the closing jump. If you would like to submit this as an answer, I'll select it. – basica Apr 03 '13 at 08:43

1 Answers1

2

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

Michael
  • 57,169
  • 9
  • 80
  • 125