【问题标题】:Assembly: LC3 Division组装:LC3分部
【发布时间】:2014-02-09 05:47:36
【问题描述】:

我是汇编语言的新手,在课堂上我们正在使用 LC3 模拟器编写除法程序。 下面是我的除法算法代码。

DIVISION:

AND     R3, R3, 0   ; Zero out R3 /This is the remainder
AND R4, R4, 0   ; Zero out R4 /This is the quotient

NOT     R3, R2      ; Takes the inverse of 2nd input ->R3
ADD     R3, R3 #1   ; Add one to the inverse (for 2s comp)

LOOPD
ADD     R4, R4, #1  ; Add 1 to R4 repeatedly
ADD     R1, R1, R3  ; Subtract input2 from R1
BRN     NEGATIVE
BRZ     ZERO
BRP     LOOPD

NEGATIVE
ADD     R4, R4, #-1
ADD     R3, R1, R2

; Done with divison algorithm.
ZERO
LD  R0, DECCONV     ; Load Decimal converter
ADD     R3, R3, R0  ; Convert back to ASCII
ADD     R4, R4, R0  ; Convert back to ASCII

ST  R3, REMRESULT   ; Store the remainder result
ST  R4, DIVRESULT   ; Store the division result.

LD  R0, DIVRESULT   ; Load Division result into R0
PUTC            ; Print it.
LEA     R0, DIVSTRING   ; Load the string for division.
PUTS            ; Print the string.

LD  R0, REMRESULT   ; Load Remainder result into R0
PUTC            ; Print it.
LEA     R0, REMSTRING   ; Load the string for remainder
PUTS            ; Print the string.

当我输入两个输入时,例如:4 和 2。 我得到 2 的商和 1 的余数。 当我输入 9,3 我得到 6 余数 1..

有什么想法吗?

【问题讨论】:

    标签: assembly division lc3


    【解决方案1】:

    使用模拟器单步执行代码并找出问题所在。 也就是说,很明显ZERO 的情况在R1 中仍有余数,因此使用R3 是错误的。我建议您也将 R1 中的剩余部分保留在 NEGATIVE 块中,并为此调整代码的最后部分。

    商应该没问题,我不知道你为什么得到69/3(如果你真的这样做的话)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多