Lec 2
Lec 2
Assembly Language
CSC 325
Microprocessor/
Microcontroller Architecture
Outline
Introduction to MPU System
Microprocessors and Microcontrollers
Microprocessor Architecture
Addressing Mode
Address calculation
Assembly Language Programming
Introduction
I/O Device 0 Data
Data
Code
Memory
Address
CPU
I/O Device 1 Data
Address
Data
I/O Device N Data
Memory
Data
Microprocessor Architecture
Addressing Mode
Addressing Mode
The term addressing modes refers to the way in which
the operand of an instruction is specified.
Addressing modes of 8086
Register
Immediate
Direct
Register indirect
Based relative
Indexed relative
Based indexed relative
Addressing Mode
Register
Involves the use of registers
Memory is not accessed, so faster
Source and destination registers must match in size.
MOV BX,DX
MOV ES,AX
ADD AL,BH
MOV AL,CX ;not possible
Addressing Mode
Immediate
Source operand is a constant
Possible in all registers except segment and flag
registers.
MOV BX,1234H ; move 1234H into BX
MOV CX,223 ; load the hexadecimal value into CX
ADD AL,40H ;
MOV DS,1234H ;illegal
Addressing Mode
Direct
Address of the data in memory comes immediately
after the instruction operand is a constant
The address is the offset address. The offset address
is put in a rectangular bracket
MOV DL,[2400] ; move contents of DS:2400H into DL
Addressing Mode
Find the physical address of the memory location and
its content after the execution of the following
operation. Assume DS=1512H
MOV AL,99H
MOV [3518],AL
Physical address of DS:3518 => 15120+3518=18638H
The memory location 18638H will contain the value 99H
Addressing Mode
Register indirect
The address of the memory location where the
operand resides is held by a register.
SI, DI and BX registers are used as the pointers to
hold the offset addresses.
They must be combined with DS to generate the 20-bit
physical address
MOV AL,[BX] ; moves into AL the contents of the memory
location pointed to by DS:BX
MOV CL,[SI] ; move contents of DS:SI into CL
MOV [DI],AH ; move the contents of AH into DS:DI
Addressing Mode
Based relative
BX and BP are known as the base registers. In this
mode base registers as well as a displacement value
are used to calculate the effective address.
The default segments used for the calculation of
Physical address (PA) are DS for BX, and SS for BP.
MOV CX,[BX]+10 ; move DS:BX+10 and DS:BX+11 into CX ;
PA = DS (shifted left) +BX+10
Note that, the content of the low address will go into CL and
the high address contents will go into CH.
There are alternative coding:
MOV CX,[BX+10], MOV CX,10[BX]
BX+10 is effective address
Addressing Mode
Indexed relative
Indexed relative addressing mode works the same as
the based relative addressing mode.
Except the registers DI and SI holds the offset
address.
MOV DX,[SI]+5 ;PA=DS(shifted left)+SI+5
MOV CL,[DI]+20 ;PA=DS(shifted left)+DI+20
Addressing Mode
Based indexed relative
The combination of the based and indexed addressing
modes.
One base register and one index register are used.
MOV CL,[BX][DI]+8 ;PA=DS(shifted left)+BX+DI+8
MOV CH,[BX][SI]+20 ;PA=DS(shifted left)+BX+SI+20
MOV AH,[BP][DI]+12 ;PA=SS(shifted left)+BP+DI+12
MOV AL,[BP][SI]+29 ;PA=SS(shifted left)+BP+SI+29
Alternative coding
MOV CL,[BX+DI+8]
MOV CL,[DI+BX+8]
Address calculation
Physical Address
The 20 bit address which we needs to be stored.
It ranges from 00000H to FFFFFH (Hexadecimal
notation) .
Base Address
The address at which a given memory segment starts
and we use it for de-markation.
Offset address
(Distance from the base address) is a location with 64
kb segment range. It ranges from 0000H to FFFFH
Address calculation
Logical address
Something we denote on paper as a short hand
representation of the above addresses. It consists of a
segment value and offset address.
Logical address is specified as Segment base : Offset
value.
Address calculation
Physical address is obtained by shifting the
segment address 4 bits to left adding the offset
address.
Physical address = ( Segment base*10H ) + Offset
Value.
Logical address:A4FBH:4872H
Segment's base address:A4FBH
Offset value:4872H
Shifting the segment address 4 bits to left A4FBH<<4 gives
A4FB0H
Now adding offset address to A4FB0H
A4FB0H+4872H=A9822H
Assembly Language
Programming
Data Movement Instructions
Arithmetic and Logic Instructions
Program Control Instructions
Special Instructions
Assembly Language Version
operation destination, source
operation destination
operation source
operation
Assembly Language
Programming
Data Movement Instructions
Destination Operand
MOV
Source General Segment Memory
Constant
Operand Register Register Location
General
Yes yes yes no
Register
Segment
Yes no yes no
Register
Memory
Yes yes no no
Location
Constant Yes no yes no
Instruction Set
1. Data Transfer Instructions
ADD A, data
Instruction Set
Microprocessor
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADC reg2/ mem, reg1/mem
ADDC A, data
SUB A, data
SBB A, data