Which of the following statements best explains why the shifting operation is necessary?
For this problem ( http://i.imgur.com/n1mYNfn.jpg ), I have the following questions/confusions.: 1) What is this diagram about? (Please, answer that in a way that teaches it to people who have never seen such a thing before.) 2) On the statement referred to by the letter d (which is the correct answer), the offset is the offset of what? 3) What is this offset used for? 4) What is a SIGN-EXTENDED offset? 5) What is a Branch Target Adress? If you want to ask me something before you answer, go ahead. Any help in fully understanding everything about this problem would be GREATLY appreciated!
1) What is this diagram about? (Please, answer that in a way that teaches it to people who have never seen such a thing before.) - the diagram is about computing + updating the PC for branching related jumps. - it takes present PC values and adds offset to it after shifting offset left by 2 bits -so this happens for branch jump :- PC <- PC + (left shift 2 of offset)
2) On the statement referred to by the letter d (which is the correct answer), the offset is the offset of what? - d is incorrect answer, correct answer is a. the shown hardware converts byte aligned offset to word aligned address. bytes -> words - the offset is the offset from PC
3) What is this offset used for? - offset is used to jump to a statement in a branch instruction. these kindof jumps involve target adress thats very nearby present PC. thats the reason we use offset from PC.
4) What is a SIGN-EXTENDED offset? - offset is 16bit only. before adding it to PC, we need to extend it to 32 bits. this we do by populating the high 16 bits with the MSB of offset.
5) What is a Branch Target Adress? - branch target address is the final computed address : PC + (left shift 2 of offset)
4) What ganeshie8 said. Sign-extension is necessary to make sure that a jump backwards (a negative offset) remains negative by putting all 1's in front of the operand. 2) I disagree with ganeshie8 here. If you go from a byte-address (let's say byte 1000110) to a word address, you'll need to remove the last two bits (assuming your word-size is 4 bytes), so you need to shift RIGHT 2 (word address will become 10001). If you want to go the other way, from word address to byte address, you'll need to add two bits, or shift LEFT 2. E.g. word 10011 will start with byte 1001100.
thanks for correcting :)
Thank you both for your answers. :)
Join our real-time social learning platform and learn together with your friends!