# Solution for Spring 2002 CSCI 255 Homework 7

## Problem 1

Do problem 2 of Quiz 4.

See the Quiz 4 Solution.

## Problem 2

Write a trap routine that reads a single character typed on the keyboard. If that character is an upper-case letter, it is echoed to the CRT. Otherwise, it is ignored.

Your program should use the keyboard and CRT device registers.

``````
.ORIG   x0C00
HW7TRP  ST      R0,R0SAV         ; Save used registers
ST      R1,R1SAV

HW7INL  LDI     R1,AKBSR         ; Loop to read input character
BRzp    HW7INL
LDI     R0,AKBDR

LD      R1,ASC0
ADD     R1,R0,R1         ; R1 = CHAR - '0'
BRn     HW7RET           ; Don't echo is CHAR < '0'
ADD     R1,R1,#-9        ; R1 = CHAR - '9'
BRp     HW7RET           ; Don't echo if CHAR > '9'

HW7OUL  LDI     R1,ACRTSR        ; Loop to read output character
BRzp    HW7OUL
STI     R0,ACRTDR

HW7RET  LD      R0,R0SAV
LD      R1,R1SAV
RET

ASC0    .FILL   #-48; -'0'
AKBSR   .FILL   xF400
AKBDR   .FILL   xF401
ACRTSR  .FILL   xF3FC
ACRTDR  .FILL   xF3FF
R0SAV   .BLKW   1
R1SAV   .BLKW   1

.END
```
```