MPMC Course
MPMC Course
&
MICROCONTROLLERS
Presented by
Mrs. K.KrishnaKumari
Asst.Professor
What, Why & How?
Microcontroller
Microprocessor RAM ROM
TIMER I/O PORT SERIAL
INTERFACE
Microprocessor Microcontroller
Memory and I/O components have to be Memory, I/O components are inbuilt
connected externally along with processor
Cannot be used in compact systems and Can be used in compact systems and
hence inefficient hence it is an efficient technique
Cost of the entire system increases Cost of the entire system is low
Due to external components, the entire Since external components are low, total
power consumption is high. Hence it is power consumption is less and can be
not suitable to used with devices running used with devices running on stored
on stored power like batteries power like batteries
Since memory and I/O components are Since components are internal, most of
all external, each instruction will need the operations are internal instruction,
external operation, hence it is relatively hence speed is fast
slower
It has less number of registers, hence It has more number of registers, hence
more operations are memory based the programs are easier to write
Dedicated Adder to
generate 20 bit address
Instruction queue
A group of First-In-First-
Out (FIFO) in which up to 6
bytes of instruction code
are pre fetched from the
memory ahead of time.
A decoder in the EU
control system
translates instructions.
and
Some of the 16 bit registers can be
Index registers (Source used as two 8 bit registers as :
Index, Destination Index)
each of 16-bits AX can be used as AH and AL
BX can be used as BH and BL
CX 20
can be used as CH and CL
DX can be used as DH and DL
Execution Unit (EU)
Architecture
EU Accumulator Register (AX)
Registers
Consists of two 8-bit registers AL and AH, which can be
combined together and used as a 16-bit register AX.
Example:
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
Tarp Flag
Over flow Flag If this flag is set, the processor
This flag is set, if an overflow occurs, i.e, if the result of a signed enters the single step execution
operation is large enough to accommodate in a destination
mode by generating internal
register. The result is of more than 7-bits in size in case of 8-bit
signed operation and more than 15-bits in size in case of 16-bit interrupts after the execution of
sign operations, then the overflow will be set. each instruction
AD0-AD15 (Bidirectional)
Address/Data bus
MN/ MX
MINIMUM / MAXIMUM
TEST
READY
This is the acknowledgement from the
slow device or memory that they have
completed the data transfer.
RESET (Input)
CLK
The clock input provides the basic timing
for processor operation and bus control
activity. Its an asymmetric square wave
with 33% duty cycle.
Pins 24 -31
Pins 24 -31
2. Arithmetic Instructions
3. Logical Instructions
A 8-bit data can only be moved to 8-bit register/ memory and a 16-
bit data can be moved to 16-bit register/ memory.
1. Data Transfer Instructions
PUSH mem
(SP) (SP) – 2
MA S = (SS) x 1610 + SP
(MA S ; MA S + 1) (mem)
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADDC A, data
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
8086 instruction set includes instruction for string movement, comparison, scan,
load and store.
Offset or effective address of the source operand is stored in SI register and that of
the destination operand is stored in DI register.
REP
MOVS
(MAE) (MA)
MOVSW
MA = (DS) x 1610 + (SI)
MAE = (ES) x 1610 + (DI)
CMPS
SCASW
MAE = (ES) x 1610 + (DI)
Modify flags (AL) - (MAE)
LODS
STOS
STOSW
MAE = (ES) x 1610 + (DI)
(MAE ; MAE + 1 ) (AX)
Mnemonics Explanation
STC Set CF 1
CLC Clear CF 0
NOP No operation
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
1. Register Addressing
Group I : Addressing modes for
2. Immediate Addressing register and immediate data
3. Direct Addressing
5. Based Addressing
Group II : Addressing modes for
6. Indexed Addressing memory data
7. Based Index Addressing
8. String Addressing
8. String Addressing
1. Register Addressing
In immediate addressing mode, an 8-bit or 16-bit
2. Immediate Addressing data is specified as part of the instruction
3. Direct Addressing
Example:
4. Register Indirect Addressing
MOV DL, 08H
5. Based Addressing
The 8-bit data (08H) given in the instruction is
6. Indexed Addressing moved to DL
8. String Addressing
10. Indirect I/O port Addressing The 16-bit data (0A9FH) given in the instruction is
moved to AX register
11. Relative Addressing
(AX) 0A9FH
12. Implied Addressing
Addressing Modes : Memory Access
20 Address lines 8086 can address up to 220
= 1M bytes of memory
1. Register Addressing
Addressing Modes
2. Immediate Addressing
Here, the effective address of the memory
3. Direct Addressing
location at which the data operand is stored is
4. Register Indirect Addressing given in the instruction.
12. Implied Addressing This addressing mode is called direct because the
displacement of the operand from the segment
base is specified directly in the instruction.
Group II : Addressing modes for
memory data
(CL) (MA)
(CH) (MA +1)
Group II : Addressing modes for
memory data
(AL) (MA)
(AH) (MA + 1)
Group II : Addressing modes for
memory data
1. Register Addressing
2. Immediate Addressing
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
5. Based Addressing
6. Indexed Addressing
Instructions using this mode have no operands.
The instruction itself will specify the data to be
7. Based Index Addressing
operated by the instruction.
8. String Addressing
Example: CLC
9. Direct I/O port Addressing
This clears the carry flag to zero.
10. Indirect I/O port Addressing
Used to :
› specify the start and end of a program
› attach value to variables
› allocate storage locations to input/ output data
› define start and end of segments, procedures, macros etc..
Assemble Directives
DB
Define Byte
DW
Define a byte type (8-bit) variable
SEGMENT
ENDS
Reserves specific amount of memory locations to
each variable
ASSUME
Range : 00H – FFH for unsigned value;
ORG
END 00H – 7FH for positive value and 80H – FFH
EVEN for negative value
EQU
General form : variable DB value/ values
PROC
FAR Example:
NEAR
LIST DB 7FH, 42H, 35H
ENDP
Three consecutive memory locations are reserved for the
SHORT variable LIST and each data specified in the instruction
are stored as initial value in the reserved memory location
MACRO
ENDM
Assemble Directives
DB
DW Define Word
SHORT
ORG
User defined name of the
END Segment Register
segment
EVEN
EQU
PROC Example:
FAR
NEAR ASSUME CS: ACODE, DS:ADATA Tells the compiler that the
ENDP instructions of the program are stored
in the segment ACODE and data are
stored in the segment ADATA
SHORT
MACRO
ENDM
Assemble Directives
DB
ORG (Origin) is used to assign the starting address
DW (Effective address) for a program/ data segment
PROC
FAR
LOOP EQU 10FEH Value of variable LOOP is 10FEH
NEAR
ENDP
_SDATA SEGMENT In this data segment, effective address of
SHORT ORG 1200H memory location assigned to A will be 1200 H and
A DB 4CH that of B will be 1202H and 1203H.
EVEN
MACRO B DW 1052H
ENDM _SDATA ENDS
Assemble Directives
DB
PROC Indicates the beginning of a procedure
DW
ENDP End of procedure
SEGMENT
ENDS FAR Intersegment call
RET
ORG ADD64 ENDP
END
EVEN
EQU CONVERT PROC FAR The subroutine/ procedure named CONVERT is
declared as FAR and so the assembler will code
… the CALL and RET instructions involved in this
PROC … procedure as far call and return
ENDP …
FAR RET
NEAR CONVERT ENDP
SHORT
MACRO
ENDM
Assemble Directives
DB
Reserves one memory location for 8-bit signed
DW displacement in jump instructions
Example:
SEGMENT
ENDS
PROC
ENDP
FAR
NEAR
SHORT
MACRO
ENDM
Assemble Directives
DB
MACRO Indicate the beginning of a macro
DW
ENDM End of a macro
SEGMENT
ENDS
General form:
ASSUME macroname MACRO[Arg1, Arg2 ...]
Program
… statements in the
ORG … macro
END …
EVEN
EQU macroname ENDM
PROC
ENDP
FAR User defined name of the
NEAR macro
SHORT
MACRO
ENDM
Example: ARITHMATIC OPERATIONS
Objective:
Learn to write a program for performing arithmetic operations on two 8-bit
operands and get a clear view on each single step execution
Software Required:
i. Personal Computer with Windows OS
ii. MASM Software
PROGRAM FOR 8 BIT
ARITHMATIC OPERATION
dosseg \\ Segmenting the memory in small model i.e, entire code, data and stack
.model small \\ segments within 64KB size
.stack 100h \\ Initializing stack memory at 100h address location in memory
.data \\ Defining data segment
n1 db 82h \\ Starting of the data segment
n2 db 62h Input Data: 82 h =130 d,62h=98 d
sum db ?
carry db ?
diff db ? \\ Assigning variables in specific length
brw db ?
prod dw ?
quot db ?
rem db ? \\ Ending of the data segment
.code \\ Defining code segment
start: \\ Starting of the code segment, here ‘start’ is a label name
mov ax, @data \\ Initializing data segment
mov ds, ax
mov cl,00h \\ Writing the program for doing 8-bit arithmetic operation
mov al,n1
add al,n2
adc cl,00h
movsum,al\\ addition operation
movcarry,cl
mov cl,00h
mov al,n1
sub al,n2 \\ subtraction operation
sbb cl,00h
movdiff,al
movbrw,cl
mov al,n1
mul n2 \\ multiplication operation
movprod,ax
mov al,n1
mov ah,00h
div n2 \\ Division operation
movquot, al
mov rem, ah
mov ah, 4ch
int 21h \\ Interrupt for going back to dos command prompt
end start \\ End of the code segment
end \\ End of the program
RESULTS