0
votes

These 3 questions are the only ones I didn't understand in class. My professor is horrible & isn't clear at all when explaining the material which is why I had to come here. I have answers for some of them but I don't know if they're correct. Thank you so much in advance, I greatly appreciate that you took the time to read.

  1. Give the assembly instruction in order to:

a) Isolate Byte 1 of a word in $s0 using only logical shifts.

b) Complement the lower 12 bits of register $t0 but leave all the other bits unchanged. If possible, use immediate format instruction. If it's not possible to use immediate format instruction, explain why and use mask a register instead.

c) Mask the shift amount of an R-Format instruction and clear the rest of the bits. If possible, use immediate format instruction. If it's not possible to use immediate format instruction, explain why and use mask register instead.


  1. This code is for question 2a

loop: slt $t2, $t0, $t0

   bne $t2, $zero, loop

   j done

done:

a) The address of bne is 400. Give its target address.


  1. Given the assembly instruction beq $t1, $t2, Next

a) If the address of the instruction is 800bytes and Next is at target address 680 bytes. What will be the value of the offset field of the instructions binary representation? Give the offset value in decimal and in binary.


My answers:

1a. sll $t0, $s0, 16 srl $t1, $t0, 24

b. xori (can't figure out the rest)

c. andi $t0, $s1, 0x07c0

2a. 424 (400 + 4) + (4 * 3) = 416

b.

3a. I think you have to do 800-680 but I don't know for sure. What I do know is that the offset value has to be 16 bits when written in binary.

1
There are free MIPS simulators like SPIM and MARS which you could use to verify your answers. - Michael
I understand. But I want know how to do it by hand instead of using a simulator. - reppo

1 Answers

0
votes

1a is wrong, if you don't shift the same amount it can't be correct. Shift 24 bits left to clear the top 24 bits then shift 24 bits right to return the low byte to its place.

1b would be a xori 0xfff however the 12 bit immediate in the instruction is sign extended automatically so that would actually mean xori 0xffffffff which is not what you want. That's why you need to use a mask register.

1c is correct

2a the loop is clearly just before the bne so the address must be bne-4=396.

3a yeah 800-680 but you need to account for the fact that the PC is already updated and the offset is encoded in words, so you need to divide by 4 giving (800-680)/4-1=29