KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having trouble understanding how the instruction jal works in the MIPS processor. My two questions are: a) What is the value stored in R31 after "jal": PC+4 or PC+8 ? b) If it's really PC+8 , what happens to the instruction at PC+4 ? Is it executed before the jump or is it never executed? In Patterson and Hennessy (fourth edition), pg 113: "jump-and-link instruction: An instruction that jumps to and address and simultaneously saves the address of the following instruction in a register ( $ra in MIPS)" "program counter ( PC ): The register containing the address of the instruction in the program being executed" After reading those two statements, it follows that the value saved in $ra should be ( PC+4 ). However, in the MIPS reference data (green card) that comes with the book, the jal instruction's algorithm is defined like this: "Jump and Link : jal : J : R[31]=PC+8;PC=JumpAddr" This website also states that "it's really PC+8 ", but strangely, after that it says that since pipelining is an advanced topic "we'll assume the return address is PC+4 ". I come from 8086 assembly, so I'm aware that there's a big difference between returning to an address and to the one following it, because programs won't work if I just assume something that's not true. Thanks.
Tags (comma-separated)
Save Edits
Cancel