The easiest part here is writing the loop, I can help you with that. I'm pretty rusty, but I'll do my best to get you started.
Looping can be achieved through temporary values, adding immediate values, branch instructions, and/or jump instructions.
The basic flow you're looking for sounds like:
- Create a counting variable (the i part in for (int i=..; i < ...; i++), as an example)
- Label the beginning instruction of your loop (that will look something like below)
label_name:
loop instructions
- Perform the loop instructions
- Increment your loop variable from step 1
- Populate $s2 with 2*n+74 (that's the part you have now)
- Branch to the beginning of the loop if your counter is not equal to your desired iteration count
Note: if you have enough loop instructions, you might have to use a more complicated branch/jump construct.
Example loop code:
andi $t1, $t1, 0
loop:
addi $t1, $t1, 1
add $s2, $s1, $s1
addi $s2, $s2, 74
bne $s2, $t1, loop
The next part you need is grabbing a value at a memory address, there are a few ways to go about that. You should look into the load/store instructions available in MIPS. In particular, I think you will want to utilize the lw (load word) instruction.
lw r1, label -> loads the word from memory stored at the addressed stored in 'label' into register r1
I Googled a little and http://pages.cs.wisc.edu/~cs354-2/cs354/karen.notes/MAL.instructions.html had some reasonable explanations and and examples of those instructions.
Accessing a specific bit requires utilizing some bit operations. In particular, I think you will find bit shifting and masking helpful.
MIPS offers a few instructions you might like:
sll d, s1, s2 d = logical left shift of s1 by s2 places
sra d, s1, s2 d = arithmetic right shift of s1 by s2 places
srl d, s1, s2 d = logical right shift of s1 by s2 places
and d, s1, s2 d = s1 & s2; bitwise AND
-- From the source I cited above
I hope that is sufficient to answer your question, and least get you going on the problem. I didn't want to just hand you the code, since it sounded like homework. If anything isn't clear or needs clarification, please just say so.
Hope at least some of all of that helps you!
AND
'ing a bitmask with 0 in the position of the bit you are interested in (...11011111 - to turn it off) andOR
ing a bitmask with 1 in the position you are interested in (...00100000 - to turn it on). – Andon M. Coleman