MOS 6502 中的间接 Y 索引寻址模式
Indirect Y indexed addressing mode in MOS 6502
我正在查看来自 here 的 MOS 6502 指令集的寻址模式。
indirect, Y-indexed
的描述与其他来源有点不一致。
它说
OPC ($LL),Y operand is effective address incremented by Y with carry; effective address is word at zeropage address
但是其他来源没有提到带进位的加法。喜欢 here.
有效地址的正确计算方法是什么?
如有疑问,最好查看官方文档。
MOS here 有一份引人入胜的原始数据表
还有[1],即
INDIRECT INDEXED ADDRESSING - In indirect indexed addressing (referred to as ( Indirect) , Y
), the second byte of the instruction points to a memory location in page zero.
The contents of this memory location is added to the contents of the Y
index register, the result being the low order eight bits of the effective address.
The carry from this addition is added to the contents of the next page zero
memory location, the result being the high order eight bits of the effective address.
所以第二次加法是带进位的
您可以将此视为 Immediate
(在 little-endian 中)指向的 16 位字与 Y
寄存器的内容零扩展到 16 位之间的 16 位加法。
比如内存和Y
是
All values in hex
Address 00 01 02 03 04 ...
Value 80 02 f3 00 03 ...
Y = 90
那么 (0), Y
就是
low 8 bits: 80 + 90 = 10 (with carry = 1)
high 8 bits: 02 + 00 + 1 = 03
给出0310
的有效地址。同样 (3), Y
是
low 8 bits: 00 + 90 = 90 (with carry = 0)
high 8 bits: 03 + 00 + 0 = 03
这导致有效地址值为 0390
。
你可以看到当作为16位量时,0处的字是0280
,Y
是0090
,它们的加法是预期的0310
。
长描述只是对这些事实进行了编码:a) Indirect
指向的 16 位字存储在小端 b) Y
是零扩展的 c) 加法是 a 16位1.
在 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;
}
我正在查看来自 here 的 MOS 6502 指令集的寻址模式。
indirect, Y-indexed
的描述与其他来源有点不一致。
它说
OPC ($LL),Y operand is effective address incremented by Y with carry; effective address is word at zeropage address
但是其他来源没有提到带进位的加法。喜欢 here.
有效地址的正确计算方法是什么?
如有疑问,最好查看官方文档。
MOS here 有一份引人入胜的原始数据表
还有[1],即
INDIRECT INDEXED ADDRESSING - In indirect indexed addressing (referred to as
( Indirect) , Y
), the second byte of the instruction points to a memory location in page zero.
The contents of this memory location is added to the contents of theY
index register, the result being the low order eight bits of the effective address.
The carry from this addition is added to the contents of the next page zero memory location, the result being the high order eight bits of the effective address.
所以第二次加法是带进位的
您可以将此视为 Immediate
(在 little-endian 中)指向的 16 位字与 Y
寄存器的内容零扩展到 16 位之间的 16 位加法。
比如内存和Y
是
All values in hex
Address 00 01 02 03 04 ...
Value 80 02 f3 00 03 ...
Y = 90
那么 (0), Y
就是
low 8 bits: 80 + 90 = 10 (with carry = 1)
high 8 bits: 02 + 00 + 1 = 03
给出0310
的有效地址。同样 (3), Y
是
low 8 bits: 00 + 90 = 90 (with carry = 0)
high 8 bits: 03 + 00 + 0 = 03
这导致有效地址值为 0390
。
你可以看到当作为16位量时,0处的字是0280
,Y
是0090
,它们的加法是预期的0310
。
长描述只是对这些事实进行了编码:a) Indirect
指向的 16 位字存储在小端 b) Y
是零扩展的 c) 加法是 a 16位1.
在 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;
}