簡體   English   中英

如何在程序集中將累加器值與特定的正整數進行比較?

[英]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:

也有一些例子在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM