2

I have a problem with this LC-3 program, I can't get the string to display from the if/else statement. I don't know if I'm doing the statement wrong, or if I am displaying the string wrong. The goal is to have it display the IF when the user enters 0 and the else (halt the program) when they enter a 1.

    .ORIG   x3000


START:
; clear registers
    AND R0, R0, 0
    AND R1, R0, 0
    AND R2, R0, 0
    AND R3, R0, 0
    AND R4, R0, 0

; print greeting
    LEA R0, GREETING
    PUTS

; get user-input
; echo it back
    GETC
    PUTC

; store entered string 
    ST  R0, USERINPUT

;FIRST IF STATEMENT
OUTPUT  LD R2, USERINPUT
    BRz ENDIF
    LEA R3, GREETING
;ELSE
    ENDIF
    LD R2, USERINPUT
    HALT
    DONE

; stop the processor
    HALT

    GREETING:   .STRINGZ    "\nWelcome to the game.\nDo you want to play?\n0:Yes   1:No\n: "
    GREETINGTWO:    .STRINGZ    "\nTest if statement: "

    ; variables
    USERINPUT:  .FILL   0
    ; end of code
    .END
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Jimmy
  • 57
  • 1
  • 5

1 Answers1

1

You're displaying the string incorrectly.

LEA only loads the effective address of a label/memory offset, it does not print it out. If you want to print out a string, you must call TRAP x22 (macroed to PUTS), as in the 14th line of your code snippet above.

aqua
  • 617
  • 4
  • 12