COA——Instruction Sets: Addressing Modes

发布于 2015-01-04  1.34k 次阅读


First, how is the address of an operand specified, and second, how are the bits of an instruction organized to define the operand addresses and operation of that instruction?

The most common addressing techniques

Immediate(立即数寻址):the operand value is present in the instruction. Operand=A. 操作数的值在指令中给出。数会存储成二进制补码形式,最左的一位为符号位。当这个值被传输到寄存器中时,就会进行扩展。优点:不用访问内存,节省时间。缺点:娄的尺寸受地址域的限制。地址域长度小于字长

Direct(直接寻址):the address field contains the effective address of the operand: EA=A. 早期的计算机中流行,但是现在不流行了。只需要一次内存访问,限制是可访问的空间太小。

Indirect(间接寻址):have the address field refer to the address of a word in memory. EA=(A). 显然可以有更大的寻址空间,但是需要两次访问内存空间,速度也就更慢了。

Register(寄存器寻址):the address field refers to a register rather than a main memory address. EA=R. 通常一个寄存器域是3至5位,所以能够访问的寄存器的个数为8到32个。好处就是寄存器域位数小,访问速度快。缺点就是可寻址空间太小了。

Register indirect(寄存器间接寻址):the address field refers to a memory location. EA=(R). 优缺点同间接寻址相似。其所具有的另一个优点就是访问内存的次数更少。

Displacement(偏移寻址):A powerful mode of addressing combines the capabilities of direct addressing and register indirect addressing. EA=A+(R),具有两个地址域。The value contained in one address field(value=A)is used directly.

  • Relative addressing, also called PC-relative addressing. The implicitly referenced register is the program counter(PC).  在大部分接近指令的寄存器访问,使用这种方式可以节省内存位。
  • Base-register addressing, the referenced register contains a main memory address, and the address field contains a displacement(usually an  unsigned representation) from that address.
  • Indexing, the address field references a main memory address, and the referenced register contains a positive displacement from that address. An important use of indexing is to provide an efficient mechanism for performing iterative operations. The value A is stored in the instruction's address field, and the chosen register, called an index register, is initialized to 0. After each operation, the index register in incremented by 1. Some systems will automatically do this as part of the same instruction cycle. This is known as autoindexing. postindexing: EA=(A)+(R), preindexing: EA=(A+(R)). 这两种寻址方式显然上以述提到的偏移寻址有差距,A本来是用来指明主内存的地址的,现在指明主内存地址的变成A指向的内存单元中的内容。而对于后一种情况,则是,在获取原来计算出来的地址的内容作为主内存的地址,也就是再进行了一次内存寻址操作。

Stack, pushdown list or last-in-first-out queue. 因为堆栈指针是存放在寄存器中的,所以堆栈寻址本质上来讲就是间接寄存器寻址。

Addressing Modes

 

Basic Addressing Modes

寻址方式的确定:不同的操作码会使用不同的寻址方式。此外,在指令中的一个或几个位会被用为模式域。

在一个没有虚拟内存的系统中,物理地址就会是主内存地址或是寄存器地址。而对于有虚拟内存了的系统而言,物理地址是虚拟地址或是寄存器地址,对于真实物理地址的映射使用页机制 ,并且对于程序员是不可见的。


公交车司机终于在众人的指责中将座位让给了老太太