📜  基于内存和基于寄存器的寻址模式之间的差异

📅  最后修改于: 2021-06-28 14:20:33             🧑  作者: Mango

先决条件–寻址模式
寻址模式是操作字段,用于指定需要执行的操作。必须对已经存储在计算机寄存器或存储器中的某些数据执行该操作。在程序执行期间选择操作数的方式取决于指令的寻址模式。 “寻址模式指定了一个规则,用于在实际引用操作数之前解释或修改指令的地址字段。 “基本上,我们如何解释指令中给出的操作数称为寻址模式。

寻址模式在很大程度上取决于CPU组织的类型。有三种类型的CPU组织:

  1. 单一累加器组织
  2. 通用登记机构
  3. 堆栈组织

寻址模式用于一种或两种目的。这些也可以说是使用寻址模式的优点:

  1. 通过提供诸如指向内存的指针,用于循环控制的计数器,数据索引和程序重定位之类的功能,为用户提供编程的多功能性。
  2. 减少指令寻址字段中的位数。

有多种寻址模式可用,并且取决于体系结构和CPU组织,可以应用哪种寻址模式。

Memory Based Addressing Modes Register Based Addressing Modes
The operand is present in memory and its address is given in the instruction itself. This addressing mode is taking proper advantage of memory address, e.g., Direct addressing mode An operand will be given in one of the register and register number will be provided in the instruction.With the register number present in instruction, operand is fetched, e.g., Register mode
The memory address specified in instruction may give the address where the effective address is stored in the memory. In this case effective memory address is present in the memory address which is specified in the instruction, e.g., Indirect Addressing Mode The register contains the address of the operand. The effective address can be derived from the content of the register specified in the instruction. The content of the register might not be the effective address. This mode takes full advantage of registers, e.g., Register indirect mode
The content of base register is added to the address part of the instruction to obtain the effective address. A base register is assumed to hold a base address and the address field of the instruction gives displacement relative to the base address, e.g., Base Register Addressing Mode If we are having a table of data and our program needs to access all the values one by one we need something which decrements the program counter/or any register which has base address. Though in this case register is basically decreased, it is register based addressing mode, e.g., In Auto decrements mode
The content of the index register is added to the address part that is given in the instruction to obtain the effective address. Index Mode is used to access an array whose elements are in successive memory locations, e.g., Indexed Addressing Mode If we are having a table of data and our program needs to access all the values one by one we need something which increment the program counter/or any register which has base address, e.g., Auto increment mode
The content of program counter is added to the address part of the instruction in order to obtain the effective address. The address part of the instruction in this case is usually a signed number which can be either positive or negative, e.g., Relative addressing mode Instructions generally used for initializing registers to a constant value is register based addressing mode,and this technique is very useful approach, e.g., Immediate mode.

基于内存的寻址模式主要取决于内存地址和某些内存位置上的内容。基于寄存器的寻址模式主要取决于寄存器以及某些寄存器中的内容,无论是数据还是内存地址。