如何将累加器值与汇编中的特定正整数进行比较?

How do I compare accumulator value to specific positive integer in assembly?

我正在编写一个非递归程序,用于计算 Mac-1 汇编架构中序列中第 N 项的斐波那契数。一切都进行得很顺利,直到我到达函数中需要比较的点,看看我加载到累加器中的 N 值是否 <= 2。但是,我得到的唯一 JUMP 执行是 JNEG(它跳转如果值为负)和 JZER(如果值为零则跳转)。

所以我的问题是如果我有:

0001  One:  1        // Constant definition
000A  N:    10       // N

在函数中我可以说:

800y  LODL  y        // Loading N after its already been placed in the stack by offset y
C0xx  JNEG  Finished // If the number is negative, we are finished
50xx  JZER  Finished // If the number is zero, we are finished

但是如果 N <= 2 我怎么说呢?我只得到负数或零的选项,但我需要比较 N <= 2 对于我的循环中的基本情况。

注意

                                                    a ≤ 2 ⇒ a - 2 ≤ 0 ⇒ a - 2 < 0 ∨ a = 0

这两种情况都可以使用可用的说明进行测试。


如果你想实现if (a0 <= a1) ... else ...你可以使用

LODD a0              /Accumulator = a0
SUBD a1              /Accumulator = a0 - a1
jzer _THEN_branch    /Jump to "then branch" if a0 == a1
jneg _THEN_branch    /Jump to "then branch" if a0 < a1

 /Put "else branch" code here

jump _IF_end

_THEN_branch:

 /Put "then branch" code here

_IF_end:

还有一些例子here