LC3汇编编程给我一个奇怪的标签错误?

时间:2015-04-21 16:21:56

标签: loops assembly lc3

我正在制作一个计算x阶乘的LC3装配程序。我有这个名为" OUTERLOOP"只要我的计数器值不是负值就可以使用。但是,汇编程序给出了这个错误:" 32:标签OUTERLOOP已经出现。"它没有给我内部循环的这个错误。出于某种原因,当我尝试将其分支回OUTERLOOP地址时,它似乎认为我试图再次使用OUTERLOOP命名另一个地址。有什么想法吗?

; This program calculates X! (X factorial). It can calculate
;   different numbers (4!, 6!, etc.) by changing the value of the first memory
;   location at the bottom of the code. It is currently set up to calculate
;   5!. The program does not account for zero or negative numbers as input.

; This program primarily uses registers in the following manner:
; R0 contains 0 (registers contain zero after reset)
; R1 contains multiplication result (6x5 = 30, 30x4 = 120, etc)
; R2 contains -1
; R3 contains counter for outer loop
; R4 contains counter for inner loop
; R5 contains current sum

           .ORIG  x3000

            LD    R1,INPUT            ; R1 contains input number
            LD    R2,xFFFF            ; R2 contains -1
            ADD   R3,R1,R2            ; R3 contains input number -1
            ADD   R3,R3,R2            ; R3 contains input number -2
                                      ;   (initializes outer count)
OUTERLOOP   ADD   R4,R0,R3            ; Copy outer count into inner count

; This loop multiplies via addition (6x5 = 6+6+6+6+6 = 30,
;   30x4 = 30+30+30+30 = 120, etc)
INNERLOOP   ADD   R5,R5,R1            ; Increment sum
            ADD   R4,R4,R2            ; Decrement inner count
            BRzp  INNERLOOP           ; Branch to inner loop if inner count
                                      ;   is positive or zero
            ADD   R1,R0,R5            ; R1 now contains sum result from inner loop
            AND   R5,R5,#0            ; Clear R5 (previous sum) to 0
            ADD   R3,R3,R2            ; Decrement outer count
            BRpz  OUTERLOOP           ; Branch to outer loop if outer count
                                      ;   is positive or zero

            ST   R1,INPUT             ; This address contains X!
            TRAP x25                  ; HALT

INPUT      .FILL  x0005               ; Input for X!, in this case X = 5
           .FILL  x0000
           .FILL  xFFFF               ; 2's complement of 1 (i.e. -1)
           .FILL  x0000               ; At program completion, the result is
                                      ;   stored here
           .END

1 个答案:

答案 0 :(得分:3)

尝试更改

BRpz  OUTERLOOP           ; Branch to outer loop if outer count

BRzp  OUTERLOOP           ; Branch to outer loop if outer count