Currently, our website is under development. Sorry for the inconvenience.

8086 Microprocessor: Array Addressing Modes

 Array Addressing Modes


Array means collection data that can be stored under the same name. For example, an array named MYARRAY, address of the k-th element,
MYARRY+(K-1)*S ...........(Eqation 1)
Where S is the size of each element (1 for byte, 2 for word, 3 for .....). We can clear our understanding using the following problem.

Problem: Exchange the 10th and 25th elements in a word array W.

Solution:
Here the array name is W, and each element size is S=2 because for a word array, element size will be 2. Now compared to Equation 1, we can write for 10th elements k = 10 the following:
W+(10-1)*2
W+9*2
W+18

Same as for 25th elements: K=25, S=2
W+(25-1)*2
W+24*2
W+48

So, we can exchange as follows:
MOV    AX, W+18;
XCHG    W+48;
MOV   W+18, AX;

DUP

DUP refers to duplicate. For example
MYARRAY    DB    10DUP(0)
It means 0 will repeat or duplicate 10 times. So, the answer is 0, 0, 0, 0, 0, 0, 0, 0, 0. We can also clarify more about our topic using next example
MYARRAY    DB    1, 2, 3, 7 DUP(4)
It means 4 will repeat or duplicate 7 times. So, the answer is 1,2,3,4,4,4,4,4,4,4.  Another e.g
MYARRAY    DB    3,2,DUP(5,6, 2 DUP(4),5),8
We can simplify our problem like the following:
 3,2,DUP(5,6, 2 DUP(4), 5), 8
 =  3,2,DUP(5,6, 4,4,5),8
   = 3,5,6, 4,4,5,5,6, 4,4,5,8
Now we can back our main topics. Actually, addressing modes specified the way of an operand. It can operate in three modes, which are
  1. Resister Mode
  2. Immediate Mode
  3. Direct Mode
Register Mode: In this mode, both operands are register. For example, 
MOV    AX, BX;
Here, AX and BX both are registers, and we know that both register sizes are 16 bits or 2 bytes.

Immediate Mode: In this mode, one operand is register and another operand is constant. For example, 
MOV   AX, 12;
Here, AX is a register, but 12 is a constant. Another example
MOV AX,  0ABFCH
Here, AX is a register and 0ABFCH is a constant. So we can say that both are in immediate mode.

Direct Mode: In this mode, one operand is a register and another operand is a variable. For example, 
MOV   DATA1, AX;
Here, AX is a register, but DATA1 is a variable. Another example,
A    DB    1, 5, 9, 4
MOV AL, A+2
Here, we have an array named "A," and the array element size is 1 byte and the number of elements is 4, and AL is register and A+2=9. So both examples are for direct mode, as DATA1 depends on the AX register and AL register depends on the array A elements. 

Post a Comment

Previous Post Next Post