您的问题没有说明您指的是哪种架构。
谈论不允许指令与字节对齐的设计,您描述的行为因CPU而异!
首先我们看一下8位CPU上“地址”的含义。在此类 CPU 上,当从内存中的一个字节到下一个字节时,地址会增加 1:
Address Meaning
0 1st byte in memory
1 2nd byte in memory
2 3rd byte in memory
3 4th byte in memory
4 5th byte in memory
...
The 68000使用与 8 位 CPU 类似的寻址方式。然而,存储器实际上是以 16 位为单位组织的,指令必须从偶数地址开始,并且长度是 16 位的倍数。因此,程序计数器始终包含偶数值。它会增加 2或每条指令期间 2 的倍数。
(仅允许使用奇数地址进行按字节内存访问(读/写),这实际上将在后台执行 16 位内存访问。)
For the TMS9900(16位CPU)地址加1为16位;可以访问之间的字节,但地址是通过添加 0x8000 形成的:
Address Meaning
0 1st byte in memory
0x8000 2nd byte in memory
1 3rd byte in memory
0x8001 4th byte in memory
2 5th byte in memory
...
程序计数器此处可能包含奇数或偶数值,但不能包含高于 0x7FFF 的值,因为这将引用非 16 位对齐的字节。当然,程序计数器会增加 1当指令长度为16位时。
The TMS320不允许寻址奇数字节:
Address Meaning
0 1st + 2nd byte in memory
not possible 2nd + 3rd byte in memory
1 3rd + 4th byte in memory
2 5th + 6th byte in memory
...
在此设计中,程序计数器还将增加 1当指令长度为16位时。
The 小MIPS(或类似的;我不记得正确的名称)设计是一种简化的 MIPS CPU,旨在供学生学习微芯片设计。它只允许 32 位内存访问和 4 对齐地址:
Address Meaning
0 1st to 4th byte in memory
1 address does not exist
2 address does not exist
3 address does not exist
4 5th to 8th byte in memory
5 address does not exist
...
在此设计中,程序计数器将始终包含 4 的倍数。因为每条指令正好是 4 个字节长,所以程序计数器将增加 4在指令期间。