You are on page 1of 170

MICROPROCESSORS

AND
MICROCONTROLLERS
By
P.A.Sravanthi
Asst.Prof.,
ECE Dept.,
GMRIT
Evolution of
Microprocessors
Bus structure of 8086 based computer system:
• - A set of conductors, used for communicating
information between the components in a
computer system is called System-Bus.
• - Internal Bus: connects two minor components
within a major component (or IC), such the
connection between the control unit and internal
registers of the MPU)
• - External Bus: connects two major components,
such as MPU and an interface (Memory or
input/output).
• Although some systems include more than one
external bus, 8086 and 8088 processors contain
one bus called system-bus.
• Typical system-bus includes; Address-bus
(carries physical address of memory storages
or input/output locations), Data-bus (carries
data to be read or written into MPU registers)
and Control-bus(carries information to control
the read or write operation).
Flag register (8-bit)
Instruction set of 8086
1. Data copy/Transfer instructions
2. Arithmetic and Logical instructions
3. Branch instructions
4. Loop instructions
5. Machine control instructions
6. Flag Manipulation instructions
7. Shift and Rotate instructions
8. String instructions
Procedures and Macros
Writing and using Procedures
• To avoid writing the sequence of instructions
in the program each time, we can write the
sequence as a separate subprogram called a
procedure

• Use the CALL instruction to send the 8086 to


the starting address of the procedure in
memory

47
Contd..
• A RET instruction at the end of the procedure
returns execution to the next instruction in
the main line

• Procedures can even be nested

48
MAINLINE OR CALLING
PROGRAM
PROCEDURE
INSTRUCTIONS

CALL

NEXT MAINLINE
INSTRUCTIONS

RET

Fig. Single Procedure Call

49
Main Line Instructions

Lower level
Procedure Procedure

CALL CALL
Next Main Line
Instructions
RET
RET

Fig. Nested Procedures Call

50
8086 CALL and RET Instructions
• A CALL instruction in the mainline program
loads the Instruction Pointer and in some
cases also the code segment register with the
starting address of the procedure

• At the end of the procedure, a RET instruction


sends execution back to the next instruction
after the CALL in the mainline program

51
The CALL Instruction Overview
• The 8086 CALL instruction performs 2 operations
when it executes

• First, it stores the address of the instruction after the


CALL instruction on the stack

• This address is called the return address because it is


the address that execution will return to after the
procedure executes

52
Contd..
• If the CALL is to a procedure in the same code
segment, then the call is near, and only the
instruction pointer contents will be saved on
the stack

• If the CALL is to a procedure in another code


segment, the call is far ; In this case both the
instruction pointer and the code segment
register contents will be saved on the stack
53
Contd..

• Second operation of the CALL instruction is to


change the contents of the instruction pointer
and, in some cases, the contents of the code
segment register to contain the starting
address of the procedure.

54
The CALL and RET instructions
The 8086 RET instruction:
• When 8086 does near call it saves the instruction
pointer value after the CALL instruction on to the
stack.

• RET at the end of the procedure copies this value


from stack back to the instruction pointer (IP).
ASSUME CS:CODE1,DS:DATA
DATA SEGMENT
NUM DB 23H

DATA ENDS
CODE1 SEGMENT
START: MOV AX,DATA
MOV DS,AX
NEAR PROCEDURE …

CALL PROCEDURE1


PROCEDURE1 PROC NEAR
MOV CX,23F2H


RET
PROCEDURE1 ENDP


CODE1 ENDS
END START
ASSUME CS:CODE1,DS:DATA
DATA SEGMENT

DATA ENDS
CODE1 SEGMENT


CALL MULTIPLY_32

FAR PROCEDURE CODE1 ENDS
ASSUME CS:CODE2
CODE2 SEGMENT


MULTIPLY_32 PROC FAR
MOV CX,23F2H


RET
MULTIPLY_32 ENDP

CODE ENDS
END START
Passing parameters to & from
procedures
• Using GLOBAL declared variable
• Using registers
• Using stack
• Using PUBLIC & EXTRN
Using GLOBAL declared variable
ASSUME CS:CODE1,DS:DATA
DATA SEGMENT
NUM EQU 23H GLOBAL
DATA ENDS
CODE1 SEGMENT
START: MOV AX,DATA

CALL ROUTINE

ROUTINE PROC NEAR


MOV AL,NUM

RET
ROUTINE ENDP
CODE ENDS
END START
Using registers
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,5655H
MOV BX,7272H


CALL PROCEDURE1


PROCEDURE1 PROC NEAR


ADD AX,BX


RET
PROCEDURE1 ENDP
CODE ENDS
END START
Using stack

ASSUME CS:CODE, SS:STACK

STACK SEGMENT
ROUTINE PROC NEAR
S_DATA DB 200H DUP(0)
..
STACK ENDS
MOV DX,SP
CODE SEGMENT
ADD SP,02
START: MOV AX,STACK
POP BX
MOV SS,AX
POPAX
MOV AX,5555H
MOV SP,DX
MOV BX,7777H

PUSH AX

PUSH BX
RET
CALL ROUTINE
ROUTINE ENDP

CODE ENDS

END START
Using PUBLIC & EXTRN
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
PUBLIC NUMBER EQU 200H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX

CALL ROUTINE

ROUTINE PROC NEAR
EXTRN NUMBER
MOV AX,NUMBER

ROUTINE ENDP

CODE ENDS
END START
Procedures
• A big advantage of using procedures is that the machine
codes for the group of instruction in the procedures needs
to be loaded in to main memory only once.

• Disadvantage using the procedures is the need for the


stack.
Macros
• The macro is also a similar concept
• Suppose, a number of instructions are repeating through in
the main program, the listing becomes lengthy.
• So, a macro definition, i.e. a label is assigned with the
repeatedly appearing string of instructions.
• The process of assigning a label or macroname to the string
is called defining a macro.
• The macroname is then used throughout the main program
to refer to that string of instructions.
Passing parameters to a Macro
• Using parameters in a definition, the programmer specifies
the parameters of the macro those are likely to be changed
each time the macro is called.
DISPLAY MACRO MSG
MOV AX,SEG MSG
MOV DS,AX
MOV DX,OFFSET MSG
MOV AH,09H
INT 21H
DISPLAY ENDM
• The parameter MSG can be replaced by MSG1 or
MSG2 while calling the macro.



DISPLAY MSG1

DISPLAY MSG2


Macros vs Procedures

• Advantage of using macros


– execution of MACRO expansion is usually faster (no call
and ret) than the execution of the same code implemented
with procedures

• Disadvantage
– assembler copies the macro code into the program at each
macro invocation
– if the number of macro invocations within the program is
large then the program will be much larger than when
using procedures

EENG4005
Procedure
ASSUME CS:CODE, DS:DATA PROCEDURE PROC NEAR
DATA SEGMENT
XOR CL,CL
N1 DW 2458H
N2 DW 8956H ADD AL,BL
OUTPUT DW 02H DUP(0) ADC AH,BH
DATA ENDS JNC XYZ
CODE SEGMENT INC CL
START: MOV AX,DATA
XYZ: RET
MOV DS,AX
MOV AX,N1 PROCEDURE ENDP
MOV BX,N2 CODE ENDS
CALL PROCEDURE END START
MOV [OUTPUT],AX
MOV [OUTPUT+2],CL
HLT
MACROS
ASSUME CS:CODE, DS:DATA CODE SEGMENT
DATA SEGMENT START: MOV AX,DATA
MSG1 DB 10,13,”GMRIT” MOV DS,AX
MSG2 DB 10,13,”RAJAM” XYZ MSG1
DATA ENDS XYZ MSG2
XYZ MACRO MSG HLT
MOV AH,09H CODE ENDS
LEA MSG END START
INT 21H
ENDM
PROGRAMMABLE PERIPHERAL
INTERFACE -8255

Features:
• It is a programmable device.

• It has 24 I/O programmable pins like PA,PB,PC (three


8 pins).
Pin Diagram
Function of pins:
• Data bus(D0-D7):These are 8-bit bi-directional buses,
connected to 8085 data bus for transferring data.

• CS: This is Active Low signal. When it is low, then


data is transfer from 8085.

• RD: This is Active Low signal, when it is Low read


operation will be start.

• WR: This is Active Low signal, when it is Low Write


operation will be start.
• Address (A0-A1):This is used to select the
ports.

A1 A0 Select

0 0 PA

0 1 PB

1 0 PC

Control
1 1
reg.
Block Diagram
Data Bus buffer:
• It is a 8-bit bidirectional Data bus.

• Used to interface between 8255 data bus with


system bus.

• The internal data bus and Outer pins D0-D7


pins are connected in internally.

• The direction of data buffer is decided by


Read/Control Logic.
Read/Write Control Logic:
• This is getting the input signals from control
bus and Address bus

• Control signal are RD and WR.

• Address signals are A0,A1,and CS.

• 8255 operation is enabled or disabled by CS.


Group A and Group B control:
• Group A and B get the Control signal from CPU and
send the command to the individual control blocks.
• Group A send the control signal to port A and Port C
(Upper) PC7-PC4.
• Group B send the control signal to port B and Port C
(Lower) PC3-PC0.

PORT A:
• This is a 8-bit buffered I/O latch.
• It can be programmed by mode 0 , mode 1, mode 2 .
PORT B:
• This is a 8-bit buffer I/O latch.
• It can be programmed by mode 0 and mode 1.

PORT C:
• This is a 8-bit Unlatched buffer Input and an Output latch.
• It is splitted into two parts.
• It can be programmed by bit set/reset operation.
Operation modes:
Bit Set/Reset Mode(BSR):
• The PORT C can be Set or Reset by sending OUT instruction to the
CONTROL registers.

I/O Modes:
MODE 0 (Simple input / Output):
• In this mode , port A, port B and port C is used as individually
(Simply).
• Features:
• Outputs are latched , Inputs are buffered not latched.
• Ports do not have Handshake or interrupt capability.
ROL ; reading port C upper and
JNC WAIT ; rotating through carry.
IN AL,Port A ; If EOC, read digital equivalent in AL
HLT ; Stop
8257 DMA Controller
Pin Diagram of 8257
Interfacing a DMA controller with a system
Mode Set Register
Status Register
8257 Register Selection
Type 0 interrupts: This interrupt is also known as the divide by zero
interrupt. For cases where the quotient becomes particularly large to be
placed / adjusted an error might occur.

Type 1 interrupts: This is also known as the single step interrupt. This type
of interrupt is primarily used for debugging purposes in assembly language.

Type 2 interrupts: also known as the non-maskable NMI interrupts. These


type of interrupts are used for emergency scenarios such as power failure.

Type 3 interrupts: These type of interrupts are also known as breakpoint


interrupts. When this interrupt occurs a program would execute up to its
break point.

Type 4 interrupts: Also known as overflow interrupts is generally existent


after an arithmetic operation was performed.
LONG DISTANCE SERIAL COMMUNICATION
8251 USART
TABLE 1 OPERATION BETWEEN A CPU AND 8251
Control words
There are two types of control word.

1. Mode instruction (setting of function)


2. Command (setting of operation)
Problem:
Design the hardware interface circuit for interfacing
8251 with 8086. Set the 8251A in asynchronous mode
as a transmitter and receiver with even parity
enabled, 2 stop bits, 8-bit character length, frequency
160kHz and baud rate 10K.

a) Write an ALP to transmit 100 bytes of data string


starting at location 2000H:5000H.
b) Write an ALP receive 100 bytes of data string and
store it at 3000H:4000H.
A) ALP to initialize 8251 and transmit 100 bytes of data
ASSUME CS:CODE
C ODE SEGMENT
START: MOV AX,2000H
MOV DS,AX;DS ; points to byte string segment
MOV SI,5000H ; SI points to byte string
MOV CL,64H ; length of the string in CL (hex)
MOV AL,0FEH ; Mode control word out to
OUT 0FEH,AL ; D0-D7
MOV AX,11H ; Load command word
OUT OFEH,AL ; to transmit enable and error reset
WAIT: IN AL,0FEH ; Read status
AND AL,01H ; check transmitter enable
JZ WAIT ; bit, if zero wait for the transmitter to be ready
MOV AL,[SI] ; If ready, first byte of string data
OUT 0FCH,AL ; is transmitted
INC SI ; Point to next byte
DEC CL ; Decrement counter
JNZ WAIT ; If CL is not zero, go for next byte
MOV AH,4CH
INT 21H
CODE ENDS
END START
• An ALP to initialize 8251 and receive 100 bytes of data
ASSUME CS:CODE
CODE SEGMENT
START: MOV AX,3000H
MOV DS,AX ; Data segment set to 3000h
MOV SI,4000H ; Pointer to destination offset
MOV CL,64H ; Byte count in CL
MOV AL,0FEH ; Only one stop bit for
OUT 0FEH,AL ; receiver is set
MOV AL,14H ; Load command word to enable
OUT 0FEH,AL ; the receiver and disable transmitter
NXTBT: IN AL,0FEH ; Read status
AND AL,38H ; check FE, OE and PE
JZ READY ; If zero, jump to READY
MOV AL,14H ; If not zero, clear them
OUT 0FEH,AL ;
READY: IN AL,0FEH ; Check RXRDY, if the
AND AL,02H ; receiver is not ready
JZ READY ; wait
IN AL,0FCH ; If it is ready,
MOV [SI],AL ; receive the character
INC SI ; Increment pointer to next byte
DEC CL ; Decrement counter
JNZ NXTBT ; Repeat, if CL is not zero
HLT
CODE ENDS
END START

You might also like