PC-relative with displacement
Pc value is the instruction address.
instructionformat:@(disp:8, PC)
Effective address caculation method:
Effective address is PC+4 with 8-bitdisplacement
disp added. After disp is zero-extended, it is
multiplied by 2 (word), or 4 (longword), according
to the operand size. With a longword operand,
the lower 2 bits of PC are masked.
static voidchangePCrelativeAddress(int offset, uint16_t* instructionPtr, uint32_tnewAddress)
{
uint32_t address = (offset << 2) +((reinterpret_cast<uint32_t>(instructionPtr) + 4) &(~0x3));
*reinterpret_cast<uint32_t*>(address) =newAddress;
}
能被2 整除数据的二进制表示,其最低位一定是‘0’;能被4 整除数据的二进制表示, 其最低两位一定是‘00’。在SH4状态下,指令在存储器中存储必须2字节对齐。