Search code examples
javadebugginglc3

Simple guessing game error


Ok so first this is the description of the program: The program will simulate a simple guessing game. The answer to the guessing game will always be 6. The program will continually ask the user to guess a number between 0 and 9. The user enters the guess from the keyboard. If the guess is larger than 6; the program should output: Too big. If the guess is smaller than 6; the program should output: Too small. When the user finally guesses correctly, the program will output: Correct! You took # guesses. where # is the number of guesses it took the user. If after 9 guesses, the user has not correctly guessed the number, the program should output:Game over. Correct answer is 6. You do not need to check for invalid input (alphabetical characters, punctuation, etc).

This is the error i'm receiving: Line 43: Expected label or 9 bit signed PC offset, but found 'R3' instead. And here's my code:

.ORIG X3000

LD R2, SIX
LD R3, COUNTER

IN
ADD R1, R0, #0
ADD R0, R1, R2
BRn TOOLOW
BRp TOOHIGH
BRz GG

AGAIN:
IN
ADD R1, R0, #0
ADD R0, R1, R2
BRn TOOLOW
BRp TOOHIGH
BRz GG

TOOLOW:
LEA R0, LOW
PUTS
ADD R1, R0, #0
ADD R3, R3, #1
ADD R0, R3, #-9
BRn AGAIN
BRz LOSE

TOOHIGH:
LEA R0, HIGH
PUTS
ADD R1, R0, #0
ADD R3, R3, #1
ADD R0, R3, #-9
BRn AGAIN
BRz LOSE

GG:
ADD R3, R3, #1
LEA R0, WIN
PUTS
LEA R0, R3
PUTS
LEA R0, WIN2
PUTS
HALT

LOSE:
LEA R0, GAMEOVER 
PUTS
HALT

SIX .FILL #-54
COUNTER .FILL #0
LOW .STRINGZ "Too small."
HIGH .STRINGZ "Too big."
WIN .STRINGZ "Correct! You took "
WIN2 .STRINGZ " guesses."
GAMEOVER .STRINGZ "Game over. Correct answer is 6."

.END

So how can I fix the error?Thanks in advance.


Solution

  • That error is pointing to this line

    LEA R0, R3

    Your program is trying to use register R3 like a label and the assembler won't allow it.

    If you want to move the value stored in R3 into R0, you will need to do something like the following:

    AND R3, R3, #0    ; clear R3
    ADD R3, R3, R0    ; store the value in R0 into R3