Question

Question asks:

Write a piece of MIPS code that, given values in $s0 and $s1, put into the $t* registers the following:

$t0 = $s0
$t1 = $s1
$t2 = $t0 + $t1
$t3 = $t1 + $t2
...
$t7 = $t5 + $t6

In other words, for each register from $t2 to $t7, it stores the sum of the previous two $t* register values. The $s0 and $s1 registers contain the initial values. Don't set the value of $s0 and $s1 in your code. Instead, learn how to set it manually with MARS. Save your code into sum.s.

ok that's not hard:

move $t0 $s0 
move $t1, $s1 
add $t2, $t0, $t1    
add $t3, $t1, $t2 

... and so on

But what does the last part mean? "Don't set the value of $s0 and $s1 in your code. Instead, learn how to set it manually with MARS. Save your code into sum.s." ?

Was it helpful?

Solution

It means that you should not include input-setup operations like:

move $s0, 0xBAAD
move $s1, 0xBEEF

(pardon me if syntax is wrong)

Instead, you should configure your MARS IDE so that it will automatically set all the input parameters on the fly, just before your assembly script is run for debugging or testing. Of course you will have to specify what values those auto-set-parameters will have, but the point is to show you that you can easily(?) (re)configure the test inputs instead of hardcoding them.

I've briefly browsed the http://courses.missouristate.edu/kenvollmar/mars/ site, but I cannot find any notes. It should be described somewhere in the IDE's docs or help system, if any is there..

EDIT:

Ok, maybe I've found it.

Quoting from "Help and Info":

Contents of any data segment memory word and almost any MIPS register can be modified by editing its displayed table cell. Double-click on a cell to edit it and press the Enter key when finished typing the new value. If you enter an invalid 32-bit integer, the word INVALID appears in the cell and memory/register contents are not affected. Values can be entered in either decimal or hexadecimal (leading "0x"). Negative hexadecimal values can be entered in either two's complement or signed format. Note that three of the integer registers (zero, program counter, return address) cannot be edited.

So, for example, instead of hardcoding the values, you can set a breakpoint at the very first instruction of your code, run the program, and when it hits that breakpoint - edit the registers and enter input values into $s0/$s1. I wish it is nicer a bit than that, but I cannot find anything else.

There are also 'Macros' feature in this IDE, so you maybe will be able to create some small script that will take two numbers and put them into those two registers, or maybe even there already is such macro - I have no idea - please dig it through yourself, I don't even have this software at my board:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top