How does `Skipcond` work in the MARIE assembly language?

while x < 10 do
    x  = x + 1

will jump out of the loop as soon as x equals 10. If you subtract 10 from x, you’ll get a negative value until x equals 10 (and the value is 0). So using skpcond000 would be wrong as it would jump out too soon. So skpcond400 is correct.

Perhaps it is easier to understand if you change the C code so it will be closer to the assembly code:

Original:            while (x < 10) do
Subtract 10:         while ((x - 10) < 0) do
Use != instead of <: while ((x - 10) != 0) do

Also note that you have to increase x after the condition to reproduce identical behaviour to the while loop.

Leave a Comment