Question

I'm writing a MIPS program to sort 8 ascii atrings, the addresses of which are in registers $t0-7. When comparing two strings, I need to pass the addresses into a function (by saving into $s0 and $s1). If I want to do this in a loop, how can I increment the register values? Can I do this? Or do I need to put the addresses all in memory instead?

For example, if my loop is like this, in pseudocode:

for loop with index i:
 move address from register j into $s0
 move address from register j+1 into $s1
 call function for return value
 use return value to perform swapping operation
 increment i
 jump back to loop if i<bound

Where j is arbitrary, I'm just showing how I need to retrieve from two consecutive registers.

Is there a way to use offset notation for registers like you can with memory locations?

Was it helpful?

Solution

"Is there a way to use offset notation for registers like you can with memory locations?"

No ! Access to registers are hardcoded in assembly instructions. You can't access to a computed register.

OTHER TIPS

To increment a register, add 1 to it. Like this:

addiu $t0, $t0, 1

There are many registers on MIPS. If you don't want to trash the base address in some register, use another register for the base+offset, and increment it as necessary. Or use a third register as loop counter, and recalculate base+offset as necessary.

You can if you really want to, by using self-modifying code. But I doubt you want to, would probably wreak havoc on the cache and produce overhead bit-twiddling the machine instructions.

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