如有疑问,最好查看官方文档.
有一个从MOS一个迷人的原始数据表这里
还[ 1 ],上面写着
间接索引寻址 - 在间接索引寻址(称为
( Indirect) , Y)中,指令的第二个字节指向第0页的内存位置.
该存储单元的内容被添加到Y索引寄存器的内容中,结果是有效地址的低8位.
来自此添加的进位被添加到下一页零存储器位置的内容中,结果是有效地址的高8位.
所以第二次添加是在携带时进行的.
你可以看到这是16位字Immediate(16位字)之间的16位加法(以little-endian表示)和Y寄存器0 的内容扩展到16位.
例如,如果存储器和Y是
All values in hex
Address 00 01 02 03 04 ...
Value 80 02 f3 00 03 ...
Y = 90
Run Code Online (Sandbox Code Playgroud)
然后(0), Y是
low 8 bits: 80 + 90 = 10 (with carry = 1)
high 8 bits: 02 + 00 + 1 = 03
Run Code Online (Sandbox Code Playgroud)
给出一个有效的地址0310.同样(3), Y是
low 8 bits: 00 + 90 = 90 (with carry = 0)
high 8 bits: 03 + 00 + 0 = 03
Run Code Online (Sandbox Code Playgroud)
这导致有效的价值地址0390.
你可以看到,当16位的量在考虑0字是0280和Y是0090,被他们除了0310预期.
长描述只是编码这些事实:a)通过指向的16位字Indirect存储在小端b)中Y是零扩展c)中另外是一个16位的一个.
在C中,它应该是这样的
uint16_t effective_addr(uint8_t indirect)
{
//Take the INDIRECT immediate and make a pointer to a 16-bit LE word out of it
//In C int-to-ptr is implementation define, we assume an identity map here
uint16_t* page_zero_ptr = (uint16_t*)indirect;
//The Y register is 8-bit, we consider it a 16-bit one instead
//Assume y is of unsigned type
uint16_t y_zero_ext = y;
//Do a 16-bit addition, this is equivalent to two 8-bit additions with carry
return *page_zero_ptr + y;
}
Run Code Online (Sandbox Code Playgroud)