Microprocessor Notes 2
Microprocessor Notes 2
MICROPROCESSORS
• A Microprocessor is a multipurpose, Programmable clock-driven, register based
electronic device that read binary instruction from a storage device called memory,
accepts binary data as input and processes data according to those instructions and
provides results as outputs.
• A Microprocessor is a clock driven semiconductor device consisting of electronic
circuits manufactured by using either a LSI or VLSI technique.
• A typical programmable machine can be represented with three components : MPU,
Memory and I/O as shown in Figure
Memory
Microprocessor
I/O
Figure: A Programmable Machine
• These three components work together or interact with each other to perform a given
task; thus they comprise a system
• The machine (system) represented in above figure can be programmed to turn traffic
lights on and off, compute mathematical functions, or keep trace of guidance system.
• This system may be simple or sophisticated, depending on its applications.
• The MPU applications are classified primarily in two categories : reprogrammable
systems and embedded systems
• In reprogrammable systems, such as Microcomputers, the MPU is used for computing
and data processing.
• In embedded systems, the microprocessor is a part of a final product and is not
available for reprogramming to end user.
MICROCOMPUTER
MICRO CONTROLLER
APPLICATIONS OF MICROPROCESSOR
• Microcomputers
• Industrial Control
• Robotics
• Traffic Lights
• Washing Machines
• Microwave Oven
• Security Systems
• On Board Systems
MPU
MPU
ALU CU
Input Output Memory I/O
Register
Peripheral Devices
Array • A/D Converter
• Timer
• Serial I/O
Memory
3. Normally microcontrollers are used
for specific purposes (embedded
system) e.g. traffic light controller,
3. Normally used for general purpose printer, etc.
computers as CPU. 4. The performance speed of
microcontroller is relatively slower
4. The performance speed, i.e. clock than that of microprocessors, with
speed of microprocessor is higher clock speed from 3-33 MHz.
ranging frequency from MHz to GHz. 5. Has fixed memory and all
peripherals are embedded together
5. Addition of external RAM, ROM and on a single chip, so are not bulkier
I/O ports makes these systems bulkier and are cheaper than
and much more expensive. microprocessors.
6. As microcontrollers have already
6. Microprocessors are more versatile fixed amount of RAM, ROM and I/O
than microcontrollers as the designers ports, so are not versatile as the user
can decide on the amount of RAM, cannot change the amount of
ROM and I/O ports needed to fit the memory and I/O ports. [Link].
task at hand. [Link]. Intel 8085, 8086, AT89C51, ATmega32, AT89S52, etc.
Motorola 68000, Intel Core i7, etc.
Stored Program Concept and Von-Neumann Machine:
The simplest way to organize a computer is to have one processor, register and instruction
code format with two parts op-code and address/operand. The memory address tells the
control where to find an operand in memory. This operand is read from memory and used as
data to be operated on together with the data stored in the processor register. Instructions are
stored in one section of same memory. It is called stored program concept.
The task of entering and altering the programs for ENIAC was tedious. It could be facilitated
if the program could be represented in a form suitable for storing in memory alongside the
data. So the computer could get its instructions by reading from the memory and program
could be set or altered by setting the values of a portion of memory. This approach is known
as 'stored-program concept' was first adopted by John Von Neumann and such architecture is
named as von-Neumann architecture and shown in figure below.
The main memory is used to stare both data and instructions. The arithmetic and logic unit is
capable of performing arithmetic and logical operation on binary data. The program control
unit interprets the instruction in memory and causes them to be executed. The I/O unit gets
operated from the control unit.
The Von-Neumann architecture is the fundamental basis for the architecture of modern
digital computers. It consisted of 1000 storage locations which can hold words of 40 binary
digits and both instructions as well as data are stored in it. The storage location of control
unit and ALU are called registers and the various models of registers are:
MAR - memory address register - contains the address in memory of the word to be written
into or read from MBR.
MBR - memory buffer register - consists of a word to be stored in or received from memory.
IR-instruction register - contains the 8-bit op-code instruction to be executed.
IBR - instruction buffer register used to temporarily hold the instruction from a word in
memory.
PC - program counter - contains the address of the next instruction to be fetched from
memory.
AC & MQ (Accumulator and Multiplier Quotient) - holds the operands and results of ALU
after processing.
Harvard Architecture
In von-Neumann architecture, the same memory is used for storing instructions and data.
Similarly, a single bus called data bus or address bus is used for reading data and instructions
from or writing to memory. It also had limited the processing speed for computers.
The Harvard architecture based computer consists of separate memory spaces for the
programs (instructions) and data. Each space has its own address and data buses. So
instructions and data can be fetched from memory concurrently and provides significance
processing speed improvement.
In figure below, there are two data and two address buses multiplexed for data bus and address
bus. Hence, there are two blocks of RAM chips one for program memory and another for data
memory addresses.
The control unit controls the sequence of operations. Central ALU consists of ALU,
multiplier, accumulator and scaling chief register. The PC used to address program
memory and always contains the address of next instruction to be executed. Here data and
control buses are bidirectional and address bus is unidirectional.
32 Bit Microprocessors
80386
• Introduced in 1986
• First 32-bit microprocessor
• Data bus is 32 bit and address bus is 32-bit
• It could address 4GB of memory
• It has 275,000 transistors
• Clock speed varied from 16 MHz to 33 MHz depending upon different versions
• Different Versions
➢ 80386DX
➢ 80386SX
➢ 80386SL
80486
• Introduced in 1989
• 32-bit microprocessor
• Had 1.2 million transistors
• Clock speed varied from 16 MHz to 100 MHz depending upon the various versions
It had five different versions
➢ 80486DX
➢ 80486SX
➢ 80486DX2
➢ 80486SL
➢ 80486DX4
• 8KB of cache memory was introduced
Pentium
• Introduced in 1993
• It was also 32-bit microprocessor
• Clock speed was 66 MHz
• Data bus is 32-bit and address bus is 32-bit
• Could address 4GB of memory
• Could execute 110 million instructions per second
• Cache memory
➢ 8KB for Instruction
➢ 8KB for data
• Upgraded Version: Pentium Pro
Pentium II
• Introduced in 1997
• 32-bit microprocessor
• Clock speed was 233 to 450 MHz
• MMX technology was supported
• L2 cache and processor were on one circuit
• Upgraded Version: Pentium II Xenon
Pentium III
• Introduced in 1999
• It was 32-bit microprocessor
• Clock speed varied from 500 MHz to 1.4 GHz
• It had 9.5 million transistors
Pentium IV
• Introduced in 2000
• 32-bit microprocessor
• Clock speed was from 1.3 GHz to 3.8 GHz
• L1 cache was 32 KB and L2 cache was 256 KB
• It had 42 million transistors
Intel Dual Core
• Introduced in 2006
• It is 32-bit or 64 bit Microprocessor
• It has 2-cores
• Both cores have their own internal bus and L1 cache but share the external bus and
L2 cache
• Support SMT (Simultaneously Multithreading Technology)
8085 INTRODUCTION
The features of INTEL 8085 are:
• It is an 8 bit processor.
• It is a single chip N-MOS device with 40 pins.
• It works on 5 Volt dc power supply.
• The maximum clock frequency is 3 MHz while minimum frequency is 500 KHz.
• It provides 74 instructions with 5 different addressing modes.
• It has multiplexed address and data bus (AD0-AD7).
• It provides 16 address lines so it can access 216 =64K bytes of memory.
• It generates 8 bit I/O address so it can access 28=256 input ports.
Temporary register:
It is not available for user. All the arithmetic and logical operations are done in the
temporary register but user can’t access it.
Flag Register: It is an 8-bit register which consists of 5 flip flops used to know status
of various operations done.
S Z - AC - P - CY
REGISTER ARRAY
Temporary registers (W, Z): These are not available for user. These are loaded only
when there is an operation being performed.
General purpose: There are six 8-bit general purposes register in 8085 namely B, C,
D, E, H and L. These are used for various data manipulations. They can be used in
pairs as 16-bit registers. The register pairs are: BC pair, DE pair and HL pair.
Special purpose: There are two special purpose registers in 8085:
SP (Stack Pointer): It is a 16-bit register used to hold the address of stack
during stack operation i.e PUSH and POP operations.
PC (Program Counter): It is a 16-bit register which holds the address of next
instruction to be fetched. When a single byte instruction is executed PC is
automatically incremented by 1. Upon reset PC contents are set to 0000H.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
INSTRUCTION REGISTER AND DECODER
The instruction register and decoder are part of ALU. When an instruction is fetched
from memory, it is loaded in the instruction register. The decoder decodes the
instruction and establishes the sequence of events to flow. The instruction register is
not programmable and cannot be accessed through any instructions.
INTERRUPT CONTROL
It accepts different interrupts like TRAP, RST 5.5, RST 6.5, RST 7.5 and INTR. INTA
is interrupt acknowledgement signal.
SERIAL IO CONTROL
It is used to accept and send the serial 1 bit data by using SID and SOD signals and it
can be performed by using SIM & RIM instructions.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
LDA 16-bit Copies the content of memory LDA 2015H
(Load Accumulator location specified by 16-bit A [2015 ]
Direct) address into A
STA 16-bit Copies the content of A into STA 2015H A→[
(Store Accumulator 16-bit memory address 2015]
Direct)
Copies the content of memory LDAX B
LDAX Rp location specified by register
(Load Accumulator pair Rp into A
Inirect) Rp can be B or D i.e. BC
pair or DE pair
Copies the content of A into STAX B
STAX Rp 16-bit memory address specified
(Store Accumulator by register pair Rp
Indirect) Rp can be B or D i.e. BC pair
or DE pair
LXI Rp, 16-bit Loads 16-bit data into register LXI H, 2015H
(Load Register Pair) pair L15
Rp can be B, D or H i.e. BC H20
pair, DE pair or HL pair
IN 8-bit The data from i/p port IN 40H
specified by 8-bit address is A[40]
transferred into A 40H is address of
input port
OUT 8-bit The data of A is transferred OUT 10H
into output port specified by A→[10]
8bit address 10H is address of
output port
XCHG Exchange the content of HL XCHG
pair with DE pair i.e. the content H→D
of H and D are exchanged L→E
whereas content of
L and E are exchanged
b) Arithmetic Instructions
Mnemonics Description Example
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
The content of register ADC B
ADC R/M /memory (R/M) is added to the AA+B+CF
(add with carry) A along with carry flag CF and
result is stored in A ADC M
The memory M is specified AA+M+CF
by HL pair
ADI 8-bit The 8-bit data is added to A ADI 32H
(add immediate) and result is stored in A AA+32
ACI 8-bit The 8-bit data is added to A ACI 32H
(add immediate along with carry flag CF and result is AA+32+CF
with carry) stored in A
The content of register SUB B
SUB R/M /memory (R/M) is subtracted AA-B
(subtract from A and result is stored in
register/memory) A SUB M
The memory M is specified AA-M
by HL pair
The content of register SBB B
SBB R/M /memory (R/M) is subtracted AA-B-BF
(subtract with from A along with borrow
borrow) flag BF and result is stored in SBB M
A AA-M-CF
The memory M is specified
by HL pair
SUI 8-bit The 8-bit data is subtracted SUI 32H AA-
(subtract from A and result is stored in A 32
immediate)
Increment the content of INR B
INR R/M register/memory by 1 BB+1
(Increment Memory is specified by HL
Register/Memory) pair INR M
MM+1
Decrement the content of DCR B
DCR R/M register/memory by 1 BB-1
(Decrement Memory is specified by HL
Register/Memory) pair DCR M
MM-1
INX Rp Increment the content of INX H
(Increment Register register pair Rp by 1 HLHL+1
Pair)
DCX Rp Decrement the content of DCX H
(Decrement register pair Rp by 1 HLHL-1
Register Pair)
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
c) Logical Instructions
Mnemonics Description Example
CMP R/M • Compares the content of CMP B
(Compare register/memory with A
Register/Memory) • The result of comparison is: CMP M
If A< R/M : Carry Flag CY=1
If A= R/M : Zero Flag Z=1
If A> R/M : Carry Flag CY=0
CPI 8-bit • Compares 8-bit data with A •
(Compare The result of comparison is:
Immediate)
If A< 8-bit : Carry Flag CY=1 CPI 32H
If A= 8-bit : Zero Flag Z=1
If A> 8-bit : Carry Flag CY=0
ANA R/M The content of A are logically ANA B
(logical AND ANDed with the content of AA.B
register/memory) register/memory and result is
stored in A ANA M
Memory M must be AA.M
specified by HL pair
ANI 8-bit The content of A are logically ANI 32H
(AND immediate) ANDed with the 8-bit data AA.32H
and result is stored in A
ORA R/M The content of A are logically ORA B
(logical OR ORed with the content of AA or B
register/memory) register/memory and result is
stored in A ORA M
Memory M must be AA or M
specified by HL pair
ORI 8-bit The content of A are logically ORI 32H
(OR immediate) ORed with the 8-bit data and AA or 32H
result is stored in A
XRA R/M The content of A are logically XRA B
(logical XOR XORed with the content of AA xor B
register/memory) register/memory and result is
stored in A XRA M
Memory M must be AA xor M
specified by HL pair
XRI 8-bit The content of A are logically XRI 32H
(XOR immediate) XORed with the 8-bit data AA xor 32H
and result is stored in A
d) Rotate Instructions
Mnemonics Description Example
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
RLC Each bit of A is rotated left RLC
(Rotate by one bit position. Bit D7 is
Accumulator Left) placed in the position of D0.
e) Branching Instructions
Mnemonics Description Example
JMP 16-bit The program sequence is transferred JMP C000H
(Unconditional to the memory location specified by
Jump) 16-bit address
JC Jump on Carry (CY=1)
JNC Jump No Carry (CY=0)
JP Jump on Positive (S=0)
JM Jump on Negative (S=1)
JZ Jump on Zero (Z=1)
JNZ Jump No Zero (Z=0)
JPE Jump on Parity Even (P=1)
JPO Jump on Parity Odd (P=0)
CALL 16-bit The program sequence is transferred CALL C000H
to the subroutine at memory location
specified by the 16-bit address
RET The program sequence is transferred RET
from the subroutine program to
calling program
f) Control Instructions
Mnemonics Description Example
NOP No operation is performed NOP
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
HLT The CPU finishes executing the HLT
current instruction and stops any
further execution
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
TIMING DIAGRAMS OF 8085 INSTRUCTIONS a)
Related Terms
Instruction Cycle: The time taken to complete the execution of an instruction is
called instruction cycle. It is the combinations of machine cycles.
Machine Cycle: The time taken by the processor to access memory location, IO
ports or to acknowledge an interrupt once is called as machine cycles. It is the
combinations of T-states.
IO/ S1 S0
Opcode Fetch 0 1 1
Memory Read 0 1 0
Memory Write 0 0 1
IO Read 1 1 0
IO Write 1 0 1
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
INTERNAL ARCHITECTURE OF 8086
The first byte specifies the opcode and the remaining two bytes specifies the
16bit address i.e. second byte specifies the lower order address and third byte
specifies the higher order address. Example: LDA 2070H
STA 2050H
LXI H, 2070H
8086 MICROPROCESSOR
• The 8086 CPU is divided into two independent functional parts : BIU (Bus Interface
Unit) and EU (Execution Unit)
• Dividing the work between these units speed up the processing.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
A. THE EXECUTION UNIT (EU)
• The EU of the 8086 tells the BIU where to fetch the instructions and data from,
decodes instructions and executes instructions.
• The EU has a 16 bit ALU which can add subtract, ND, OR, increment, decrement,
complement or shift binary numbers.
AX = Accumulator Register
BX = Base Register
CX = Count Register
DX = Data Register
2. FLAG REGISTER
• A Flag is a flip-flop which indicates some condition produced by the execution of an
instruction or controls certain operations of the EU.
• A 16 bit flag register in the EU contains 9 active flags.
• Figure below show shows the location of the nine flags in the flag register.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U U U U OF DF IF TF SF ZF U AF U PF U CF
CONTROL FLAG
TF = SINGLE STEP TRAP FLAG
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
IF = INTERRUPT ENABLE FLAG
DF = STRING DIRECTION FLAG
• The six conditional flags in this group are the CF,PF,AF,ZF,SF and OF
• The three remaining flags in the Flag Register are used to control certain operations of
the processor.
• The six conditional flags are set or reset by the EU on the basis of the result of some
arithmetic or logic operation.
• The Control Flags are deliberately set or reset with specific instructions you put in
your program.
• The three control flags are the TF, IF and DF.
• Trap Flag is used for single stepping through a program.
• The Interrupt Flag is used to allow or prohibit the interruption of a program.
• The Direction Flag is used with string instructions.
3. POINTER REGISTERS
• The 16 bit Pointer Registers are IP,SP and BP respectively
• SP and BP are located in EU whereas IP is located in BIU
4. INDEX REGISTERS
The 16 bit Index Registers are SI and DI
• The BIU send out address, fetches instructions from memory, reads data from ports
and memory, and writes data to ports and memory.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• In other words BIU handles all transfers of data and addresses on the buses for the
execution unit.
1. SEGMENT REGISTERS
1.1 CODE SEGMENT REGISTER (CS)
• It contains the starting address of a program's code segment.
• This segment address plus an offset value in the IP register indicates the address of an
instruction to be fetched for execution
• For normal programming purpose, you need not directly reference this register.
3. THE QUEUE
• While the EU is decoding an instruction or executing an instruction which does not
require use of the buses, the BIU fetches up to six instructions bytes for the following
instructions.
• The BIU Stores pre-fetched bytes in First in First out register set called a queue.
• When the EU is ready for its next instruction, it simply reads the instruction bytes for
the instruction from the queue in the BIU.
• This is much faster than sending out an address to the system memory and waiting for
memory to send back the next instruction bytes or bytes.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• Fetching the next instruction while the current instruction executes is called
pipelining.
ADDRESSING MODES
• The different ways in which a processor can access data are referred to as its
addressing modes.
• In assembly language statements, the addressing mode is indicated in the instruction
itself.
• The various addressing modes are
EXAMPLES
MOV AL, BL : Copies BL into AL
MOV ES, DS : Copies DS into ES
8MOV AX, CX : Copies CX into AX
EXAMPLES
MOV AL, 90 : Copies 90 into AL
MOV AX, 1234H : Copies 1234H into AX
MOV CL, 10000001B : Copies 100000001 binary value into CL
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
3. DIRECT ADDRESSING MODE
• In this scheme, the address of the data is defined in the instruction itself.
• When a memory location is to be referenced, its offset address must be specified
MEMORY LOCATION
11234 H
EXAMPLES
MOV AL, [1234H] : Copies the byte content of data segment memory location
11234H into AL.
MOV AL, NUMBER: Copies the byte content of data segment memory location
NUMBER into AL.
MEMORY LOCATION
10300H
EXAMPLES
MOV CX, [BX] : Copies the word contents of the data segment memory
location addressed by BX into CX.
MOV [DI], BH : Copies BH into the data segment memory location
addressed by DI.
MOV [DI], [BX] : Memory to Memory moves are not allowed except
with string instructions.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
5. BASE PLUS INDEX ADDRESSING MODE
• Base plus index addressing is similar to indirect addressing because it indirectly
addresses memory data
• This type of addressing uses one base register (BP or BX) and one Index Register (DI
or SI) to indirectly address memory.
MEMORY LOCATION
10500H
EXAMPLES
MOV CX, [BX+DI] : Copies the word contents of the data
segment memory location addressed by BX plus DI into CX.
MOV CH, [BP+SI] : Copies the byte contents of the stack
segment memory location addressed by BP plus SI into CH.
MEMORY LOCATION
10304H
EXAMPLES
MOV [SI+4], BL : Copies BL into the data segment memory location addressed by
SI plus 4
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
7. BASE RELATIVE PLUS INDEX ADDRESSING MODE
• The base relative plus index addressing mode is similar to the base plus index
addressing mode but it adds a displacement to form a memory address.
• Transfers a byte or word between a register and the memory location addressed by a
base and an index register plus a displacement.
MEMORY LOCATION
10505H
EXAMPLES
MOV DH, [BX+DI+20H] : Copies the byte contents of the data segment memory location
addressed by the sum of BX, DI and20H into DH
INSTRUCTIONS COMMENTS
MOV Copy byte or word from specified source to
MOV Destination,Source Eg specified destination.
: MOV CX,04H
PUSH Copy specified word to top of stack.
PUSH Source
Eg: PUSH BX
POP Copy word from top to stack to specified
POP Destination location.
Eg: POP AX
XCHG Exchange word or byte.
XCHG Destination,Source
Eg: XCHG AX,BX
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
1.2 SIMPLE INPUT AND OUTPUT PORT TRANSFER INSTRUCTIONS
INSTRUCTIONS COMMENTS
IN Copy a byte or word from specified port to
accumulator.
IN AX,Port_Addr
Eg:IN AX,34H
INSTRUCTIONS COMMENTS
LEA Load effective address of operand into specified
register.
LEA Register,Source
Eg: LEA BX,PRICE
LDS Load DS register and other specified register from
memory.
LDS Register,Source
Eg: LDS BX,[4326H]
2. ARITHMETIC INSTRUCTIONS
INSTRUCTIONS COMMENTS
ADD Add specified byte to byte or word to word.
ADD Destination,Source
Eg: ADD AL,74H
ADC Add byte + byte + carry flag Add
word+word + carry flag
ADC Destination,Source
Eg: ADC CL,BL
INC Increment specified byte or word by 1.
INC Register
Eg: INC CX
AAA ASCII adjust after addition.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
DAA Decimal adjust after addition.
INSTRUCTIONS COMMENTS
SUB Subtract byte from byte or word from word.
SUB Destination,Source
Eg: SUB CX,BX
SBB Subtract byte and carry flag from byte.
Subtract word and carry flag from word.
SBB Destination,Source
Eg: SBB CH,AL
DEC Decrement specified byte or word by 1.
DEC Register
Eg: DEC CX
NEG Form 2's complement.
NEG Register
Eg: NEG AL
CMP Destination,Source
Eg: CMP CX,BX
CF ZF SF
CX = BX 0 1 0
CX > BX 0 0 0
CX < BX 1 0 1
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
2.3 MULIPLICATION INSTRUCTION
INSTRUCTIONS COMMENTS
MUL Multiply unsigned byte by byte or unsigned word
by word.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
AAD ASCII adjust before division
BCD to binary convert before division.
MSB->MSB LSB->CF
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
3.3 ROTATE INSTRUCTIONS
INSTRUCTIONS COMMENTS
ROL Rotate Bits of Byte or Word Left,MSB to LS and to
CF.
ROR Rotate Bits of Byte or Word Right,LSB to MSB and
to CF.
RCL Rotate Bits of Byte or Word Left,MSB to CF and
CF to LSB.
RCR Rotate Bits of Byte or Word Right,LSB TO CF and
CF TO MSB.
INSTRUCTIONS COMMENTS
CALL Call a Subprogram/Procedure.
INSTRUCTIONS COMMENTS
JC Jump if Carry Flag CF=1.
JE/JZ Jump if Equal/Jump if Zero Flag (ZF=1).
JNC Jump if No Carry i.e. CF=0
JNE/JNZ Jump if Not Equal/Jump if Not Zero(ZF=0)
JNO Jump if No Overflow.
JNP/JPO Jump if Not Parity/Jump if Parity Odd.
JNS Jump if Not Sign(SF=0)
JP/JPE Jump if Parity/Jump if Parity Even (PF=1)
JS Jump if Sign (SF=1)
LOOP Loop Through a Sequence of Instructions Until
CX=0.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
JCXZ Jump to Specified Address if CX=0.
• Assembly language statements are usually written in a standard form that has 4 fields.
• A LABEL is a symbol used to represent an address. They are followed by colon. Labels
are only inserted when they are needed so it is an optional field.
• The OPCODE FIELD of the instruction contains the mnemonics for the instruction to be
performed. The instruction mnemonics are sometimes called as operation codes.
• The OPERAND FIELD of the statement contains the data, the memory address, the port
address or the name of the register on which the instruction is to be performed.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• The final field in an assembly language statement is the COMMENTS which start with
semicolon. It forms a well-documented program.
1. EDITOR
An Editor is a Program which allows you to create a file containing the Assembly
Language statements for your Program.
2. ASSEMBLER
An Assembler Program is used to translate the assembly language mnemonics for
instruction to the corresponding binary codes.
3. LINKER
A Linker is a Program used to join several files into one large .obj file. It produces .exe file
so that the program becomes executable.
4. LOCATOR
• A Locator is a program used to assign the specific address of where the segment of object
code are to be loaded into memory.
• It usually converts .exe file to .bin file.
5. DEBUGGER
• A Debugger is a program which allows you to load your .obj code program into system
memory, execute program and troubleshoot.
• It allows you to look at the content of registers and memory locations after your program
runs.
• It allows to set the breakpoint.
6. EMULATOR
• An Emulator is a mixture of hardware and software.
• It is used to test and debug the hardware and software of an external system such as the
prototype of a Microprocessor based system.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
TYPES OF ASSEMBLERS
MACRO ASSEMBLER
A macro assembler translates a program written in macro language into the binary codes
(machine language). A macro language is the one in which all the instruction sequences can
be defined using macros. A macro is an instruction sequence having specific name that
appears repeatedly in a program. The macro assembler replaces a macro name with the
appropriate instructions sequence, each time it encounters a macro name.
ADDITION MACRO
MOV AX, num1
MOV BX, num2
ADD AX, BX
ENDM
ASSEMBLER DIRECTIVES
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• Assembly Language supports a number of statements that enable to control the way in
which a source program assembles and lists. These Statements are called Directives.
• They act only during the assembly of a program and generate no machine executable
code.
• The most common Directives are:
1. PAGE DIRECTIVE
• The PAGE Directive helps to control the format of a listing of an assembled program.
• It is optional Directive.
• At the start of program, the PAGE Directive designates the maximum number of lines to
list on a page and the maximum number of characters on a line.
• Its format is
PAGE [LENGTH],[WIDTH]
• Omission of a PAGE Directive causes the assembler to set the default value to PAGE
50,80
2. TITLE DIRECTIVE
• The TITLE Directive is used to define the title of a program to print on line 2 of each
page of the program listing.
• It is also optional Directive.
• Its format is
TITLE [TEXT]
3. SEGMENT DIRECTIVE
• The SEGMENT Directive defines the start of a segment.
• A Stack Segment defines stack storage, a data segment defines data items and a code
segment provides executable code.
• The format (including the leading dot) for the directives that defines the stack, data and
code segment are
.STACK [SIZE]
.DATA
………………. Initialize Data Variables
.CODE
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
4. MEMORY MODEL DEFINTION
• The different models tell the assembler how to use segments to provide space and ensure
optimum execution speed.
• The format of Memory Model Definition is
• The Memory Model may be TINY, SMALL, MEDIUM, COMPACT, LARGE AND
HUGE.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
6. END DIRECTIVE
• As already mentioned, the ENDP Directive indicates the end of a procedure.
• An END Directive ends the entire Program and appears as the last statement.
• Its Format is
EXAMPLE
DATAX DB 25
DATA EQU DATAX
EXAMPLES
STRING DB 'HELLO WORLD'
NUM1 DB 10
NUM2 DB 90
DEFINITION DIRECTIVE
BYTE DB
WORD DW
DOUBLE WORD DD
FAR WORD DF
QUAD WORD DQ
TEN BYTES DT
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
Duplication of Constants in a Statement is also possible and is given by
EXAMPLES
DATAX DB 5 DUP(12) ; 5 Bytes containing hex 0c0c0c0c0c DATA DB
10 DUP(?) ; 10 Words Uninitialized
1. CHARACTER STRINGS
• Character Strings are used for descriptive data.
• Consequently DB is the conventional format for defining character data of any length
• An Example is DB 'Computer City'
DB "Hello World"
DB "NCIT College"
2. NUMERIC CONSTANTS
#BINARY : VAL1 DB 10101010B
#DECIMAL : VAL1 DB 230
#HEXADECIMAL : VAL1 DB 23H
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
8086 MODES OF OPERATION
There are two available modes of operation for 8086.
1. Minimum mode of Operation
2. Maximum Mode of Operation
Minimum mode is obtained by connecting the mode selection MN/ to +5V. Maximum
mode is obtained by connecting MN/ to ground.
• Bit S5 is the logic level of the internal enable flag Bit S6 is always at
logic
‘0’ level.
c) Control Signals
The following are the control signals associated with 8086 minimum mode
ALE (Address Latch Enable): latch address and data
• (Bus High Enable): must be made low for read or write
operation and it acts as a status signal S7
• /IO (Memory/IO): IO operation if /IO=1
Memory operation if /IO=0
• DT/ (Data Transmit/Receive): Data Transmitting if DT/ =1
Data Receiving if DT/ =0
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• (Read): indicates read bus cycle when
• (Write): indicates write bus cycle when
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
2. Maximum Mode
• In maximum mode, the 8086 is operated by connecting the MN/ pin to
ground.
• In this mode, the processor derives the status signals S2, S1, S0. Another chip
called Bus Controller derives the control signals using these status signals.
• In maximum mode, there may be more than one microprocessors
(coprocessors) in the system configuration.
• The Bus Controller receives the three status signals S2, S1, S0 from 8086 and
generates the signals that are needed to control the memory, IO and Interrupt
Interfaces.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• is used to issue interrupt acknowledge pulses to the interrupt controller
or to the interrupting device
• (IO Read Command), (IO write Command) enable an IO
interface to read or write data from or to the address port
• (Memory Read Command), (Memory Write Command) are
used to read from or write into memory locations
• For both IO and Memory Write Command signals, the advance signals namely
(Advance IO Write Command) and (Advance Memory
Write Command) are available.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
MODULAR PROGRAMMING
1. LINKING AND RELOCATION
Program is composed from several smaller modules. Modules could be developed by
separate teams concurrently. The modules are assembled producing .OBJ modules
(Object modules). The DOS linking program links the different object modules of a
source program and function library routines to generate an integrated executable
code of the source program.
The main input to the linker is the .OBJ file that contains the object modules of the
source programs. The linker program is invoked using the following options. C>
LINK
or
C>LINK [Link]
The .OBJ extension is a must for a file to be accepted by the LINK as a valid object
file.
The first object may generate a display asking for the object file, list file and libraries
as inputs and an expected name of the .EXE file to be generated. The output of the
link program is an executable file with the entered filename and .EXE extension. This
executable filename can further be entered at the DOS prompt to execute the file.
Linking is necessary because of the number of codes to be linked for the final binary
file.
The linked file in binary for run on a computer is commonly known as executable file
or simply ‘.exe.’ file. After linking, there has to be re-allocation of the sequences of
placing the codes before actually placement of the codes in the memory. The loader
program performs the task of reallocating the codes after finding the physical RAM
addresses available at a given instant. The loader is a part of the operating system and
places codes into the memory after reading the ‘.exe’ file. This step is necessary
because the available memory addresses may not start from 0x0000, and binary codes
have to be loaded at the different addresses during the run. The loader finds the
appropriate start address.
In a computer, the loader is used and it loads a program that is ready to run, into a
section of RAM. A program called locator reallocates the linked file and creates a file
for permanent location of codes in a standard format.
2. STACK
➢ The stack is a block of memory that may be used for temporarily storing the
contents of the registers inside the CPU.
➢ It is a top-down data structure whose elements are accessed using the stack pointer
(SP) which gets decremented by two as we store a data word into the stack and
gets incremented by two as we retrieve a data word from the stack back to the
CPU register.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
➢ The process of storing the data in the stack is called ‘pushing into’ the stack and
the reverse process of transferring the data back from the stack to the CPU register
is known as ‘popping off’ the stack.
➢ The stack is essentially Last-In-First-Out (LIFO) data segment. This means that
the data which is pushed into the stack last will be on top of stack and will be
popped off the stack first.
➢ The stack pointer is a 16-bit register that contains the offset address of the memory
location in the stack segment. Stack Segment register (SS) contains the base
address of the stack segment in the memory.
3. PROCEDURES/SUBROUTINES
➢ Procedure or a subroutine or a function is a key concept for modular programming,
the essential way to reduce complexity.
➢ A procedure is a reusable set of instructions that has a name.
➢ Only one copy of the procedure is stored in the memory; and it can be called as many
times as needed.
➢ As only one copy is stored, it saves memory; but has execution time overhead for the
CALL and RETURN operations.
➢ CALL transfers control to the procedure just like in JUMP; but unlike a JUMP,
procedure has a RETURN instruction which returns control to the instruction
following the CALL instruction
➢ In order to implement such a return, the necessary information is stored on a stack,
before transferring control to the procedure.
➢ In program, procedure starts with PROC directive and ends with ENDP directive. ➢
PROC directive is followed by the type of procedure: NEAR or FAR.
Near CALL
➢ A procedure may be in the same code segment as that of the main program (Intra
segment). In such a case, we specify only IP. This is known as NEAR CALL. Example:
Main program:
…. …..
CALL DISPLAY ; calling a procedure. Transfer control to procedure named as DISPLAY
…..
…….. Procedure Definition……..
DISPLAY PROC NEAR
MOV DX, OFFSET string1
MOV AH, 02H
INT 21H
RET
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
DISPLAY ENDP
FAR CALL
➢ A procedure may be in a different code segment (Inter segment). In such a case, we
need to specify both IP and CS (directly or indirectly). This is known as a FAR
CALL.
Example:
4. MACRO
➢ MACRO is a group of instructions with a name.
➢ When a macro is invoked, the associated set of instructions replaces the macro name
in the program. This macro expansion is done by a Macro Assembler and it happens
before assembly. Thus the actual Assembler sees the expanded source.
MACRO Definition:
A macro has a name. The body of the macro is defined between a pair of
directives, MACRO and ENDM.
Examples of Macro Definitions:
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
MACROS Vs PROCEDURES
1) Procedure:
➢ Only one copy exists in memory. Thus memory consumed is less.
➢ Called when required
➢ Return address (IP or CS:IP) is saved (PUSH) on stack before transferring control to
the subroutine through CALL instruction. It should be popped (POP) again when
control comes back to calling program with RET instruction.
➢ Execution time overhead is present because of the call and return instructions. ➢ If
more lines of code, better to write a procedure than a macro.
2) Macro:
➢ When a macro is invoked, the corresponding code is inserted into the source. Thus
multiple copies of the same code exist in the memory leading to greater space
requirements.
➢ However, there is no execution overhead because there are no additional call and
return instructions.
➢ No use of stack for operation.
➢ Good if few lines of code are in the Macro body.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
CHAPTER 5: INTERRUPTS
INTRODUCTION
Interrupt is considered as an emergency signal to which the MP responds as soon as possible.
When the microprocessor receives an interrupt signal, it suspends the current executing
program and jumps to an interrupt service routine (ISR) to respond to the incoming interrupt
When a device interrupts, it actually wants the microprocessor to give a service which is
equivalent to asking the microprocessor to call a subroutine. This subroutine is call Interrupt
Service Routine (ISR).
SOURCES OF INTERRUPTS
There are three sources of interrupts and they are as follows:
1. Processor Interrupt
2. Software Interrupt
3. Hardware Interrupt
Processor Interrupt
These interrupts are generated by processor itself, usually in response to an error condition.
For example: In 8086 Type 0 interrupt occurs when attempt to divide by zero which is a
processor interrupt.
Software Interrupt
These are special instructions that trigger an interrupt response to processor.
In 8086 the general form of software interrupt instruction is INT nnH (eg: INT 21H)
Hardware Interrupt
Hardware interrupts are interrupt request initiated by external hardware.
8086 have two pins reserved for hardware interrupts. They are NMI and INTR
CLASSIFICATIONS OF INTERRUPTS
Interrupts can be classified as:
• Maskable Interrupt or Non-Maskable Interrupt
• Vectored Interrupt or Non-Vectored Interrupt
Maskable Interrupt
• The interrupts which can be blocked or delayed by using instructions are called
maskable interrupts.
• In 8085, the RESET interrupts (RST 5.5, RST 6.5 and RST 7.5) and INTR are
maskable interrupts. They can be enabled/disabled by using instructions EI/DI.
• In 8086, INTR is maskable interrupt. It can be enabled/disabled by using
instructions STI/CLI.
Non-Maskable Interrupt
• Those interrupts which cannot be blocked by instructions are termed as
nonmaskable interrupts.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• In 8085, TRAP is only non-maskable interrupt and it is used for power failure and
emergency cutoff.
• In 8086, NMI is non-maskable interrupt.
Vectored Interrupt
• The interrupts for which address of ISR is already known to MP are called
vectored interrupts.
• In 8085, RESET interrupts (RST 5.5, RST 6.5 and RST 7.5) are vectored
interrupts.
Interrupt Vector Address (Hex)
RST 5.5 002C
RST 6.5 0034
RST 7.5 003C
Non-Vectored Interrupt
• In non-vectored interrupts, the interrupting device needs to supply the address of
the ISR to the microprocessor.
• In 8085, INTR is non-vectored interrupt.
8085 INTERRUPTS
8085 microprocessor consists of five interrupt signals: INTR, RST 5.5, RST 6.5, RST 7.5 and
TRAP
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• It is used as external hardware interrupt source and is used for power failure
and emergency shutoff instruction.
8086 INTERRUPTS
• An 8086 interrupt can come from any one of 3 sources.
• One source is an external signal applied to the Nonmaskable Interrupt (NMI) or to the
(INTR) input pin. An interrupt caused by a signal applied to one of these inputs (NMI or
INTR) is referred as Hardware Interrupt.
• A second source of an interrupt is execution of the interrupt instruction INT nn. This is
referred as Software Interrupt.
• The third source of an interrupt is some error conditions produced in 8086, by the
execution of an instruction, referred as processor interrupt.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• These 256 interrupts are stored in memory location forming a table which is called
Interrupt Vector Table (IVT).
• An Interrupt Vector contains the address (segment CS and offset IP) of the Interrupt
Service Routine.
• Each vector is a 4 byte long and contains the starting address of the Interrupt Service
Routine.
• The first 2 bytes of the vector contain the offset address (IP) and the last two bytes
contain the segment address (CS).
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
• When a MP is interrupted using Type 1 interrupt, it will execute one instruction and stop so
that we can then examine the contents of registers and memory locations.
• In other words, in single step mode, a system will stop after it executes each instruction
and waits for further direction from us.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar
Pudasaini, rameshkp@[Link]
3. NON MASKABLE INTERRUPT : TYPE 2
• A result of placing logic 1 on the NMI input pin causes type 2 interrupt.
• This input is non-maskable, which means that it cannot be disabled.
• Another common use of type 2 interrupt is to save program data in case of a system power failure or
to deal with some other catastrophic failure conditions.
• Some external circuitry detects when the AC power to the system fails and sends an Interrupt signal
to the NMI.
INTERRUPTS PRIORITY
DIVIDE ERROR, INT n , INTO HIGHEST
NMI
INTR
SINGLE STEP LOWEST
PRIORITISING INTERRUPTS
1. Polled Interrupts
A polling procedure is used to identify the interrupt source having the highest priority.
Only one branch address is used for all interrupts.
The priority of each interrupt source determines the order in which it is polled. The source
with the highest priority is tested first, and if its interrupt signal is on, control branches to a
routine that services that source. Otherwise, the source with the next lower priority is tested,
and so on.
2. Vectored Interrupt
A vectored interrupt unit functions as an overall manager in an interrupt system environment.
The unit accepts interrupt requests from many sources, determines which request has the
highest priority, and issues an interrupt request to the computer based on this determination. To
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
speed up the operation, each interrupt source has its own interrupt vector address to access its
own service routine directly.
INTERRUPT PROCESSING
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Figure: Interrupt Processing
• The processor checks for interrupts. If interrupt has occurred, processor will complete the
instruction currently being executed.
• The processor will disable the further interrupts.
• The processor stores the current state of program by PUSH operation i.e. the value of flag
register and CS: IP will be stored into stack by PUSH operation.
• The processor will load the address of the ISR and execute the ISR. At the end of ISR,
instruction IRET is used which makes the processor return from the ISR to the original program.
• After the execution of ISR, the processor restores the previous state of program i.e. it will restore
the value of flag register and CS: IP from stack by POP operation.
• The processor enables the interrupts and then starts program execution from where it has been
interrupted.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
CHAPTER-4 BUS STRUCTURE AND MEMORY DEVICES
BUS STRUCTURE
In any microprocessor system, the system bus consists of a number of separate lines. Each line
is assigned a particular function. Fundamentally in any system, the system bus can be classified
into three functional groups: the address, the data and control lines or buses.
Data Bus
• The data bus provides path for transferring data between the microprocessor system and
the peripherals.
• The data bus consists of a number of separate lines, generally 8, 16, 32 or 64. The number
of lines is referred as the width of the data bus.
• Since, each line carry only one bit at a time, the number of lines determines how many bits
can be transmitted at a time.
• The width of data bus is a key factor in determining the overall system performance.
Address Bus
• The address bus which consists of a number of separate lines, are used to designate the source or
destination of the data on data bus. For example, if the CPU requires reading a word (8, 16, 32 or
64 bits of data) from memory, it put the address of the desired word on the address bus.
• The width of address bus (i.e number of lines) determines the maximum possible memory
capacity of the system.
• The address bus is also used to address IO ports.
Control Bus
• The control bus is a group of lines used to control the access to and the use of the data and
address bus since the data and address bus are shared by all components of microcomputer
system. Hence control bus provides a means of controlling their use.
• The control bus carries the control signals. The control signals transmit both command and
timing information between the system modules.
• The timing signals indicate the validity of data and address information; whereas the
command signals specify the operations to be performed.
• Some control signals are: Memory Read, Memory Write, IO Read, IO Write, Interrupt
Request, Interrupt Acknowledge, Bus request, Bus Grant etc.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
SYNCHRONOUS AND ASYNCHRONOUS BUS
Synchronous Bus
In a synchronous bus, the occurrence of the events on the bus is determined by a clock. The
clock transmits a regular sequence of 0’s and 1’s of equal duration. A single 1-0 transition is
called clock cycle or bus cycle and defines a time slot. All other devices on the bus can read the
clock live, and all events start at the beginning of the clock cycle. In synchronous bus, all
devices are tied to a fixed rate, and hence the system cannot take advantage of device
performance. It is easier to implement.
Asynchronous Bus
In an asynchronous bus, the timing is maintained in such a way that occurrence of one event
on the bus follows and depends on the occurrence of previous event. Asynchronous bus are
faster than the synchronous bus as the events are independent of the processor timing.
MEMORY DEVICES
• In a microcomputer system, the memory is used to store both instructions and data. A memory
can be volatile or non-volatile. The contents of a volatile memory are lost if power is turned
off; whereas the non-volatile memory retains its contents after the power is switched off.
• A microcomputer’s memory system can be divided into three groups:
a) Processor Memory
b) Primary or Main Memory
c) Secondary Memory
a) Processor Memory Microprocessor’s registers and cache memory are referred to
as processor memory.
• The registers are used to hold results temporarily when computation is in
progress. The speed of registers is equal to the speed of microprocessor, since
they are fabricated using the same technology. Although the use of registers
enhances the execution speed, the cost involved in the approach forces the
microprocessor designers to include only few registers inside the processors.
• Beside registers, these days microprocessor also consists of a separate memory
in order to store the frequently needed information, known as cache memory.
The speed and efficiency of program execution has been significantly improved
by the use of cache memory.
b) Primary/Main Memory
It is the storage area where all programs are executed. The microprocessors can directly
access only those items that are stored in primary memory. Hence, all programs and
data must be in primary memory prior to execution.
Primary memories can be divided into two main groups:
• Random Access Memory (RAM)
• Read Only Memory (ROM)
Random Access Memory (RAM)
From its name itself, it is obvious that this memory uses random access mode. It is
read/write memory i.e information can be read from it or can be written on it.
However, it is volatile in nature. Being random access mode, it is faster with access
time in nano seconds. The Random Access Memories are basically of two types:
• Dynamic RAM (DRAM)
• Static RAM (SRAM)
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Dynamic RAM: Dynamic RAM stores data in capacitors; it can hold data for
few milliseconds. Thus dynamic RAM need to be refreshed by using external
refresh circuitry. The charging of capacitor and refreshing is done by MOS
transistors. Due to its small storage cell, DRAM exhibits compactness i.e.
greater number of bits can be stored in small chips. Thus, DRAMs are cheaper
than SRAM. However the interfacing circuit of DRAM is complicated
because of refreshing circuit.
Static RAM: The static RAM is made up of flip-flops. A single flip-flop stores
one bit information i.e. 0 or 1. Each flip-flop is called storage cell of the
memory device. The individual storage cell is addressed with the help of row
and column decoder in the SRAM.
c) Secondary Memory
Secondary Memory refers to the storage medium comprising slow devices such as
hard disks. These devices are used to hold large data files and huge programs such as
compilers and database management systems that are needed by the processor
frequently. The secondary memories are also referred to as auxiliary or backup storage.
On the basis of access modes, secondary memories are of three types:
➢ Random Access Secondary Memory
➢ Sequential Access Memory
➢ Semi random Access Memory
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Semiconductor Memories
Semi random Access Memory: These memories combine both random and
sequential access mode. This is done in order to achieve a compromise
between random access and sequential access memories because the random
access is more expensive than sequential access though it is much faster.
Example: Floppy, Hard Disks
ADDRESS DECODING
• The process of generating chip select signal ( ) using the address lines of the
microprocessor and a decoder or logic-gates, to interface memory devices or IO devices
with microprocessor is called address decoding.
• During address decoding, the address lines of a microprocessor is divided into two parts. N
most significant lines and M list significant bits. The N most significant lines are passed to
decoder/logic-gates to generate signal, whereas the M least significant lines are passed
directly to the device (memory/IO).
Full Address Decoding: If all the address lines of a microprocessor system is used to
address a memory or IO devices, such address decoding is called full address
decoding. The address of the memory/IO in this scheme is unique so it is also called
unique address decoding or absolute address decoding.
Partial Address Decoding: If all the address lines of microprocessor is not used i.e. only
some address lines are used to address a memory location or IO device then it is called
partial address decoding. The address of the memory location/IO device is not unique i.e.
the memory or IO device may have two or more address. It is also called non-unique
address decoding.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
CHAPTER 5 INPUT OUTPUT INTERFACES
Block Diagram
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Status Registers Interrupt Request Register (IRR)
• 8-bit register that indicates which interrupt request inputs are active In-Service
Register (ISR)
• 8-bit register that contains the level of interrupt being serviced Interrupt Mask
Register (IMR)
• 8-bit register that stores the interrupt mask bits and indicates which interrupts are
masked off.
Priority Resolver
• This block determines the priority of the bits set in IRR.
Cascade Buffer
• This block is used for cascading multiple 8259s to handle more than 8 interrupts.
• CAS2-CAS0 cascade lines are used as output from master to slave 8259s
• SP/ (Slave Program / Enable) pin is used to identify master or slave 8259A. For master SP/
=1 and for slave SP/ =0.
Interfacing 8259A with Microprocessor
3. Special Mask Mode This mode can be enabled by making ESMM and
SMM bits as ‘1’ in operation control word OCW3.
In this mode, by programming the mask register, it is possible to selectively enable the
interrupts.
4. Polled Mode
• Polled mode is enabled by making P=1 in OCW3.
• In this mode of operation INT output of the 8259A is either not connected to INTR of
MPU or the system interrupts are disabled by the software.
• The peripherals are serviced by MPU by polling the interrupt request.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
8255A PROGRAMMABLE PHERIPHERAL INTERFACE (PPI)
• 8255A I widely used programmable parallel I/O device. It can be programmed to transfer
data under various conditions from simple I/O to interrupt I/O.
• It is a general purpose device that can be interfaced with almost any microprocessor for
I/O interface.
BLOCK DIAGRAM
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
•
Data, control words and status information are transferred through data bus buffer.
I/O Ports
• The 8255A has 24 I/O pins that are grouped into three 8-bit parallel I/O ports: Port A (PA)
Port B (PB) and Port C (PC)
• The 8-bit of port C can be used as individual bits or grouped into two 4-bit ports: Port C
Upper (PCU) and Port C Lower (PCL)
• The functions of I/O ports are defined by writing a control word into control register.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Q. Derive a control word for 8255A to configure:
Port A= i/p port
Port B= o/p port
Port C Lower= i/p port
Port C Upper= o/p port
In simple I/O mode with Group A in mode 0 and Group B in mode 1.
Solution:
Control Word = 1 0 0 1 0 1 0 1
=10010101
= 95H
In this mode, ports A and B are used as two simple 8-bit I/O port and port C as two 4-bit ports.
Each port can be programmed to function simply as input port or output port. The I/O features
in Mode 0 are:
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
•
In this mode, handshake signals are exchanged between the MPU and peripherals during data
transfer. The features of this mode are:
• Two ports PA and PB function as 8-bit I/O ports. They can be configured either as input or
output.
• Each port PA and PB uses three lines from Port C as handshake signals. The remaining two
lines of PC can be used for Simple I/O function (mode 0).
• Input and Output data are latched.
• Interrupt logic is supported.
• This mode is used primarily in applications such as data transfers between two computers.
• In this mode Port A can be configured as the bidirectional port (data bus) and Port B either in
mode 0 or mode 1.
• Port A uses five signals from Port C as handshake signals for data transfer. The remaining
three signals form Port C can be used as Simple I/O or as handshake for Port B.
Solution:
Control Word to Set PC7= 0 0 0 0 1 1 1 1
= 00001111
=0FH
Control Word to Set PC3= 00000111
= 07H
Control Word to Reset PC0= 00000000
= 00H
Control Word to Reset PC2= 00000100
=04H
BLOCK DIAGRAM
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
•
Control Logic
• The control section has five signals: (Read), (Write), (Chip Select) and address
lines AO, A1.
(Read) and (Write) are connected to (IO Read) and (IO Write) respectively in
IO mapped IO and (Read) and (Write) are connected to (Memory Read) and
(Memory Write) respectively in Memory mapped IO.
• Address lines AO and A1 are connected to the address lines AO and A1 of MPU and is
connected to the decoded address.
• is used to enable or select the device. If the chip is selected.
• The counters and control word register are selected according to signals on lines AO and A1 as
shown in table below-
A1 AO Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
Counters
• 8254 includes three identical 16-bit counters that can operate independently in any six modes
of operation.
• To operate a counter, a 16-bit count is loaded into its register.
• The counter can count either in BCD or Binary.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
CONTROL WORD OF 8254
Q. Generate a 8254 control word to operate it as a BCD counter in mode 2 using Counter 0
with 16-bit value of count.
Solution:
Control Word= 0 0 1 1 0 1 0 1
=00110101
=35H
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
•
• When the GATE is triggered, the OUT goes low and at the end of count, the OUT goes high
again thus generating a one-shot pulse.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
i.e frequency of square wave =
Q. Write a subroutine program to generate 1 KHz square wave from Counter-1 of 8254 PIT.
Solution:
Given:
Counter= Counter 1
Mode of Operation= Mode 3: Square Wave Generator
Frequency of square wave= 1 KHz
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
•
= 1000
Control Word = 0 1 1 1 0 1 1 1
=77H
Subroutine Program
SQUAREWAVE: MVI A, 77H ;move value of control word in A
OUT 83H ;load control word in A into control register
MVI A, 00 ; move lower byte of count into A
OUT 81H ; move lower byte of count in A into Counter 1
MVI A, 10 ; move higher byte of count into A
OUT 81H ; move higher byte of count in A into Counter 1
RET ; return from subroutine program
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Q. Write a subroutine program to generate a pulse of width 50 microseconds using 8254 PIT.
Take frequency of clock as 2 MHz and use Counter 0.
Solution:
Given:
Counter= Counter 0
Mode of Operation= Mode 1: Hardware Retriggerable One Shot
Time period of pulse= 50 µS
Frequency of Clock= 2 MHz
Count
Control Word = 0 0 1 1 0 1 0 1
= 00110101
=35H
Subroutine Program
PULSE: MVI A, 35H ; move value of control word in A
OUT 83H ; load control word in A into control register
MVI A, 00 ; move lower byte of count into A
OUT 80H ; move lower byte of count in A into Counter 0
MVI A, 01 ; move higher byte of count into A
OUT 80H ; move higher byte of count in A into Counter 0
RET ; return from subroutine program
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
DMA CONTROLLER
DMA (Direct Memory Access) and 8237 DMA CONTROLLER
• Direct memory access is an I/O technique commonly used for high speed data transfer.
• In DMA, the MPU releases the control of the buses to a device called DMA controller.
• The controller manages the data transfer between memory and peripherals under its control,
thus bypassing the MPU.
• For all practical purposes, DMA controller is a processor capable of copying data at high speed
from one location to another location.
• 8237 is a complex device. We can study its properties under two sections: DMA Channels and
DMA Signals.
DMA Channels
• 8237 has four DMA Channels: CH0 to CH3
• Two 16-bit registers are associated with each channel.
• Memory Address Register: used to load starting address of byte to be copied Count Register:
used to load the count of number of bytes to be copied.
• The address of these register are determined by four address lines A3 to A0
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
A3 A2 A1 A0 Channel Register
0 0 0 0 CH0 Memory Address Register
0 0 0 1 CH0 Count Register
0 0 1 0 CH1 Memory Address Register
0 0 1 1 CH1 Count Register
and so on.
DMA Signals
DMA signals can be divided into two groups:
i) Signals required to interface with peripheral devices ii)
Signals required to interface with MPU
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
DMA Transfer
The sequence of DMA transfer is as follows:
1. The I/O devices request the DMA controller to perform DMA transfer through DREQ (DMA
request) line.
2. The DMA controller in turn sends a request signal (HRQ) to MPU through the HOLD line.
3. The MPU finishes the current machine cycle and releases the system bus. It also
acknowledges the receiving of HOLD signal through HLDA line.
4. The DMA controller acquires control of the system bus. The DMA controller sends the DACK
signal to the peripheral I/O and the DMA transfer begins.
5. At the end of the transfer, the system bus is released by the DMA controller. The MPU takes
control of the system bus and continues the operation.
DMA Operation
The 8237 is designated to operate in two major cycles. These are called Ideal and Active cycle.
A) Idle Cycle:
o When no channel is requesting service, the 8237 will enter the idle cycle. In
this cycle the 8237 will sample DREQ lines every clock cycle to determine if
any channel is requesting DMA service. The device will also sample ,
looking for an attempt by MPU to write or read the internal register of 8237. o
When is low and HRQ is low, the 8237 enters the program condition. o
Special software commands can be executed by 8237 in program condition.
B) Active Cycle:
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
When the 8237 is in the idle cycle and channel requests a DMA service, the device
will output an HRQ to the microprocessor and enter into the active cycle. In this
cycle the DMA transfer occurs in one of the four modes: i) Single Transfer Mode ii)
Block transfer Mode iii) Demand Transfer Mode iv) Cascade
Mode
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
receives parallel data from the CPU and transmits serial data after conversion. This device also
receives serial data from the outside and transmits parallel data to the CPU after conversion.
Modem Control
The 8251A has the set of control inputs and outputs that can be used to simply interface to almost
any modem. This block has following signals-
Transmit Buffer
The Transmit Buffer accepts parallel data from the Data Bus Buffer, converts it to serial bit
stream, inserts the appropriate character or bits and outputs a serial stream of data on the
TXD output pin.
Transmit Control
The Transmit Control manages all the activities associated with the transmission of serial data.
It has following signals-
TXRDY (Transmitter Ready)
This is an output terminal which indicates that the transmitter is ready to accept a data character.
TXE(Transmitter Empty)
This is an output terminal which indicates that the 8251A has transmitted all the characters
and had no data character.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
TXC (Transmitter Clock)
The Transmitter Clock controls the rate at which the character is to be transmitted.
Receive Buffer
The Receive Buffer accepts serial data, converts this serial data to parallel format and sends
to the CPU. Serial Data is input to RXD pin.
Receive Control
This functional block manages all receiver-related activities and consists of following signals-
CONTROL WORDS
There are two types of control word.
1. Mode instruction
2. Command
1) Mode Instruction
The bit configuration of mode instruction is shown in Figures 2 and 3. In the case of
synchronous mode, it is necessary to write one-or two byte sync characters. If sync characters
were written, a function will be set because the writing of sync characters constitutes part of
mode instruction.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
2) Command
Command is used for setting the operation of the 8251A. It is possible to write a command
whenever necessary after writing a mode instruction and sync characters.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
STATUS WORD
It is possible to see the internal status of the 8251A by reading a status word. The bit configuration
of status word is shown in Fig. 5.
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
Program to add numbers input from keyboard
.model small
.stack .data .code main proc
.startup mov ah,01h int
21h sub al,30h mov bl,al
;store 1st number in bl
mov ah,01
int 21h sub
al,30h
add al,bl push al
jnc SKIP mov
dl, ‘1’ mov ah,02h
int
21h
SKIP: pop al add
al,30h
mov dl,al
mov ah,02h
int 21h
.exit
main endp
end main
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
fantastic$' string3 db ? .code
main proc
.startup
mov di,offset string3
mov si,offset string1 mov
cx,14
AGAIN1:
mov bx,[si]
mov [di],bx
inc si
inc di
loop AGAIN1
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
.code
main proc
.startup mov
dx,offset msg1
mov ah,09h
int 21h
AGAIN:
mov ah,01h
int 21h
mov val,al mov bl,[si]
cmp val,bl jne SKIP
; jump if not equal
inc
bh
SKIP:
inc
si
loop
AGAIN
cmp
bh,5
jne
INVAL
ID
mov
dx,of
fset
msg2
mov
ah,09
h
int
21h
jmp
EXIT
INVALID:
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
mov dx,offset msg3
mov
ah,09h
int 21h
EXIT:
.exit
main endp end
main
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
.code
main proc
.startup
mov dx,offset name1
mov ah,09h
int 21h mov
dx,offset name2
mov ah,09h
int 21h
.exit
main endp
end main
UPPERCASE:
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
sub [si],20h ;note: to change UPPERCASE into lowercase add 20h
mov dl,[si] mov ah,02h int 21h
inc si loop UPPERCASE
.exit
main endp end
main
.model small
.stack .data
num1 db 32
num2 db 51
.code
main proc
.startup mov
al, num1 mov
ah, num2 add
al, ah aam
add ax, 3030h
mov
bl,al
mov dl,ah
mov
ah,02h
int 21h
mov dl,bl
mov
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
ah,02h
int 21h
.exit
main endp
end main
AGAIN: mov
ah, 01h
int 21h
mov [si],
al inc si
loop AGAIN
mov cx, len
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
REPEAT:
mov dl,
[si] mov
ah, 02h
int 21h
dec si
loop REPEAT
.exit
main endp
end main
.model small
.stack .data
num db 32h
.code
main proc
.startup
mov al, num
mov ah, 0
aam add
ax, 3030h
mov bl,al
mov dl,ah
mov ah,02h
int 21h
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
mov dl,bl
mov ah,02h
int 21h
.exit
main endp
end main
.model small
.stack .data
string db
'microprocessor$'
.code main proc .startup
mov bh,0 ; to count no. of vowels
mov cx,14 ; length of string
mov si,offset string
AGAIN:
mov al,[si]
cmp
al, ‘a’
je COUNT ; jump if equal
cmp
al, ‘e’
je COUNT ; jump if equal
cmp
al, ‘i’
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
je COUNT ; jump if equal
COUNT: inc bl
SKIP: inc si
loop AGAIN
.model small
.stack
.data
string db ‘Enter two digit
Number:$’ num db ? .code
main proc
.startup
mov cx, 10 ;multiplier of 10
mov dx, offset string mov
ah, 09h int 21h mov
ah, 01h int 21h sub al,
30h mov ah, 0 mul cx
;multiplies ax by cx push
ax ;save result mov ah,
01h int 21h sub al, 30h
mov bl, al mov bh, 0 pop
ax add ax, bx
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]
.exit
main endp end
main
Nepal Engineering College, Microprocessors, Compiled by: Asst. Prof. Ramesh Kumar Pudasaini,
rameshkp@[Link]