ASM Code:
readchar:
lbu $t0, 0xB8000400 #load the port/mapped io. maybe not needed because s0 contains 0xB8000400 aka port address
try:
lb $t1, 5($t0) #control register. t0 can be replaced with $s0. t1 will tell us if it is ok to read from the port or not.
andi $t1, $t1, 0x1 #is it ok for us to read? yes or no? 1 or 0? Might have to be: 0b00100000 like you have above.
beq $t1, $0, try #if we cannot read from the port, try again until the port is not busy.
lb $v0, $0($t0) #read the character into v0.
jr $ra
ASM Code:
readint:
lui $t0, 0xB8000400 #maybe not needed but s0 contains 0xB8000400 aka port address.
waitl:
lw $t1, 0($t0) #control register. $t0 can be replaced with $s0.
andi $t1, $t1, 0x1 #t1 will store whether or not we can read from the port. Might have to be: 0b00100000 like you have above.
beq $t1, $0, waitl #keep looping until we successfully read a character from the port.
lw $v0, 4($t0) #read our character into the #v0 register.
jr $ra