2

Ok, so I have to convert the following C code segment to MIPS Assembly.

f = k + A[5]

The question tells me that f is stored in register $s3, k is in $s2 and the base address of array A is $s4. This is what I put as my answer:

add $s3, $s2, $s4

Is this correct? Do I have to do anything special with the 5 in the array? I'm very new to MIPS, so any and all help if VERY much appreciated.

1

2 Answers 2

1

Are you working on this for homework? If so, are you actually writing out an executable program or just responding to a list of questions?

Either way yes, you do need to account for the 5 in the array. The question is telling you that $s4 points to the base address of the array, not the 5th index.

hint: A[0] would be at the same address as the base of the array.

Sign up to request clarification or add additional context in comments.

2 Comments

@wazy thanks for the heads up. I noticed nothing came up when I went searching to retag, but didn't find anything. Is there a new tag for homework type questions or does SO condone just giving away hw answers these days?
For anyone interested, I found this link on meta. Indeed the homework tag has been deprecated. Editing my response to more politely ask if the question is homework, but still only guiding towards correct answer.
0

Try this out. (Off the top of my head). Remember each index is * 4.

li $t2, 6            # init 6 to $t2
addi $t2, $t2, $t2   # $t2 * 2
addi $t2, $t2, $t2   # $t2 * 2
addi $t1, $t2, $s4   # A[6 * 4] 
lw $t4, 0($t1)       # load A[6] int $t4
addi $s3, $s2, $t4   # obtain f

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.