I would like to know how to deal with the index of an array. My objective is to get and change the value at a specific index.
My array looks like this:
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
;...
I didn't try a lot of things because I can't find any doc about it, especially in 16-bit.
Many thanks for considering my request.
What you probably want to use is one of the registers that can be used for addressing (for example
BX
orSI
). Then you can get value at a specific index withmov ax, [line + BX]
where BX is element index * 2 (since each element is 2 bytes long).Alternatively you can put the starting address of line into BX, and then just add index * 2 directly to it. Let's say index we want to get is in CX, then the code would be