0

I'm writing a program to eventually translate words into pig latin and so far, I've stored the characters of the user input into separate memory locations (words can be 19 characters max).

Now I want to print another prompt when the user hits the enter key (after they're done typing their word in english). I've looked at some examples and I see that they have a line near the bottom of the program that says "NEWLINE .FILL x00A". I understand that this is the ASCII code for the enter key, but I'm not sure how to tell my program that another prompt needs to be displayed after hitting "Enter". Any tips or ideas are appreciated!

.ORIG x3000
START ST R1,SAVER1
ST R2,SAVER2
ST R3,SAVER3


LEA R1,PROMPT          ; loading the address of the first character of prompt
LOOP LDR R0,R1,#0      ; loading the first character into R0
BRz INPUT              ; if at 0, or at the end of the string, (.STRINGZ initializes length+1 memory locations, 
                       ; last location being 0), then go to instruction labeles "INPUT"; else go to next instructio



L2 LDI R3,DSR          ; loading the display status register into R3
BRzp L2                ; if display status register is not clear (meaning monitor is still processing char), then load DSR again
STI R0,DDR             ; store R0 into DDR's memory location
ADD R1,R1,#1           ; increment prompt address so that we can move through the string until the end
BRnzp LOOP             ; this will go to the LOOP instruction no matter what


LEA R4,ENGLWORD
INPUT GETC              ; now that user has typed, read char into R0
OUT                     ; write char in R0 to console
STR R0,R4,#0
ADD R4,R4,#1
BRnzp INPUT



LD R1,SAVER1           ; restore R1 to original value
LD R2,SAVER2           ; restore R2 to original value
LD R3,SAVER3           ; restore R3 to original value


SAVER1 .BLKW 1         ; allocates 1 memory location for SAVER1
SAVER2 .BLKW 1         ; allocates 1 memory location for SAVER2
SAVER3 .BLKW 1         ; allocates 1 memory location for SAVER3
ENGLWORD .BLKW 19


ENTER .FILL x0A

PROMPT .STRINGZ "English word: "          ; initializes a sequence of stringLength+1 memory locations to hold string
DSR .FILL xFE04                           
DDR .FILL xFE06
KBSR .FILL xFE00
KBDR .FILL xFE02
HALT
.END
skaffman
  • 398,947
  • 96
  • 818
  • 769
Michelle
  • 9
  • 6
  • I'm not familiar with the simulator(?) you're running this in, but it seems to me like you should be watching for the value 13 (Carriage Return) in the loop where you read the user input. Once you get that character you exit the loop and display another prompt just like you showed the first prompt. – Michael Apr 09 '15 at 07:03
  • Thank you! I'm confused as to how to check for the value 13, would I use a BR instruction?? – Michelle Apr 09 '15 at 18:19
  • @Michael Can you take a look at this? http://stackoverflow.com/questions/29981266/how-to-increment-a-letter-in-string-in-lc3 – committedandroider May 01 '15 at 05:30

0 Answers0