EE 361 Homework 6 Solution
Problem A
There are two IO registers to transmit ASCII charcters to a computer
terminal.
- Transmitter Data Register: Its an 8-bit register with address
0xffff0000. ASCII character bytes are sent to the terminal from
here. The Register has two states: "Ready" and "Not Ready". If the Register
is Ready then an ASCII character can be loaded into it (in the low order
byte of the register) by using the "sb" ("store byte) instruction (see
pg. A-67). Then the Register will send the byte to the terminal. On the
other hand, if the Register is Not Ready then it will ignore any "sb"
instruction. Note that this Register is write only.
- Transmitter Control Register: Its address is 0xffff0004
. This 8-bit register has status bits for the Transmitter Data Register.
In particular, Bit 2 indicates when the Transmitter Data Register is
Ready. If the Bit is equal to "1" then the Transmitter Data Register is
Ready, and if the Bit is "0" then the Transmitter Data Register is Not
Ready.
Solution:
putchar:
lui $t0,0xffff #
Load upper half with $t0 all ones. If that doesn't work then you can
try lui $t0,-1.
# Note that the lower half of $t0 is filled with zeros. Anyway,
now $t0 = ffff0000
wait:
lbu $t1,0xc($t0) # Check if the transmitter data
register is ready
andi $t1,$t1,4 # We're masking with 000....0100
beq $0,$t1,wait # If the bit2 = 0 then it's
not ready
# At this point, bit 2 =1, so we proceed to output the char c.
sb $a0,0($t0) # Write the byte "c"
(that's in $a0) to the transmitter data register.
# If that doesn't work, you can try sw $a0,0($t0)
jr $31