📌  相关文章
📜  相对寻址模式和直接寻址模式之间的差异

📅  最后修改于: 2021-06-28 09:24:37             🧑  作者: Mango

先决条件–寻址模式
在指令周期过程的指令提取操作中,寻址模式至关重要。寻址模式是在实际执行操作之前在指令字中对操作数进行寻址的方式。

1.相对地址模式:
在这种模式下,通过将CPU寄存器的内容和指令字的地址部分相加来计算操作数的有效地址(EA)。有效地址是通过将位移(指令中给出的中间值)和寄存器值相加而得出的。指令的地址部分通常是带正负号的带正负号。这样计算出的有效地址是相对于下一条指令的地址的。

EA = CPU Register + Displacement

图– PC相对寻址模式
相对寻址模式可以进一步分为三种类型–

  • PC(程序计数器)相对寻址模式。
  • 索引寄存器相对寻址模式或索引寻址模式。
  • 基址寄存器寻址模式。

2.直接地址模式:
在直接地址模式下,操作数的有效地址等于指令的地址部分,即指令的地址部分指示包含操作数的存储位置。

例子 –
ADD R1,4000,其中4000是位置的有效地址。

图–直接地址模式

在此示例中,存储位置4000包含操作数100,该操作数100被添加到R1的内容中并被存储在R1中。

相对寻址模式和直接寻址模式之间的区别:

S.NO. RELATIVE ADDRESSING MODE DIRECT ADDRESSING MODE
1. Effective address is calculated by adding the contents of the CPU Register with the address part of the instruction. The address for fetching the operand is already provided in the address part of the instruction. It is not calculated.
2. Relative mode has three types : PC Relative, Index Register Relative, Base Register Relative Addressing modes. Direct addressing mode has no types.
3. It results in shorter address field in the instruction format as the relative address can be specified with a small number of bits. It results in longer address field in the instruction format as it requires more number of bits to designate the entire memory address.
4. It is often used with branch type instructions since it directly updates the program counter. It is not used in branch type of instructions.
5. It is used for writing relocatable code, position independent code, i.e. for program relocation at run time. It is used to access static data.
6. It is used to implement array addressing, records. It is used to implement variables.
7. It is used to handle recursive procedures. It cannot handle recursive procedures.