how do i read an input in LC-3 where it checks for yes or no as an answer to a prompt and returns 1 if yes and no if 0. thanks

## All 2 Replies

you should probably get the recommended book Introduction to Computing Systems: From Bits and Gates to C and Beyond and read it. I don't know the first thing about it, so can't help you.

You're just in luck. I just finished writing a similar subroutine for my assembly class (uses the same textbook as mentioned above) to ask if someone wants to play again (we've made the game pong breakout). The following code is documented well enough for you to understand it clearly.

;
; Prompts the user for something.
;
; Preconditions:
;
;     TRAP x42 must be implemented in the OS in a way that it does not wait
;     for a key to be pressed. It should only check if a key's pressed once.
;
;	Must use the following declarations.
;
;	PROMPT .STRINGZ "Would you like to do something (y/n)? "
;	HEX_Y1 .FILL x79			; hex for 'y'
;	HEX_Y2 .FILL x59			; hex for 'Y'
;	HEX_N1 .FILL x6E			; hex for 'n'
;	HEX_N2 .FILL x4E			; hex for 'N'
;
; Postconditions:
;
;	If yes, return 1 in R0.
;	If no, return 0 in R0.
;
PROMPT_SR
LEA R0, PROMPT			; Load PROMPT to R0 be a string.
TRAP x22				; Print the string in R0.

POLL	TRAP x42 				; Get the key press. (This code assumes that
; TRAP x42 does not wait for a key to be pressed.

LD R4, HEX_Y1			; Load the hex value for 'y'.
NOT R4, R4;				; Get the 2's compliment
ADD R4, R5, R4			; R4 = R5 - R4

BRz YES				; If R5 is zero, then 'y' was pressed.

LD R4, HEX_Y2			; Load the hex value for 'Y'.
NOT R4, R4;				; Get the 2's compliment
ADD R4, R5, R4			; R4 = R5 - R4

BRz YES				; If R5 is zero, then 'Y' was pressed.

LD R4, HEX_N1			; Load the hex value for 'n'.
NOT R4, R4;				; Get the 2's compliment
ADD R4, R5, R4			; R4 = R5 - R4

BRz NO				; If R5 is zero, then 'n' was pressed.

LD R4, HEX_N2			; Load the hex value for 'N'.
NOT R4, R4;				; Get the 2's compliment
ADD R4, R5, R4			; R4 = R5 - R4

BRz NO				; If R5 is zero, then 'N' was pressed.

BRnzp POLL				; y/Y or n/N has not bee pressed, so poll again.

YES:
AND R0, R0, #0			; Clear R0.