先决条件 – 寻址模式
寻址模式是操作字段指定需要执行的操作。该操作必须对一些已经存储在计算机寄存器或内存中的数据执行。在程序执行过程中选择操作数的方式取决于指令的寻址方式。 “寻址模式指定了在实际引用操作数之前解释或修改指令地址字段的规则。 “基本上我们如何解释指令中给出的操作数被称为寻址模式。
寻址模式很大程度上取决于 CPU 组织的类型。 CPU 组织分为三种类型:
- 单累加器组织
- 一般注册机构
- 堆栈组织
寻址模式用于一个或两个目的。这些也可以说是使用寻址方式的优点:
- 通过提供诸如内存指针、循环控制计数器、数据索引和程序重定位等功能,为用户提供编程的多功能性。
- 减少指令寻址字段中的位数。
有多种寻址模式可用,这取决于可以应用哪种寻址模式的体系结构和 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. |
基于内存的寻址模式主要依赖于内存地址和存在于某个内存位置的内容。基于寄存器的寻址模式主要依赖于寄存器和存在于某个寄存器中的内容,要么是数据,要么是某个内存地址。