How does the assembler reset array index when it reaches the last one

155 views Asked by At

edit: Sorry I meant 100 elements in the array.Edited with 4 .

I am having a difficulty understanding how does the assembler works when it comes to array indices. I have attached the code below. As you can see, I commented out the part that I find not clear. di is 64h which is 100 in decimal, after 1 shl it becomes c8h which is 200 in decimal, after substracting 2 it becomes c6h which is 198 in decimal.

Now,after line L1 I see: mov dx,xx[di]. it compiles just fine and it also shows the last element of the array (which is 19h, 25 in decimal because it is a dup. Forgive me for creating such a stupid complicated array). How does that work? isn't it out of scope?

I'd appreciate any help... Thanks! Code below:

.model small
.stack 100
.data

xx dw 4 dup (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
n1 db 100

.code
main:
mov ax,@data
mov ds, ax

mov cx,0
mov cl,n1
mov di, cx   ;di=64h=100d 
shl di,1 ;di=c8h = 200d
sub di, 2 ;di= c6h = 198d
mov si,0   ; si= 0


L1:
mov ax,xx[si]
mov dx,xx[di]
mov xx[si], dx
mov xx[di],ax
add si,2
sub di, 2
cmp si,cx
jl L1



mov ax,4c00h
int 21h
end main
0

There are 0 answers