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

谁说我不能喝 提交于 2019-12-21 04:40:56

问题


I am trying to understand the MARIE assembly language. I don't quite understand skipcond for doing things like <, or >, or multiply or divide.

I am taking this simple program:

x = 1
while x < 10 do
x  = x +1
endwhile;

What I don't understand is how to use certain skip conditions:

Skipcond 800 if AC > 0,
Skipcond 400 if AC = 0,
Skipcond 000 if AC < 0

Now, I know I would subtract x from 10 and test using skipcond.

I am not sure which one and why. I guess if I knew how they really work maybe it would be easier to understand. Why is it used to compare to zero?

This is what I have:

100     load one
101     store x
102     subt ten
103     skipcond400  if x-10 = 0?   // or skpcond000 x -10 < 0?? 

回答1:


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.



来源:https://stackoverflow.com/questions/5136860/how-does-skipcond-work-in-the-marie-assembly-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!