EE 361 Homework 6 Solution

Problem A

There are two IO registers to transmit ASCII charcters to a computer terminal.

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