我想知道如何处理数组的索引。我的目标是获取和更改特定索引的值。
我的数组看起来像这样:
Dots_pos dw firstLine, firstLine+ 8, firstLine+ 16, firstLine+ 24, firstLine+ 32
dw firstLine+ 40, firstLine+ 48, firstLine+ 56, firstLine+ 64, firstLine+ 72
dw firstLine+ 80, firstLine+ 88, firstLine+ 96, firstLine+ 104, firstLine+ 112
dw firstLine+ 120, firstLine+ 168, firstLine+ 176, firstLine+ 184, firstLine+ 192
dw firstLine+ 200, firstLine+ 208, firstLine+ 216, firstLine+ 224, firstLine+ 232
dw firstLine+ 240, firstLine+ 248, firstLine+ 256, firstLine+ 264, firstLine+ 272
dw firstLine+ 280, firstLine+ 288
; 2nd line
dw secondLine, secondLine+ 96, secondLine+ 120, secondLine+ 168, secondLine+ 192
dw secondLine+ 288
;...
我没有尝试很多东西,因为我找不到任何关于它的文档,特别是在 16 位中。
非常感谢您考虑我的请求。
您可能想要使用的是可用于寻址的寄存器之一(例如
BX
或SI
)。然后,您可以使用 mov ax, [line + BX]
获取特定索引处的值,其中 BX 是元素索引 * 2(因为每个元素有 2 个字节长)。
也可以将行的起始地址放入BX中,然后直接添加index * 2即可。 假设我们要获取的索引在 CX 中,那么代码将是
mov bx, line
shl cx ; CX *= 2
add bx, cx
mov ax, [bx]