问题
I am doing a practice question from Question 7
Shouldn't the address I highlighted be x3307, not x3308?
The way I reasoned this out was that (PC before 2nd instruction) = (PC after 1st instruction).
The PC after 1st instruction is x3301. Therefore when the second instruction executes, the PC, x3301 will be incremented by 6 to x3307.
Does everyone agree? Or did I miss something and R3 should actually store x3308?
回答1:
PC-relative offsets are applied on top of the already incremented PC, that is the "after" value of the PC, or in other words, the address of the following instruction.
回答2:
From Appendix A of Patt & Patel, the notational conventions (Table A.1) says this about the PC:
Program Counter; 16-bit register that contains the memory address of the next instruction to be fetched. For example, during execution of the instruction at address
A
, the PC contains addressA + 1
, indicating the next instruction is contained inA + 1
.
the specification for the LEA
opcode says:
An address is computed by sign-extending bits [8:0] to 16 bits and adding this value to the incremented PC.
So when the second instruction is being executed the 'incremented PC' is 0x3302
. Adding 6 to that results in 0x3308
.
来源:https://stackoverflow.com/questions/30179866/shouldnt-r3-hold-address-x3307