首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LC3汇编编程给了我一个奇怪的标签错误?

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

Stack Overflow用户
提问于 2015-04-21 16:21:56
回答 1查看 3.4K关注 0票数 0

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

代码语言:javascript
复制
; 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-21 16:33:51

试着改变

代码语言:javascript
复制
BRpz  OUTERLOOP           ; Branch to outer loop if outer count

代码语言:javascript
复制
BRzp  OUTERLOOP           ; Branch to outer loop if outer count
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29777909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档