我正在制作一个计算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发布于 2015-04-21 16:33:51
试着改变
BRpz OUTERLOOP ; Branch to outer loop if outer count至
BRzp OUTERLOOP ; Branch to outer loop if outer counthttps://stackoverflow.com/questions/29777909
复制相似问题