PC-relative addressing
It usually used in conditional branches. PC in PC-relative addressing mode bring a meaning of "special purpose register, Program Counter", which address of next instruction to be fetched are stores inside.
The offset is the number of instructions forward or backward that must be skipped to get to the instruction labeled Label. The offset value can be an interpreted label value or immediate value.
Thus, 4*offset + PC+4 is the address of the instruction labeled with Label.
The effective address is the sum of the Program Counter and offset value in the instruction. The branch target is determine by effective address.
The effective address is the sum of the Program Counter and offset value in the instruction. The branch target is determine by effective address.
PC-relative addressing occurs in branch instructions, such as beq and bne. These instructions are I-type instructions, with the following format.
The immediate value is only 16 bits, which means we can't address a large range of memory.
To implement loops or if-else statements, Branch instructions are used primarily.
When jump to a statement in an if-else or loop, we will typically jump to a nearby instruction from the one we jumped from. It makes sense to jump relative to the PC, because the instruction we jumped from must have been the one at PC
For example, if you had a branch instruction at address 1000, then normally you'll jump somewhere near the branch instruction.
PC relative addressing in action
Below diagram shows how an effective address is generated when using PC relative addressing mode.
SOON BOON JIAN
B031210199
The immediate value is only 16 bits, which means we can't address a large range of memory.
To implement loops or if-else statements, Branch instructions are used primarily.
When jump to a statement in an if-else or loop, we will typically jump to a nearby instruction from the one we jumped from. It makes sense to jump relative to the PC, because the instruction we jumped from must have been the one at PC
For example, if you had a branch instruction at address 1000, then normally you'll jump somewhere near the branch instruction.
PC relative addressing in action
Below diagram shows how an effective address is generated when using PC relative addressing mode.
SOON BOON JIAN
B031210199
i can understand well.^^
ReplyDeleteOh it's very useful to me! Thx a lot!
ReplyDelete