- #1
TheMathNoob
- 189
- 4
Mod note: Edited the post to add code tags, and moved the code to the attempt section.
Hi I am trying to write a program in LC3 which performs the operation AND on the input given by the user and the test input highlighted on the next code . The problem that I am having is that the register R0 doesn't seem to change in the console. I try to AND R0 with 0 to see if it reacts and still doesn't work. It preserves the value X7FFF. The reason why I am ANDing the input given by the user and values like this 1000 0000 0000 0000 is because I am trying to display on the screen the number given by the user in binary.
Homework Statement
Hi I am trying to write a program in LC3 which performs the operation AND on the input given by the user and the test input highlighted on the next code . The problem that I am having is that the register R0 doesn't seem to change in the console. I try to AND R0 with 0 to see if it reacts and still doesn't work. It preserves the value X7FFF. The reason why I am ANDing the input given by the user and values like this 1000 0000 0000 0000 is because I am trying to display on the screen the number given by the user in binary.
Homework Equations
The Attempt at a Solution
Code:
.ORIG x3000
LD R0,ZERO
LD R2,ZERO ;INT
LD R3,ZERO ;INT
LD R4,ZERO ;DIGIT
LD R5,ZERO ;LF
LD R6,FORTYFIVE ;45 48 AND COUNTER
LOOP TRAP x20
TRAP x21
AND R5,R5,#0
ADD R5,R0,xFFF6
BRz NEXT3
ADD R3,R0,R6
BRnp NEXT
AND R3,R3,#0
ADD R3,R3,#1
BRnzp LOOP
NEXT AND R6,R6,#0
LD R6,FORTYEIGHT
ADD R4,R0,R6
AND R5,R5,#0
ADD R5,R5,R2
AND R6,R6,#0
ADD R6,R6,#9
DIGIT BRz NEXT2
ADD R2,R2,R5
ADD R6,R6,#-1
BRnzp DIGIT
NEXT2 ADD R2,R2,R4
BRnzp LOOP
NEXT3 AND R4,R4,#0
AND R6,R6,#0
LD R4,x0050 ------>Test Input
LD R6,FORTYEIGHT_
AND R0,R2,R4
BRnp GO
AND R0,R0,#0
LD R0,ZERO
ADD R0,R0,R6
GO AND R0,R0,#0
LD R0,ZERO
ADD R6,R6,#1
ADD R0,R0,R6
OUT
HALT
ENTER .STRINGZ "ENTER A NUMBER OR PRESS X TO EXIT: "
ZERO .FILL #0
NINE .FILL #9
FORTYFIVE .FILL #-45
FORTYEIGHT .FILL #-48
FORTYEIGHT_ .FILL #48
.END
Last edited by a moderator: