gpt4 book ai didi

assembly - MOS 6502 中的间接 Y 变址寻址模式

转载 作者:行者123 更新时间:2023-12-01 17:46:38 26 4
gpt4 key购买 nike

我正在查看 here 中 MOS 6502 指令集的寻址模式.

间接、Y 索引的描述与其他来源有点不一致。

上面写着

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 指向的 16 位字(在 little-endian 中)与 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 处的字为 0280Y0090,它们的相加为 0310 正如预期的那样。

长描述只是对这些事实进行编码:a) Indirect 指向的 16 位字存储在小端 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;
}

关于assembly - MOS 6502 中的间接 Y 变址寻址模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46262435/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com