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?
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 modetab[si].Four ways to solve it:
Setup SI with
mov si, offset taband access the first element with[si]and the second element with[si+1].Setup SI with
xor si, si(same asmov si, 0) and access the first element withtab[si]and the second element withtab[si+1].Setup SI with
mov si, offset taband access all of the elements with[si]because in between accesses you will have incremented the SI register as part of a loop's logic.Setup SI with
xor si, si(same asmov si, 0) and access all of the elements withtab[si]because in between accesses you will have incremented the SI register as part of a loop's logic.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.