.ORIG x3000 LD R0,ASCII LD R1,NEG AGAIN LDI R2,DSR BRzp AGAIN STI R0,DDR ADD R0,R0,#1 ADD R2,R0,R1 BRnp AGAIN HALT ASCII .FILL x0041 NEG .FILL xFFB6 ;x004A DSR .FILL xFE04 DDR .FILL xFE06 .END
时间: 2024-01-19 08:03:15 浏览: 76
accerciser_3.22.0.orig.tar.xz
This LC-3 assembly language program loads two values into registers R0 and R1, then enters a loop that repeatedly loads a value from memory into register R2, checks if the value is positive, stores the value from R0 into memory, increments the value in R0, adds the values in R0 and R1, checks if the sum is negative, and repeats the loop if it is. If the sum is not negative, the program halts. Here is a breakdown of each line of the program:
```
.ORIG x3000 ; Start of program
LD R0,ASCII ; Load ASCII value into R0
LD R1,NEG ; Load negative value into R1
AGAIN ; Loop label
LDI R2,DSR ; Load value at DSR address into R2
BRzp AGAIN ; Branch to AGAIN label if value in R2 is positive
STI R0,DDR ; Store value in R0 at DDR address
ADD R0,R0,#1 ; Add 1 to value in R0
ADD R2,R0,R1 ; Add values in R0 and R1, store result in R2
BRnp AGAIN ; Branch to AGAIN label if sum of R0 and R1 is not negative
HALT ; Halt program execution
ASCII .FILL x0041 ; Define memory location with ASCII value
NEG .FILL xFFB6 ; Define memory location with negative value
DSR .FILL xFE04 ; Define memory location with value
DDR .FILL xFE06 ; Define memory location with value
.END ; End of program
```
阅读全文