SRL Archive - General

Last HW help for my programming career,MIPs assignment?


rmorris7

2014-12-01 12:42:15

Create a MIPS function sendchar that outputs a single character to the secondary UART on our backend machines. The UART (Universal Asynchronous Receiver / Transmitter, aka "serial port") is a member of the venerable 16550 family of UARTs, documented here. Of particular interest to us is section 8 of the specification, starting on page 14, which describes the registers accessible to programmers. The UART control and status registers are memory-mapped, starting with base address 0xB8000400. The second UART is available through the XINU console daemon system by running xinu-console with the name of your mips-console backend followed by a "2". Thus, if running mips-console gave you backend "voc", running xinu-console voc2 in a second terminal window will give you access to voc's secondary UART interface. This main.S calls sendchar function, for which you will implement at the end of the file.

I have this so far

#include <mips.h>

.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 #base address for UART

jal getchar
move s1, v0

move a0, s1
jal sendchar


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. */


//sends character to UART2
//implement the sendchar function below
sendchar:

Any help is much appreciated

Brandon

2014-12-01 13:50:24

Do all of you guys take the same course or go to the same school? You all seem to have the same assignment.. In the future, try to make the post easier to read and put a clearer title.. Maybe something like (I'm just being picky but it's easier to read):

Title: "Help with last MIPS assignment".
Post: "Create a MIPS function: "sendchar", that outputs a single character to the secondary UART on our backend machines. The UART control and status registers are memory-mapped, starting with base address 0xB8000400. The main function calls sendchar, for which you will implement at the end of the file. (Insert starting code here)".
Extra: "(Any extra details.. voc, voc2, documentation, etc..)".


Anyone with any idea what you meant would immediately know the answer or at least be able to help faster.

Anyway,

https://villavu.com/forum/showthread.php?t=107098&p=1275369#post1275369

is the hint/answer. Your assignment is slightly different (in that you don't have to use kprintf and it's worded differently), but nonetheless the same.

rmorris7

2014-12-02 13:01:49

Wow yea seems similar, if he goes to Marquette then very well could be the same teacher. It seems like his questions wants the readchar implemented. Is this the same for the sendchar?

Turpinator

2014-12-02 14:42:48

From: rmorris7
Wow yea seems similar, if he goes to Marquette then very well could be the same teacher.

True story bro.

Brandon

2014-12-03 01:53:34

From: rmorris7
Wow yea seems similar, if he goes to Marquette then very well could be the same teacher. It seems like his questions wants the readchar implemented. Is this the same for the sendchar?


Assignment seems to be quite popular: http://www.mscs.mu.edu/~rge/cosc2200/homework-fall2013/HW10.htm with almost no answers on the net.. This thread is the second link on google. lol..


Anyway, it is very much the same procedure in reverse:


reading:
load effective address (the UART address)
load control register
if we can read (port not busy)
read char from address into register
print char
return to main

writing:
load effective address (the UART Address)
load control register
if we can write (port not busy)
write/move char into effective address
return to main

If there is no stack-frame setup, you may use the same label for the loop (provided you load the address once in main instead of on a per call basis)..


Ex:

main:
lbu $t0, 0xB8000400

getchar:
lb $t1, 5($t0) #control register to let us know if we can read/write.
andi $t1, $t1, 0x1 #is it ok for us to read? yes or no? 1 or 0.
beqz $t1, getchar #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 #return to main.


sendchar:
lb $t1, 5($t0) #control register to let us know if we can read/write.
andi $t1, $t1, 0x20 #is it ok for us to write? yes or no? 1 or 0.
beqz $t1, sendchar #if we cannot write to the port, try again until the port is not busy.
sb $v0, 0($t0) #write from v0 to the port.
jr $ra #return to main.


I did not test any of the above because I don't have the equipment but the code should work perfectly fine. Beware the infinite loops ("try again") in the above code.

rmorris7

2014-12-03 08:34:15

By "try again loop" you mean initializing the sendstr into a loop function?

Brandon

2014-12-03 11:51:29

From: rmorris7
By "try again loop" you mean initializing the sendstr into a loop function?


It is already in a loop. Recursive actually.


my_function:

#some instructions here..
beqz $t1, my_function #jump back to the beginning.. aka recursion.

#more instructions..
jr $ra

is the same as:


my_function:

while:
#some instructions here
beqz $t1, while

#more instructions..
jr $ra

However, the second version is safer if the function has an "epilogue" aka stack-frame. Why? Because a function that calls itself and does not restore the stack-frame before each call will cause a stack-overflow. The second function is a loop and not recursion.

In the cases above, neither function has a stack-frame/epilogue so both is safe. I was just mentioning it is all. I also mention that it is infinite because it tries infinitely until the port is not busy. If the port never gets freed up, it will loop forever. But don't worry about that for now.

[XoL]

2014-12-03 14:06:21

Lol I do go to marquette! Who is your teacher?

Rong Ge?

rmorris7

2014-12-03 14:28:19

Sure is! Wow what a coincidence

[XoL]

2014-12-06 14:32:53

From: rmorris7
Sure is! Wow what a coincidence


Ha thats awesome, I wish I still had my hardware materials to give you. What year are you/major? Send me a pm, I took all the classes basically, currently in programming languages then next semester game design/AI/app development in the summer if it is offered.

Sin

2014-12-06 16:47:14

People still use MIPS? Honestly curious here. I used to use it when I was writing subroutines for PSP games haha.

[XoL]

2014-12-06 18:34:11

From: Sin
People still use MIPS? Honestly curious here. I used to use it when I was writing subroutines for PSP games haha.


No one really uses it, its basically just used as a way to teach assembly.