arraysassemblyelementx86-16emu8086

Accessing an array in emu8086


Can someone please tell me the most effective way to access an array's element in emu8086?
As an example I got this array:

tab db 30h,35h,32h,37h,38h,39h,31h

Is it wrong to write mov si, offset tab and then access to the element using si? Like tab[si], tab[si+1], tab[si+n], etc.
Am I obliged to keep using lodsb/lodsw?


Solution

  • Is it wrong to write mov si, offset tab and then access to the element using si? like tab[si], tab[si+1], tab[si+n]... etcetera.

    That would be very wrong indeed! Assuming emu8086 can accept tab[si] where (part of) the displacement component lies outside of the square brackets, you would erroneously be adding the offset to the array twice. Once in the initialization of SI (mov si, offset tab), and once more in the load/store instruction that uses the addressing mode tab[si].

    Four ways to solve it:

    Am I obliged to keep always using lodsb/lodsw?

    Definitely no. But should you ever need to write the most compact solution, then often the use of these string primitives will do the job.