Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I posted this question a little while ago but I still have some questions

ID: 3702613 • Letter: H

Question

Hello. I posted this question a little while ago but I still have some questions: I am given the following offest:

I also gave this example:

80000 bne $0 $s5 Exit

80004

80008

8000C

80010 Exit

Would the value in 80000 Exit be 3?

Thanks

The response was:

I'm not sure if this is corrent but my instructor seems to do this a different way. In the top example, because the program counter is always one instruction ahead, the distance is 2. When executing the branch, the program counter is at 80010 already. The label is at 80018. Subtracting the two gives 8 which is 2 ^ 4. In the example I provided, wouldn't the program counter be at 80004 when executing the branch? If so, then wouldn't the offset be 80010 - 80004 which would equal decimal 12 or 3 ^ 4? This is what the top given example looks like to me.

Thanks.

Addressing Example Assume Loop at location 80000 PC value when bne is executed (0x80010) + 2 x 40x80018 80000 Loop: sl $t1, $s3, 2 80004 80008 8000C 80010 80014 80018 Exit: add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 Loop Il bne Sto, $s5, 2 //j 20000 [31:28] of PC value when j is executed (0x0) : 0x20000 x4 0x80000

Explanation / Answer

That answer previously provided gives the offset between bne instruction and exit label. But the answer for the question you are asking is 3.. since exit label is 4 instructions away it's PC value has to be increased by 3*4 (since PC value as you said is already at next instruction) so, bne instruction would be as follows bne $0, $s5, 3