How can I get the index of an array in DOS Assembly x86 (16-bit)?

48 views Asked by At

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.

1

There are 1 answers

1
enp On

What you probably want to use is one of the registers that can be used for addressing (for example BX or SI). Then you can get value at a specific index with mov 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

mov bx, line
shl cx       ; CX *= 2
add bx, cx
mov ax, [bx]