LC-3 Assemby Counters

43 views Asked by At

The program must start at address x3000. Here’s how the program must behave:

  1. The program sends a newline to the console and then prints “Enter First Number (4 binary digits): ”, which serves as a prompt to tell the user that the program is waiting for input. The prompt string is a string, followed by a single space.
  2. The user types a four-digit binary number on the keyboard. As the numbers are typed on the keyboard they should be echoed onto the console window. Any illegal input values are ignored after they are echoed. The program must check and accept only 0 or 1 numerical digits. The program should recognize the entry as complete when it sees 4 valid digits.

I'm having trouble with making the problem recognizing the entry as complete when it sees 4 valid digits. This is my current code

.ORIG x3000

LEA R0, PROMPT1
PUTS
LD R1, FOUR
LOOP GETC
OUT


LD R1, ASCII_q
NOT R1, R1         ; Invert the ASCII value of 'q'
ADD R1, R1, #1     ; Add 1 to get two's complement of -113
ADD R2, R0, R1     ; Subtract the input character from the two's complement of -113
BRz THANKS1
BRnp NEXT

NEXT:
LD R1, ASCII_1
NOT R1, R1         ; Invert the ASCII value of 'q'
ADD R1, R1, #1     ; Add 1 to get two's complement of -113
ADD R2, R0, R1     ; Subtract the input character from the two's complement of -113
BRz DC
BRnp NEXT1

NEXT1:
LD R1, ASCII_0
NOT R1, R1         ; Invert the ASCII value of 'q'
ADD R1, R1, #1     ; Add 1 to get two's complement of -113
ADD R2, R0, R1     ; Subtract the input character from the two's complement of -113
BRz DC

LEA R0, IC
PUTS
BRnzp LOOP

LD R1, ASCII_0
ADD R2, R2, R1
BRnzp LOOP

ADD R1, R4, R4
BRzp FIRST_NUMBER

LD R2, ASCII_0
ADD R3, R3, R4
BRz LOOP

ADD R1, R1, #-1
BRnzp LOOP

THANKS1 
    LEA R0, THANKS ; Load the address of the thanks message into R0
    PUTS               ; Display the thanks message
    HALT               ; End program execution     

SFN:
ST R2, FIRST_NUMBER

EXIT HALT

IC:
LEA R0, ICP
PUTS
BRnzp LOOP

DC:
ADD R4, R4, #-1

FOUR .FILL #4
THANKS .STRINGZ " THANKS FOR PLAYING"
PROMPT1 .STRINGZ " ENTER FIRST NUMBER(4 binary digits):"
PROMPT2 .STRINGZ " ENTER SECOND NUMBER"
ASCII_0 .FILL x0030
ASCII_1 .FILL x0031
ASCII_q .FILL x0071
BUFFER .BLKW #5
NEWLINE .FILL x000A
SPACE .FILL x0020
ICP .STRINGZ " Invalid character. Please enter '0', '1', or 'q'."
FIRST_NUMBER .BLKW #1
SECOND_NUMBER .BLKW #1
.END

I would appreciate the help in this. Thanks

0

There are 0 answers