SRL Archive - General

Assembly, got skill?


[XoL]

2013-12-11 18:40:27

Create a MIPS function readchar that reads a single character from the secondary UART on our backend machines. An incomplete main-hw10-q2.S is provided for you. Rename it to main.S for this question. This main.S calls readchar function, for which you will implement at the end of the file to input characters from the second UART, and echoes them back using sendchar until an EOF character is seen.


Here is the code I was given (Am require to use) Anyone know what this question is asking me to do? and is anyone capable of doing this? I honestly hit a brick wall



#include <mips.h>
.data

FMT: .string "the char is %c\r\n"

.text
.globl main

main:
/* Function prolog. */
/* Sets up environment for user program to execute. */
addiu sp, sp, -32 /* Make room on Stack for O/S values. */
sw ra, 28(sp) /* Store O/S return address on Stack. */
/* Start of your program. */

li s0, 0xB8000400//THR

loop:
jal readchar
li t0, 4
beq v0, t0, done
move s2, v0
la a0, FMT
move a1, v0
jal kprintf
// move a0, s2
// jal sendchar
b loop





done: /* End of your program. */
/* Function epilogue. */
/* Restores the environment from the O/S. */
lw ra, 28(sp) /* Restore O/S return address. */
addiu sp, sp, 32 /* Restore O/S stack pointer. */
li v0, 0 /* Return value of 0 (normal exit). */
jr ra /* Return to Operating System. */


//reads character
//implement the readchar function below
readchar:

Help would glaadlyyy be appreciated, and or compensated if wanted.

[XoL]

2013-12-11 20:38:46

wait dumb comment, hmm thank you! will look into this more

[XoL]

2013-12-11 21:11:58



#include <mips.h>
.data

FMT: .string "the char is %c\r\n"

.text
.globl main

main:
/* Function prolog. */
/* Sets up environment for user program to execute. */
addiu sp, sp, -32 /* Make room on Stack for O/S values. */
sw ra, 28(sp) /* Store O/S return address on Stack. */
/* Start of your program. */

li s0, 0xB8000400//THR

loop:
jal readchar
li t0, 4
beq v0, t0, done
move s2, v0
la a0, FMT
move a1, v0
jal kprintf
// move a0, s2
// jal sendchar
b loop





done: /* End of your program. */
/* Function epilogue. */
/* Restores the environment from the O/S. */
lw ra, 28(sp) /* Restore O/S return address. */
addiu sp, sp, 32 /* Restore O/S stack pointer. */
li v0, 0 /* Return value of 0 (normal exit). */
jr ra /* Return to Operating System. */


//reads character
//implement the readchar function below
readchar:
myloop:
lb t0,5(s0)
andi t0,t0,0b00100000
beq t0, zero, myloop
sb a0, 0(a0)
jr ra


***
How about that? keep getting a compile error though on the loop

Brandon

2013-12-11 21:30:39

From: [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.

li $s0, 0xB8000400 #access register/UART port.

So:

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:

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.

[XoL]

2013-12-11 22:34:53

Got it:

li t0, 0xB8000400
myloop: lb t1, 5(t0)
andi t1, t1, 0x1
beq t1, zero, myloop
lb v0, 0(t0)
jr ra

Edit: FML, Wish I refreshed more often didn't know you wrote it out! lol well my code is basically identical, thanks brandon really appreciate it!