#------------------------------------------- # This is a sample MIPS program # that reads the echos the keyboard input # to the console using SPIM's memory mapped # IO. This does not use the syscall. # # This example uses polling. That is it polls the # ready bits in the receiver and transmitter control # registers. # #-------------------------------------------- .data msg: .asciiz "\nDone." .text .globl main main: li $t0, 0xffff0000 # address of receiver control register # wait for keyboard input by polling # the receiver control register's # ready bit. read_poll: lw $v0, 0($t0) andi $v0, $v0, 0x01 beq $v0, $zero, read_poll # at this point we must have read a character and it is in # the receiver data register which is 4 bytes beyond the # receiver control lw $t1, 4($t0) # now see if the console can accept the character. # The address of the transmitter control register is # 8 bytes beyond the receiver control. # need to wait until ready to accept a new character write_poll: lw $v0, 8($t0) andi $v0, $v0, 0x1 beq $v0, $zero, write_poll # at this point the console is ready # to receive a character sw $t1, 12($t0) j main # keep reading/writing jr $ra