In: Electrical Engineering
Write an LC-3 program that will repeatedly read a character from the keyboard. For each character read in, your program will print a neat message that echoes the input value, and the ASCII character code of the input character in hexadecimal. It will run forever: no HALT or End of processing is required.
For example:
Please press a key:
You pressed 'z' which is x7A
Please press a key:
You pressed '@' which is x40
Please press a key:
You pressed 'O' which is x4F
Please press a key:
You pressed '2' which is x32
Please press a key:
You pressed ' ' which is x20
..
Given Data:
Please press a key:
You pressed 'z' which is x7A
Please press a key:
You pressed '@' which is x40
Please press a key:
You pressed 'O' which is x4F
Please press a key:
You pressed '2' which is x32
Please press a key:
You pressed ' ' which is x20
Program:
.ORIG x3000
LD R1, NEG ; Load negative of count to R1
POLL1 (a)LDI R2, KSR ; Read Keyboard status register into R2
(b)BRzp POLL1 ; If "ready bit" not set, branch to POLL1
(c)LDI R0, KDR ; Read input character from Keyboard data register to R0
POLL2 (d)LDI R2, DSR ; Read Display status register into R2
(e)BRzp POLL2 ; If "ready bit" not set, branch to POLL2
(f)STI R0, DDR ; Write output character from R0 to Display data register
ADD R0, R0, #1 ; Increment the charater
ADD R1, R1, #1 ; Increment count
BRn POLL2
HALT
NEG .FILL xFFF6 ; -x000A
KSR .FILL xFE00 ; Keyboard status register location
KDR .FILL xFE02 ; Keyboard data register location
DSR .FILL xFE04 ; Display status register location
DDR .FILL xFE06 ; Display data register location
.END