本文介绍了`Skipcond`如何以MARIE汇编语言工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解MARIE汇编语言.我不太了解skipcond做类似<>的事情,或者乘或除.

I am trying to understand the MARIE assembly language. I don't quite understand skipcond fordoing 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

现在,我知道我会从10中减去x并使用skipcond进行测试.

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?

这就是我所拥有的:

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

推荐答案

while x < 10 do
    x  = x + 1

x等于10时,

将跳出循环.如果从x减去10,您将得到一个负值,直到x等于10(且值为0).因此,使用skpcond000是错误的,因为它跳得太早了.所以skpcond400是正确的.

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.

如果更改C代码,也许更容易理解,因此它更接近汇编代码:

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

还请注意,必须增加条件后的x 才能再现与while循环相同的行为.

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

这篇关于`Skipcond`如何以MARIE汇编语言工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:57