
Originally Posted by
[XoL]
***
How about that? keep getting a compile error though on the loop
Your code looks like it will work.
Currently:
s0 holds the address of the port or memory location we want to read from.
v0 will hold our result.
ASM Code:
li $s0, 0xB8000400 #access register/UART port.
So:
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
Another example:
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
I think your code may work as well but I don't have a mips assembler readily available to test and I'm writing in Notepad (no notepad++) atm either.