【问题标题】:How do I compare accumulator value to specific positive integer in assembly?如何将累加器值与汇编中的特定正整数进行比较?
【发布时间】:2016-09-27 22:12:50
【问题描述】:

我正在编写一个非递归程序,用于计算 Mac-1 汇编架构中序列中第 N 项的斐波那契数。一切都很好,直到我到达函数中需要比较的点,以查看我加载到累加器中的 N 值是否

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

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

【问题讨论】:

    标签: assembly hex comparison fibonacci


    【解决方案1】:

    注意

                                                     a ≤ 2 ⇒ a - 2 ≤ 0 ⇒ a - 2

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


    如果你想实现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

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多