# MIPS input using memory mapped IO and polling. .data announce: .asciiz "You typed '" apo_nl: .asciiz "'\n" .text .globl main main: # $s0 contains ascii code for 'q' # $s1 contains base address of keyboard registers # $s2 will be a copy of Reciever Control Register # $s3 will be a copy of Reciever Data Register li $s0, 'q' li $s1, 0xffff0000 # $s0 = address of Receiver Control Register waitloop: lw $s2, 0($s1) # $s2 == contents of RCR at 0xffff 0000 andi $s2, $s2, 0x1 # Clear all bits in the copy of the RCR, # except the ready bit, which is bit 0. # test RCR[0]. If it's 0, then we have nothing to read. # Go back and try again beq $s2, $zero, waitloop # RCR[0] == 1! This means there is a new char in the RDR! # Time to rock and roll. # Set $s3 = RDR. RDR is at 0xffff 0004. # Remember that RDR == 0x0000 00??, since the # undefined bits read as 0. lw $s3, 4($s1) # Is this char 'q'? beq $s3, $s0, done # Not a 'q'. Print message la $a0, announce li $v0, 4 syscall # Print "You typed " # Print the character. move $a0, $s3 li $v0, 11 # Syscall 11 is print_char syscall # Print "`\n" la $a0, apo_nl li $v0, 4 syscall # go back an wait for another character j waitloop done: # bye jr $ra