我们来查看该指令。
16-bit/32-bit displacement
PC indirect with displacement(带转移的PC间接寻址)
MOV.L @(disp:8,PC),R7
The effective address is the sum of PC value and an 8-bit displacement(disp). The value of disp is zero-extended, and is doubled for a word operation, and quadrupled for a longword operation. For a longword operation, the lowest two bits of the PC value are masked.
Word:
PC + disp * 2
Longword:
PC & H'FFFFFFFC + disp * 4
9 **** begin pool ****
10 0000F00C FF00 data for source-line 4
11 0000F00E 0000 alignment code
12 0000F010 FFFF0000 data for source-line 3
13 0000F014 0000F000 data for source-line 5
14 **** end pool ****
15 9 .END
-----------------------------------------------------
PIC的特点是,它被加载到任意地址空间都可以正确的执行。其原理是PIC对常量和函数入口地址的操作都是基于PC+偏移量的寻址方式。即使程序被移动,但是PC也变化了,而偏移量是不变的,所以程序仍然可以找到正确的入口地址或者常量。
例如:SH里面的BRA指令就可以用来设计PIC
BRA _main
编译后:
_main * 2 + PC -> PC