MIPS assembly, register traversing?
Hello and thanks in advance,
My question is if it is possible to go thro开发者_C百科ugh registers like having a pointer in one ($t0) and moving the pointer to another one ($t1).
What i actually want to do is in one loop read 8 integers and store them in ($s0-$s7)
You could try changing the bits in the sw
opcode to point to increasing registers, but that's a terrible idea. I think your best bet is to just write your unrolled loop yourself:
lw $s0, $t0
addi $t0, $t0, 4
lw $s1, $t0
...
Rearrange things to minimize stalls, but that's about as good as you're going to get.
You want to have a register number be variable? I don't know MIPS inside and out, but I doubt it's possible. The only ISAs I know of that have anything like that are SPARC (register windows, not usable for what you want) and IA64 ("rotating registers", could be used for what you want, but only with floating point).
I'm not aware of an existing MIPS architecture that supports referencing a register by the contents of a register, which would allow the type of thing you suggest, like:
move $t0, $zero
mover $t0, $s0 # $s0 = register($t0) = register(0)
addi $t0, 1
mover $t0, $s1 # $s1 = register($t0) = register(1)
addi $t0, 1
...
Although in any case it's not a good idea in my opinion, for a few reasons. Firstly, you're dealing with a very small number of registers anyway, so there is a small upper bound on the loop in any case, making the direct approach not much less flexible.
More importantly, a loop like that would be horribly inefficient. It would initialise, increment, perform a move
and a branch check (at least) for every iteration. Even without taking branch stalls into account this is at least 3x slower than simply:
move $t0, $s0
move $t1, $s1
...
move $t8, $s8
精彩评论