How can I take multiple digit positive integers as input in LC3?

25 Views Asked by At

I have a program that should take two natural numbers as input. Below is my current attempt, which doesn't work. All the labels you don't see are of course elsewhere in the code, I don't believe them to be the problem. The goal is to get a number in R1 and a number in R2.

START           LD R6, ASCII        ; load ascii offset for printing numbers
                NOT R6, R6
                ADD R6, R6, #1

                AND R1, R1, #0
INPUT1          TRAP x20
                ADD R5, R0, R6
                BRn INPUT2          ; whatever was inputted wasn't a digit, value in R1 is the correct value
                ADD R3, R5, #-9     
                BRp INPUT2          ; whatever was inputted wasn't a digit, value in R1 is the correct value
                ; input was a digit. multiply R1 by 10 and add it
                AND R3, R3, #0
                ADD R3, R3, #9
                ADD R4, R1, #0      
MULT1           ADD R1, R4, R1
                ADD R3, R3, #-1
                BRp MULT1           ; we are multiplying by 10
                ADD R1, R1, R5      ; add the input
                BRnzp INPUT1
                
                AND R2, R2, #0
INPUT2          TRAP x20
                ADD R5, R0, R6
                BRn PREP          ; whatever was inputted wasn't a digit, value in R2 is the correct value
                ADD R3, R5, #-9     
                BRp PREP          ; whatever was inputted wasn't a digit, value in R2 is the correct value
                ; input was a digit. multiply R2 by 10 and add it
                AND R3, R3, #0
                ADD R3, R3, #9
                ADD R4, R2, #0
MULT2           ADD R2, R4, R2
                ADD R3, R3, #-1
                BRp MULT2           ; we are multiplying by 10
                ADD R2, R2, R5      ; add the input
                BRnzp INPUT2

What could be the problem?

0

There are 0 best solutions below