我编写了LC3程序并通过一个数组找到哪个int是最大的哪个工作正常,但是在打印出最大的int时遇到了问题。当我告诉它时,寄存器0具有最大的int,但由于某种原因,控制台上没有任何内容。 这是我的代码:
.ORIG x3000
LD R5, negasc
LEA R6, array
loop AND R0, R0, #0
LEA R0, prompt ;load prompt
PUTS ;print prompt to screen
AND R0, R0, #0
GETC ;get int
OUT ;print int
STR R0, R6, #0 ;store int in array
ADD R6, R6, #1 ;Move to next slot in array
ADD R0, R0, R5 ;convert to decimal
BRp loop
LEA R6, array ;load address back into R6
LDR R1, R6, #0 ;load first value of array into R1
LDR R2, R6, #1 ;load second value of array into R2
ADD R3, R3, R1 ;keep original value in R3 and R4
ADD R4, R4, R2
ADD R6, R6, #2 ;move pointer
NOT R1, R1
ADD R1, R1, #1 ;2's complement now in first value
ADD R2, R1, R2 ;test which is bigger
BRnz if
BRp else
if AND R1, R1, #0
NOT R1, R3
ADD R1, R1, #1
LDR R2, R6, #0 ;Load next value of array in R2
ADD R6, R6, #1 ;move pointer
AND R4, R4, #0
ADD R4, R4, R2 ;store original in R4
ADD R4, R4, #0 ;test if done
BRz done1
ADD R2, R1, R2 ;test which is bigger
BRnz if
BRp else
else AND R2, R2, #0 ;clear R2
ADD R2, R4, R2 ;get original value back in R2
LDR R1, R6, #0 ;Load next value of array in R1
ADD R6, R6, #1 ;move pointer
AND R3, R3, #0
ADD R3, R3, R1 ;store original in R3
NOT R1, R3
ADD R1, R1, #1 ;2's complement in R1
ADD R3, R3, #0
BRz done2
ADD R2, R1, R2 ;test which is bigger
BRnz if
BRp else
done1 AND R0, R0, #0 ;clear R0
LEA R0, largest ;Print largest string
PUTS
AND R0, R0, #0 ;clear R0
ADD R0, R3, R0 ;get largest int in array
ADD R0, R0, R5 ;convert to decimal
OUT ;print largest int
BRnzp finish ;halt
done2 AND R0, R0, #0 ;clear R0
LEA R0, largest ;Print largest string
PUTS
AND R0, R0, #0 ;clear R0
ADD R0, R4, R0 ;get largest int in array
ADD R0, R0, R5 ;convert to decimal
OUT ;print largest int
BRnzp finish ;halt
finish HALT
prompt .STRINGz "\nEnter a single-digit integer: "
negasc .FILL xFFD0
array .BLKw 20
largest .STRINGz "\nThe largest integer is: "
.END