Use Debug To See How It Is Working!!!
Use Debug To See How It Is Working!!!
Introduction:
Addressing modes are an aspect of the instruction set architecture in most CPU designs. The
various addressing modes that are defined in a given instruction set architecture define how
machine language instructions in that architecture identify the operand (or operands) of
each instruction. An addressing mode specifies how to calculate the effective memory
address of an operand by using information held in registers and/or constants contained
within a machine instruction.
Various addressing modes supported by Intel 8086 processor are
1. Register addressing mode
2. Immediate addressing mode
3. Direct addressing mode
4. Register indirect addressing mode
5. Base relative addressing mode
6. Indexed relative addressing mode
7. Base indexed relative addressing mode
Segment Override
A segment override prefix allows any segment register (DS, ES, SS, or CS) to be used as
the segment when evaluating addresses in an instruction. Segment override prefix can only
be used for data access. An override is made by appending the register plus a colon to the
beginning of the memory reference of the instruction as in the following examples:
MOV AX, [ES:60000] ; USE ES AS THE SEGMENT
MOV AX, [CS:BX] ; USE CS AS THE SEGMENT
MOV AX, [DS:BP+DI+6] ; USE SS AS THE SEGMENT
1
2. Immediate addressing mode
In this mode an 8 or 16 bit data can be specified as part of the instruction.
eg:- MOV CL,05H
MOV DX,083AH
Note: Use Debug to verify the above result!!!
The instruction moves the 16 bit content of BX into a memory location offset by the value of
EA (EA is specified in DI) from the current contents in DS.
If [DS] = 3040H [DI] = 0030H [BX] = 2346H
The 20 bit physical address will be 3040H X 10H + 0030H = 30430H contents of BX (2346)
is moved into memory locations 30430H & 30431H
Note: Using Debug verify the above result!!!
Here the source operand is in Base Relative Addressing mode. EA is obtained by adding the
value of START and [BX]. The 20 bit physical address is produced from DS and EA. The 8 bit
content of the memory location 12044H is moved to AL register.
2
EA. On the other hand, for 8 bit displacement the execution unit sign extends it to 16 bits
and then adds to SI for determining EA.
DISP BP or BX SI or DI
We can choose either one column or two columns or three columns to land into the
addressing modes and combination we desire.
Task #1:
Write an ALP for the following expressions:
(i) X = 4*Z-15*Y [Assume Z=9 and Y=7]
(ii) X = (Y/Z)*(W+1) (Try your self!!!)
Sol: (i)
.model small
.data
X dw ? ; allocate 2 byte memory to X
Z db 09
Y db 07
.code
.startup
mov ax,4
imul Z ; Integer(signed) multiplication
mov bx,ax
mov ax,-15
imul Y
add ax,bx
mov X,ax
.exit
end
Note: Signed multiplication (imul) of accumulator by "src" with result placed in the
accumulator. If the source operand is a byte value, it is multiplied by AL and the result is
stored in AX. If the source operand is a word value it is multiplied by AX and the result is
stored in DX:AX.
Task #2:
The following ALP is adding the elements of two vectors and storing in a third and displays
the result on monitor.
.model small
.data
vec1 db 12,3,15,9 ; initialize vec1
vec2 db 3,5,4,1
3
vec3 db ?,?,?,?
vec4 db 19 dup('$')
.code
.startup
lea si, vec1 ; si contains starting address of vec1
lea bx, vec2
lea di, vec3
mov cx, 4
sum: ;adding the elements of vec1 and vec2
mov al, [si]
add al, [bx]
mov [di], al
inc si
inc bx
inc di
loop sum
mov cx,4
lea di,vec3
mov bx,0
lea si,vec4
result: ;storing the ASCII converted result in vec4
mov al,[bx][di]
mov ah,0
aam ; Converts two digit number in corresponding BCD number
; (e.g. MOV AL, 15 ; AL = 0Fh
AAM ; AH = 01, AL = 05 )
Try These:
1. Identify all kinds of data addressing modes used in the Task #2
2. Rewrite the above program without using lea instruction.
3. Write an ALP to copy the elements of vec1 and vec2 into vec3.
4. Write an ALP that copies four word sized contents of the memory locations
starting from CS:DATA1 into AX, BX, CX and DX respectively.
5. Write an ALP to find whether a number is prime (A prime number is evenly
divisible by only itself and 1) or not. Your program should read number as an
input and display the appropriate message as an output. Further extend the
program such that program should continuously ask input number until user
input is not -1. [Do in the lab duration and show to the instructor!!!]
---------------------------------------------------------------------------------------------------