8085 Microrprocessor Lecture Note
8085 Microrprocessor Lecture Note
Chapter one
Definition
A microprocessor is a multipurpose, programmable, clock driven, register based electronics
device that reads binary instructions from a storage device called memory, accepts binary data as
input and processes data according to those instructions, and provides results as output.
Application area
Microprocessor is a general purpose electronic device. It is used for monitoring and controlling
electronic devises. Some of the application areas are listed below:
The shift register may transfer data from the accumulator to the bus by either shifting it right or
left, or transfer it directly.
The temporary register is used to hold bus data to or from the ALU and the status register.
Accumulator is an 8-bit register used for arithmetic, logic, I/O and load/store operations. This
register is used to store 8-bit data and to perform arithmetic and logical operations. The result of
an operation is stored in the accumulator. The accumulator is also identified as register A.
Basic function of the ALU is to perform the following arithmetic and logic operations:
Status register
The status (condition) of contents of the accumulator is indicated by 5 flip-flops. The five flags
that indicate the status of the accumulator are shown in the fig. below.
S Z X AC X P X C
The letter X in the status flags indicates “do n’t “care conditions and these bits are used
internally. These status flags are named as:
- Zero (Z)
- Sign (S)
- Parity (P)
- Carry (C)
- Auxiliary carry (AC)
N.B. The flags and accumulator together is called program status word (PSW).
The flags are SET (ON=1) or RESET (OFF=0) as a result of operations such as addition,
subtraction etc.
60H
Zero flag
This flag indicates that the result of any operation in the accumulator is zero. If the contents in
the accumulator is zero, this flag is SET (ON=1) otherwise RESET (OFF=0).
Example: Add FFH and 01H
FFH
+01H
-----------------
1 00H
The result in the accumulator is zero. Therefore, Z=1.
0FH
+3AH 0 0 0 0 1 1 1 1
--------------- 0 0 1 1 1 0 1 0
49H 0 1 0 0 1 0 0 1
Parity Flag (P)
This flag indicates whether the total number of 1’s in the accumulator after execution of any
program is odd or even. If the total number of 1’s in the accumulator after execution is even, P=1
and if the number of 1’s is odd, P=0.
Example: Add 60H and 3AH
60H 01100000
+3AH 00111010
------------------ ---------------------
9AH 10011010
The total number of 1’s present in this operation is 4. Hence parity is even. i.e. parity flag will be
SET (ON = 1).
A (8)
Flag Register
B (8) C (8)
D (8) E (8)
E (8) L (8)
SP (Stack Pointer)
PC (Program Counter)
Fig. 1.3 Registers of 8085
Program Counter
This 16-bit register deals with sequencing the execution of instructions. This register is a
memory pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit
register.
The function of the program counter is to point to the memory address from which the next byte
is to be fetched. When a byte (machine code) is being fetched, the program counter is
incremented by one to point to the next memory location. Branching is implemented by making
changes to the program counter (for example, Jump instruction).
Address Bus
Address bus carries address. The address bus consists of 16 wires. That is its width is 16 bit -
wide. Address bus is unidirectional, the numbers are only sent from microprocessor to memory
or ports not the other way. Using this address, 8085 microprocessor can access 64K byte of
memory.
Data Bus
Data Bus carries data in binary form between microprocessor and other external units, such as
memory. The data bus typically consists of 8 wires and is bidirectional. The data bus also carries
instructions from memory to the microprocessor. Therefore, the size of the bus limits the number
of possible instructions to 256.
Control Bus
Control Bus is various lines which have specific functions for coordinating and controlling uP
operations. Eg: Read/Not Write line, single binary digit. Control whether memory is being
‘written to’ (data stored in mem) or ‘read from’ (data taken out of mem) 1 = Read, 0 = Write.
May also include clock line(s) for timing/synchronizing, ‘interrupts’, ‘reset’ etc.
The Control Bus carries control signals partly unidirectional, partly bi-directional. Control
signals are things like "read or write". This tells memory that we are either reading from a
location or writing to a location specified.
Memory
Program, data and stack memories occupy the same memory space. The total addressable
memory size in Intel 8085 microprocessor is 64 KB.
Program memory - program can be located anywhere in memory. Jump, branch and call
instructions can be used to jump/branch anywhere within 64 KB.
Data memory - the processor always uses 16-bit addresses so that data can be placed anywhere.
Stack memory is limited only by the size of memory. Stack grows downward.
Pin Description
The following describes the function of each pin:
ALE (Output)
Address Latch Enable: It occurs during the first clock cycle of a machine state and enables the
address to get latched into the on chip latch of peripherals. The falling edge of ALE is set to
guarantee setup and hold times for the address information.
RD (Output tri-state)
READ; indicates the selected memory or I/O device is to be read and that the Data Bus is
available for the data transfer.
WR (Output tri-state)
WRITE; indicates the data on the Data Bus is to be written into the selected memory or I/0
locations. Data is set up at the trailing edge of WR. 3 stated during Hold and Halt modes.
READY (Input)
If Ready is high during a read or write cycle, it indicates that the memory or peripheral is ready
to send or receive data. If Ready is low, the CPU will wait for Ready to go high before
completing the read or write cycle.
HOLD (Input)
HOLD; indicates that another Master is requesting the use of the Address and Data Buses. The
CPU, upon receiving the Hold request, will relinquish the use of buses as soon as the completion
of the current machine cycle. Internal processing can continue.
The processor can regain the buses only after the Hold is removed. When the Hold is
acknowledged, the Address, Data, RD, WR, and IO/M lines are 3stated.
HLDA (Output)
HOLD ACKNOWLEDGE; indicates that the CPU has received the Hold request and that it will
relinquish the buses in the next clock cycle. HLDA goes low after the Hold request is removed.
The CPU takes the buses one half clock cycles after HLDA goes low.
Interrupts
The processor has 5 interrupts. They are presented below in the order of their priority (from
lowest to highest):
INTR (Input)
INTERRUPT REQUEST; is used as a general purpose interrupt. It is sampled only during the
next to the last clock cycle of the instruction. If it is active, the Program Counter (PC) will be
inhibited from incrementing and an INTA will be issued. INTR is maskable interrupt. When the
interrupt occurs, the processor usually fetches one of these instructions:
8 RST instructions (RST0 - RST7). The processor saves current program counter into
and branches to memory location N * 8 (where N is a 3-bit number from 0 to 7
supplied with the instruction).
CALL instruction (3 byte instruction). The processor calls the subroutine, address of
which is specified the second and third bytes of the instruction.
INTA (Output)
INTERRUPT ACKNOWLEDGE; is used instead of (and has the same timing as) RD during the
Instruction cycle after an INTR is accepted. It can be used to activate the 8259 Interrupt chip or
some other interrupt port.
RST5.5 (Input) is a maskable interrupt. When this interrupt is received the processor saves the
contents of the register into stack and branches to 2Ch (hexadecimal) address.
RST6.5 (Input) is a maskable interrupt. When this interrupt is received the processor saves the
contents of the register into stack and branches to 34h (hexadecimal) address.
RST7.5 (Input) is a maskable interrupt. When this interrupt is received the processor saves the
contents of the register into stack and branches to 3Ch (hexadecimal) address.
Trap is a non-maskable interrupt. When this interrupt is received the processor saves the
contents of the register into stack and branches to 24h (hexadecimal) address.
Related links
All maskable interrupts can be enabled or disabled using EI and DI instructions. RST 5.5,
RST6.5 and RST7.5 interrupts can be enabled or disabled individually using SIM instruction.
RESET IN (Input)
Reset sets the Program Counter to zero and resets the Interrupt Enable, HLDA flip flops flags
and registers (except the instruction register) are affected. The CPU is held in the reset condition
as long as Reset is applied.
X1, X2 (Input)
X0 and X1 are inputs from the crystal or clock generating circuit. The frequency is internally
divided by 2. So, to run the microprocessor at 3 MHz, a clock running at 6 MHz should be
connected to the X0 and X1 pins.
CLK (Output)
CLK pin is an output clock line to drive the clock of the rest of the system.
IO/M (Output)
IO/M indicates whether the Read/Write is to memory or I/O during Hold and Halt modes.
SID (Input)
Serial input data line. The data on this line is loaded into accumulator bit 7 whenever a RIM
instruction is executed.
SOD (output)
Serial output data line. The output SOD is set or reset as specified by the SIM instruction.
An instruction can be written in a variety of forms. We write instructions using their mnemonic
codes and symbolic address. However a microprocessor can decode and execute only binary
coded instruction. Therefore, for each operation that can be executed by a microprocessor, there
is a binary code.
Rotate- Each bit in the accumulator can be shifted either left or right to the
next position.
Compare- Any 8-bit number or the contents of a register, or a memory can be
compared for equality, greater than, or less than, with the contents of the
accumulator.
Complement - The contents of the accumulator can be complemented. All 0s
are replaced by 1s and all 1s are replaced by 0s.
Control transfer -This group of instructions alters the sequence of program execution
either conditionally or unconditionally.
Jump - Conditional jumps are an important aspect of the decision-making process in
the programming. These instructions test for a certain conditions (e.g., Zero or Carry
flag) and alter the program sequence when the condition is met. In addition, the
instruction set includes an instruction called unconditional jump, Call, Return, and
Restart.
Other - setting/clearing flag bits, enabling/disabling interrupts, stack operations, etc.
Machine Language
A machine language program is written using binary codes and addresses. A microprocessor
only understands machine language programs. Machine language coding is time-consuming and
error-prone. Usually machine language programmers are concerned with hardware details. Every
computer or family of computers has its own machine language; each is machine-dependent
Compilers convert a finished program (or section of a program) into object code. This is often
done in steps. Some compilers convert high level language instructions into assembly language
instructions and then an assembler is used to create the finished object code.
Interpreters convert each high level instruction into a series of machine instructions and then
immediately run (or execute) those instructions. In some cases, the interpreter has a library of
routines and looks up the correct routine from the library to handle each high level instruction.
Assembler is a program that translates an assembly language program from mnemonics to the
binary machine code. i.e. Converts assembly language programs into object files.
• Object files contain a combination of machine instructions, data, and information needed to
place instructions properly in memory
• Assemblers need to
– translate assembly instructions and pseudo-instructions into machine instructions
– Convert decimal numbers, etc. specified by programmer into binary
Linker
Tool that merges the object files produced by separate compilation or assembly and creates an
executable file.
Loader
Part of the OS that brings an executable file residing on disk into memory and starts it running
• Steps
– Read executable file’s header to determine the size of text and data segments
– Create a new address space for the program
– Copies instructions and data into address space
– Copies arguments passed to the program on the stack
– Initializes the machine registers including the stack ptr
– Jumps to a startup routine that copies the program’s arguments from the stack to
registers and calls the program’s main routine.
Chapter Two
One of the primary functions of the microprocessor is copying data from a register (or IO or
memory) called the source to another register (or IO or memory) called the destination.
Sources and Destination can be Registers, Memory and Devices. I.e. data transfer can take place
between:
1. Registers [from one Register to another]
2. Specific data byte to a register or a memory location
3. Memory a memory location and a register
4. An IO device and the accumulator
MOV A, B; AB
MOV D, L; DL
MOV H, E; HE
MOV A, C; AC
MOV L, H; LH
Specify the content of registers and the flags as the following instructions are executed.
A B C D S P Z C
MVI A, FFH
MVI B, 58H
MOV C, A
MOV D, B
HLT
Answer
Mnemonics A B C D S-Flag P-Flag Z-Flag C-Flag
MVI A, FFH XX XX XX X X X X
FFH
HLT
Load Accumulator
Table 3 LDA Instruction
Example: LDA 2034H; the byte value found in 2034H is copied to register A. Assume the value
at the memory address 2034H is B6H. When the processor executes the above instruction, B6H
will be loaded into Accumulator register. I.e. A<= B6H. The content of the memory location is
not altered.
Memory Byte
Location value
2035H XX
2034H B6H
2033H XX
Example-2: Specify the content of register A after the following instruction is being executed.
Assume the byte value at memory location 33FEH is 90H.
MVI B, BDH
MOV A, B
LDA 33FEH
HLT
Memory Byte
location value
3401H 10H
3400H 32A
33FFH 5AH
33FEH 90H
33FDH 00H
Answer
Mnemonics A B
HLT
LDAX B/D register pair None The contents of the designated register pair point to a
memory location. This instruction copies the
contents of that memory location into the
accumulator. The contents of either the register pair
or the memory location are not altered.
Example-1: LDAX B; byte value pointed by register pair BC is copied to register A. BC holds
the 16-bit address. Assume BH holds 4567H. The processor will load accumulator with the value
in this memory location.
Memory Byte
location value
4569H 01H
4568H 23A
4567H 66H
4566H 4FH
4565h CCH
After the microprocessor executes the instruction register A will contain 66H.
Example-2: Specify the content of register A after the following instruction is being executed.
Assume the byte value at memory location F000H is 44H. BC=F000H.
MVI B, F0H
MVI C, 00H
MOV A, B
LDAX B
HLT
Memory Byte
location value
F002H 10H
F001H 32A
F000H 5AH
EFFFH 90H
EFFEH 00H
Answer
Mnemonics A B
HLT
The second byte is loaded in the higher order register example register B or D and the third byte
is loaded in the lower order register.
Example-1: LXI H, 2034H; loads 20 in register H and 34 in register L
LXI B, 8B0FH; loads 8B in register B and 0F in register C
Example-2: Write a program that loads the value pointed by the 16-bit address value in the
register pair HL to the accumulator register. Assume the value in the register pair HL is 5468H.
LXI H, 5468H;
LDAX H
HLT
Example-1: LHLD 2040H; loads the byte value pointed by 2040H into register L and the byte
value found in 2041H into register H.
Answer
L<= [2040H]
H<= [2041H]
Example-2: Assume memory location 8000H contains 20H and 8001 contains FEH. Write a
program that transfers content of memory location 8000H to L and 8001H to H.
Answer
LHLD 8000H
Address Memory
Content Content of register pair HL after the above instruction is being
7FFFH xx executing
8000H 20H Register H Register L
8001H FEH
8002H YY FEH 20H
Example-1: MVI A, 33
STA 8050H; stores the byte value of the accumulator in memory location pointed by
4050H.
8051H XX 8051H XX
Table 11: STAX Instruction
Example-1: LXI B, 800FH, STAX B; stores the byte value of the accumulator in memory
location pointed by content of the register pair BC.
8010H XX 8010H XX
Example-1: LXI H, 1122H, SHLD 2470H; stores the byte in register L in memory location
2470H and content of register H in 2471H.
As an example, data generated at a certain point in a program may be needed later in the
program. This data is stored in the stack and retrieved when needed. Because the number of
general purpose registers (GPRs) in a microprocessor is limited–hence not all the temporary data
can be stored in them and this is where the stack plays its part.
The stack is initialized by a 16-bit register, called the stack pointer (SP) register. But initialization
is not a must. If for programs for which any temporary data that are generated can be stored in
GPRs and which don’t require subroutine calls, there is no need to initialize the stack by the SP.
The stack is used by programmer and a system. Programmer uses the stack for storage/retrieval
of data by using the PUSH/POP instructions respectively. On the other hand, the system uses the
stack to store return address whenever subroutine CALL is used.
Stack Initialization
LXI SP, 4400 H; loads the stack pointer with 4400 H so that it points at the memory address
4400 H.
In most of the cases the stack pointer is initialized by direct way, but method (b) is sometimes
used when one wants to set the stack pointer by means of programming.
Stack is a ‘last-in first-out’ or LIFO type of memory. This means that data which is pushed last
into stack is popped out of it first.
Example-1: PUSH B
PUSH PSW
Example-2: Assuming the stack pointer SP=1234H, A=55H, Flag Register= 88H, BC= A04FH,
DE= B0A2H and HL = 5089H. Show the contents of the stack as each of the following
instructions is executed.
PUSH PSW
PUSH B
PUSH D
PUSH H
Example-1: POP H
POP PSW
Example-2: Assuming the stack pointer SP=122DH and Content of a stack is as shown below.
Show the contents of the stack and registers as each of the following instructions is executed.
Example-1: Assuming stack value at A09CH is 44H and at A09BH is A0H; specify the content
of register pair HL and stack values at memory locations A09CH and A09BH after the following
instruction is being executed.
a) Specify the contents of the accumulator when the instruction IN 4FH is executed.
b) Specify the output at port 03H and the contents of register D after executing the
instructions.
MVI B, 00H
MVI A, 99H
IN 4FH
MOV D, A
OUT 03H
HLT
Answer:
a) 08H
b) 08H
Arithmetic Operations
The 8085 microprocessor performs various arithmetic operations, such as addition, subtraction,
increment and decrement. Addition and subtraction operations are performed in relation to the
contents of the accumulator. However, the increment and decrement operations can be performed
in any operand (register or memory).
Addition
The 8085 microprocessor performs addition with 8-bit binary numbers and stores the sum in the
accumulator. Addition can be performed either by adding the contents of a source register or
memory to the contents of the accumulator or a byte value directly to the contents of the
accumulator.
4. Add the content of registers C and D and display the sum at port 89H
Answer
Answer:
LDA 997EH
LXI H, 997FH
ADD M
ACI 45H
HLT
Example-1: Specify the contents of the registers H, L, D and E when the following program is
being executed.
Answer
Mnemonics D E H L
LXI H, 5066H XX XX 50H 66H
LXI D, 4031H 40H 31H 50H 66H
DAD D 40H 31H 90H 97H
HLT
Example-2: Write an 8085 assembly language program that multiply content of register pair HL
by 2.
Answer: LXI H, 16 bit value
DAD H
HLT
Subtraction
The 8085 microprocessor performs subtraction by using the method of 2’s complement. The
value in accumulator register is regarded as the minuend (the number from which to subtract).
The 8085 microprocessor performs the following steps internally to execute subtraction
instruction.
Example-1: Register D has 89H and the accumulator has F2H. Write a program that subtracts
the contents of register D from the contents of the accumulator.
Answer
MVI D, 89H
MVI A, F2H
SUB D
HLT
Example-2: Write an 8085 assembly language program that performs the following functions:
1. Load the number 72H in register C and 96H in register B
2. Subtract 96H from 72H
3. Display the answer at port address 8FH
Answer:
MVI C, 72H
MVI B, 96H
MOV A, C
SUB B
OUT 8FH
HLT
Example-3: Write instructions to add the contents of the memory location 8090H to
accumulator, and subtract the contents of the memory location 8091H from the sum. Assume the
accumulator has 40H, the memory location 8090h has 4AH and the location 8091H has F7H.
Answer
MVI A, 40H
LXI H, 8090H
ADD M
MOV B, A
LDA 8091H
MOV C, A
MOV A, B
SUB C
HLT
LXI B, F000H
LDAX
SUI 45H
HLT
MVI A, 30H
SUI 45H
SBI 01H
HLT
Example-1: Assume byte value at memory location 909FH is 00H and at memory location
90A0H is FFH. What is the content of register B when MOV B, M instruction is being executed?
LXI H, 909FH
INX H
MOV B, M
HLT
Answer: B=FFH
Example-2: Write the instruction to load the number 5020H in the register pair BC. Increment
the number using the instruction INX B and illustrate whether the INX B is equivalent to the
instructions INR B and INR C.
Answer
LXI B, 5020H
INX B
HLT
After the above instruction has been executed register pair BC will contain 5021H.
LXI B, 5020H
INR B
INR C
HLT
Register pair BC will hold 5121H.
MVI C, 00H
MOV B, C
DCR B
MOV C, B
HLT
Example-2: Write instructions that load 40H in memory location 8091H, and decrement the
contents of the memory location 8091H.
Answer:
LXI B 8091H
MVI A, 40H
STAX B
LXI H, 8091H
DCR M
HLT
Example:
LXI H, 9A70H
DCX H
HLT
Contents of register pair HL after the above instructions have been executed is 9A6FH.
Example: obtain the value after DAA instruction is executed on the following additions.
Answer
a) 08 in decimal
b) 15 in binary coded decimal
c) 13 in binary coded decimal
BCD Subtraction
When subtracting two BCD numbers, the instruction DAA cannot be used to decimal adjust the
result of two packed BCD numbers. The DAA instruction applies only to addition. Therefore, it
is necessary to device a procedure to subtract two BCD numbers. Two BCD numbers can be
subtracted using the procedure of 100’s complements.
To subtract two BCD numbers, in short add 100’s complement of the subtrahend to a minuend
and then adjust it using DAA instruction.
MOV B, 90H
MOV C, 01H
MVI A, 99H
SUB C, Find 99’s complement of Subtrahend
INR A, Find 100’s complement of subtrahend
ADD B, Add minuend to 100’s complement of subtrahend
DAA, Adjust for BCD
HLT
BRANCHING INSTRUCTIONS
Jump instructions
Jump Unconditionally
The unconditional jump instruction is a 3-byte instruction with the first byte containing the
Opcode and the second and the third bytes containing the address. When the unconditional jump
instruction is executed, the second and the third address bytes are loaded in the PC counter. The
microprocessor will fetch next instruction from the memory at the new address.
Example-1: Identify the memory locations that are cleared by the following instructions:
MVI B, 00H
LXI H, 9005H
JMP XXXX
MOV M, B
XXXX: INX H
MOV M, B
INX H
INX H
MOV M, B
HLT
Jump conditionally
All conditional jump instructions are three byte instructions. The program sequence is transferred
to the memory location specified by the 16-bit address given in the operand based on the
specified flag of the PSW as described below. I.e. conditional jump instructions are executed if
the specified condition is satisfied or otherwise control proceeds in the sequence.
Example-1 Write an assembly language program to add N byte binary numbers stored from
location X+1, where N is stored at location X. Store the result in location Y and Y+1.
Store the program starting from F000H
Store the count at location F100H
Answer
LXI H, F000H
MOV C, M
MVI B, 00H
MVI A, 00H
YYYY: INX H
ADD M
JNC XXXX
INR B
XXXX: DCR C
JNZ YYYY
STA F200H
STA F201H
HLT
Example-1: Write an assembly language program to find the product of two unsigned binary
numbers stored at location X and X+1 using successive addition.
Answer
LXI D, F101H
LDAX D
INX D
MOV C, A
LDAX D
MVI E, 00H
MOV B, A
SUB A
YYYY: ADD B
JNC XXXX
INR E
XXXX: DCR C
JNZ YYYY
STA F103H
MOV A, E
STA F104H
HLT
Example-3: Explain how many times the following loop will be executed.
MVI B, 02H
MVI A, FCH
XXXX: ADD B
JC XXXX
STA 809FH
HLT
Example-4: The following instructions are intended to clear five memory locations starting from
memory location F00AH. Explain why a large memory block will be cleared.
LXI H, F00AH
YYYY: MVI B, 04H
MVI M, 00H
INX H
DCR B
JNZ YYYY
LOGICAL INSTRUCTIONS
Compare instructions
The 8085 instruction set has two types of compare operations: CMP and CPI.
CMP: Compare with accumulator
CPI: Compare immediate value with accumulator
The microprocessor compares a data byte (memory or register value) with the contents of the
accumulator by subtracting the data from A, and indicates whether the data byte is <, >, or = by
modifying the flags. However the contents are not modified.
Example-1: 20 values are stored in memory locations starting at F00FH. Write an 8085 ALP that stores
value between 30H and 45H exclusive starting at F100H.
Answer
MVI C, 14H
LXI H, F00FH
LXI D, F100H
Again: MVI A, 30H
CPM M
JNC NXT
MVI A, 45H
JNC NXT
MOV A, M
STAX D
INX D
NXT: INX H
DCR C
JNZ Again
HLT
Example-1: A set of current readings is stored in memory locations starting at F000H. The end
of the data byte is indicated by the data 00H. Add the set of readings. The result may be larger
than FFH. Write a program that displays the entire sum at port addresses F1H and F2H.
LXI H, F000H
SUB A
MOV B, A
MOV C, B
NXTR: MOV A, M
CPI 00H
JZ display
ADD B
JC NXT
INR C
NXT: MOV B, A
INX H
JMP NXTR
Display: MOV A, B
OUT F1H
MOV A, C
OUT F2H
HLT
Example-1:
MVI B, 00H
MOV A, B
ANI FFH
HLT
Example-1: What operations can be performed by using the instruction XRA A? Specify the
status of Z and CY flags.
XRA A will clear contents of register A. I.e. A=00H. Z = 1 and CY = 0
Example-1: Identify the contents of the accumulator and the flag status as the following instructions are
executed.
A S Z CY
MVI A, 82H 82H X X X
ORA A 82H 1 0 0
CPI B3H 82H 1 0 1
HLT
Example-2: Explain the type of the number that can be displayed at the output port 00H.
LXI H, 9000H
MVI C, 20H
NXT: MOV A, M
ORA A
JP Display
XRA A
Display: OUT 00H
INX H
DCR C
JNZ NXT
HLT
Example-1: Write an 8085 ALP that reads the switch connected to port address FFH continuously, set
D6, D2 and D1 of the readings and display it at port address 50H.
NXT: IN FFH
ORI 46H
OUT 50H
JMP NXT
HLT
Example-1: Explain the mathematical function that is performed by the following instructions.
MVI B, 05H; Load five into register B
MOV A, B; Copy the value in B to A
RLC ; Rotate left through carry once: - A contains 0AH
MOV B, A; Copy the value contained in A to B
RLC ; Rotate left through carry once: A contains 14H
RLC ; Rotate left through carry once: A contains 28H
ADD B ; add 28H and 0AH: A=32H which is 50 in decimal
HLT
Therefore, the mathematical function of the above segment of codes is multiplying by 10 the value
initially contained in register B.
Example-1: Assume the accumulator contents are AAH and carry flag=0. Illustrate the accumulator
contents after the execution of RRC instruction twice.
Answer
A= 10101010 in binary and CY=X
RRC
A=01010101, CY =0
RRC
A=10101010, CY =1
Example-1: Assume the accumulator contents are AAH and CY =0. Illustrate the accumulator
contents after the execution of the instruction RAL twice.
Answer
A=10101010, CY =0
RAL
A=01010100, CY =1
RAL
A=10101001, CY=0
Example-1: Identify the contents of register A after the last RAR instruction is being executed.
MVI A, 81H
STC
RAR
CMC
RAR
HLT
Answer
A=10000001, CY=1
RAR
A=11000000, CY=1
CMC
A=11000000, CY=0
RAR
A=01100000, CY=0
Complement accumulator
Opcode Operand Flag affected Description
CMA None No flags are affected. The contents of the accumulator are complemented.
Example-1:
MVI A, 55H
CMA
ADD 55H
HLT
Complement carry
Opcode Operand Flag affected Description
CMC None Carry flag is affected. No other flags The Carry flag is complemented.
are affected.
Example-1:
MVI FEH
ADI 02H
CMC
RAL
HLT
Set Carry
Opcode Operand Flag affected Description
STC None The Carry flag is set to 1. No other Set carry flag to 1.
flags are affected.
No Operation
Example-1
MVI C, FFH
NXT: NOP
DCR C
JNZ NXT
HLT
Halt
Example: HLT
Disable interrupts
Example: DI
Enable interrupts
Example: EI
1. Immediate Addressing
2. Direct Addressing
3. Register Addressing
4. Register Indirect Addressing
5. Inherent or Implied Addressing
In this addressing mode, the operand resides in the memory address directly specified as part of
the instruction. Instructions included under a direct addressing mode require three bytes of
storage: one for the instruction code, and two for the 16-bit address.
Example: Jump instructions include a 16-bit address as part of the instruction. For example, the
instruction JMP 1000H causes a jump to the hexadecimal address 1000 by replacing the current
contents of the program counter with the new value 1000H.
Example-2:
LDA F00FH
STA F000H
Example-1: The instruction MOV M, C moves the contents of the C register into the memory
address stored in the H and L register pair.
Example-2: The instruction LDAX B loads the accumulator with the byte of data specified by
the address in the B and C register pair.
Immediate Addressing
Instructions that use immediate addressing have data assembled as a part of the instruction itself.
Example-1: The instruction CPI 46H may be interpreted as ‘compare the contents of the
accumulator with the 46H. When assembled, this instruction has the hexadecimal value FE43.
Hexadecimal 43 is the internal representation for the letter C. When this instruction is executed,
the processor fetches the first instruction byte and determines that it must fetch one more byte.
The processor fetches the next byte into one of its internal registers and then performs the
compare operation. Notice that the names of the immediate instructions indicate that they use
immediate data.
Example-2: The MVI (move immediate) instruction can move its immediate data to any of the
working registers including the accumulator or to memory. Thus, the instruction MVI D, OFFH
moves the hexadecimal value FF to the D register.
Example-3: The LXI instruction (load register pair immediate) is even more unusual in that its
immediate data is a 16-bit value. This instruction is commonly used to load addresses into a
register pair. As mentioned previously, your program must initialize the stack pointer; LXI is the
instruction most commonly used for this purpose. The instruction LXI SP, 3OFFH loads the
stack pointer with the hexadecimal value 30FF.
Subroutine
A subroutine is a group of instructions written separately from the main program to perform a
function that occurs repeatedly in the main program.
Example-1:
MVI A, 80H
OUT CWR
MVI A, 01H
OUT PORT A
LXI H, FFFFH
XX : DCX H
MOV A, L
ORA H
JNZ XX
MVI A, 02H
OUT PORT A
LXI H, FFFFH
XY: DCX H
MOV A, L
ORA H
JNZ XY
MVI A, 03H
OUT PORT A
LXI H, FFFFH
YX: DCX H
MOV A, L
ORA H
JNZ YX
HLT
The following segment of code is repeated three times. Therefore, subroutine is used to avoid
such type repetition.
LXI H, FFFFH
TT: DCX H
MOV A, L
ORA H
JNZ TT
8085 uses two unconditional branching instructions to implement subroutine: CALL and RET
instructions.
Example-2: illustrate the exchange of information between the stack and the program counter for
the following program if the available user memory ranges from 2000H to 23FFH.
When the processor encounters the CALL 2070H, the processor automatically pushes 20H and
43H in 23FFH and 23FEH respectively. PC will hold 2070H. At the end of the subroutine the
processor will execute RET instruction and pops the value on top of the stack to the PC counter
and continue executing the instructions in the main program.
3. Loads the 16-bit address operand which is available in the CALL instruction to the PC ( Program
Counter)
5. At the end of the subroutine execution, a single instruction tells the microprocessor original
contents of the PC (Program Counter)
The conditional call and return instructions are based on-four flag conditions: Carry, Zero, sign and parity
flags. The condition is tested by checking the respective flags.
Call conditionally
All conditional call instructions are three byte instruction and have a 16-bit address operand.
The program sequence is transferred to the memory location specified by the 16-bit address given in the
operand based on the specified flag of the PSW as described below. Before the transfer, the address of the
next instruction after the call (the contents of the program counter) is pushed onto the stack.
Example: RZ
Solution:
Types of Subroutine
1. Multiple-calling of a subroutine
Subroutines are normally called more than once by the main program. Calling a subroutine more than
once by the main program is called multiple calling of a subroutine.
2. Nesting of subroutines
The process of a subroutine calling a second subroutine and the second subroutine in its turn
calling a third one and so on is called nesting of subroutines.
Theoretically speaking, the number of subroutines that can be called by this process is infinite
but, in practice it is limited by the size of memory.
Re-entrant subroutine
In nested subroutines, many subroutines are there. In such a case, if a latter subroutine
calls an earlier one, then it is known as re-entrant subroutine. As an example, say a main
program has two subroutines. The main program calls subroutine 1, then subroutine 1
calls subroutine 2. If now subroutine 1 is called from subroutine 2, then this falls under the
category of re-entrant subroutines.
Recursive subroutine
A recursive subroutine is a subroutine which is called by itself and is used with complex data
structures, known as ‘trees. For the flow diagram shown, if the subroutine is called with n = 4
(known as ‘recursive depth’), then until n becomes 0 it will stay within the recursive subroutine.
If n _ 0
Decrement n
Call SR recursive
else
return.
Multiple ending subroutine is a subroutine that has one or more conditional return
instruction and one unconditional return instruction.
There are two methods of ending a subroutine—multiple ending and common ending. The
example of each type follows:
Example: Write an 8085 ALP that converts 32 ASCII characters available starting at 9000H
memory location to their binary equivalent. Write the converter function outside the main
program.
Answer:
LXI H, 9000H
MVI C, 10H
NXT: MOV A, M
CALL TTYY
INX H
DCR C
JNZ NXT
HLT
Parameter passing
Subroutines are scattered at many places in the memory and that they may be called from
different locations in the main program. In such cases, various types of information/data re
exchanged between the main program and the subroutine. This ‘passing’ of data/address
variable is referred to as passing parameters to the subroutine.
There are four ways in which this ‘passing’ can be done, as mentioned below:
Time Delay
A register is loaded with a number depending on the time delay required, and then the register is
decremented until it reaches zero by setting up a loop with a conditional jump instruction. The
loop causes the delay, depending upon the clock period of the system.
Answer
Given: Clock frequency of the system= 2MHz
T-states (Clock periods) = 7
T=1/2MHz=0.5µ second
Time to execute MVI= 7*0.5µ second= 3.5µ seconds
Important points
Every instruction requires some time to be executed. The amount of time is not constant.
It varies from instruction to instruction. The time required to execute each instruction is
referred as T-states or Clock periods.
Execution of instruction depends on the speed (clock frequency) of the microprocessor.
Execution time is small for processor with large clock frequency and vise versa.\
Example-2: Calculate the time required to execute the following segment of codes on
8085 microprocessor with clock frequency 4MHz. assume the value at memory location
899FH is BCH.
T-state required
MVI B, 34H 7
MOV A, B 4
LXI H,899FH 10
ADD M 7
JC NXT 7 if condition is not true
MVI A, 00H Otherwise 10
OUT FFH 10
MVI A, 01H 7
NXT:OUT FFH 10
HLT 5
Example-3: Calculate the time required to execute the following functions. Clock frequency=
4MHZ.
T-state required
LXI B, 0064H 10
Nxt: DCX B 6
MOV A, B 4
ORA C 4
JNZ NXT 7 if condition is not true
HLT Otherwise 10
5
Answer
T=1/F=1/4MHz=0.25 µs
T-states outside the loop = 15
T-sates inside the loop = 24 for 99 times and 21 for one times
Time required to executed instructions outside the loop = 15 * 0.25 µs = 3.75µs
Time required to executed instructions inside the loop = (24 * 99+21) *0.25µs=599.25µs
Total time = 599.25µs + 3.75µs = 603µs
Example-4: Calculate the time required to execute the following segment of codes on a processor
with clock frequency of 2MHz.
T-state required
MVI D, 38H 7
NXT1: MVI B, FFH 7
NXT2: DCR B 4
JNZ NXT2 10/7
DCR D 4
JNZ NXT1 10/7
HLT 5
Answer
Inner loop is controlled by register B
Outer loop is controlled by register C
T=1/2MHz = 0.5µs
Time delay for the inner loop
Inner loop is executed 255 times
T-inner = 255*14*0.5µs – 3*0.5µs = 1785µs – 1.5µs = 1783.5µs
Time delay for the outer loop
Inner loop is executed 56 times
T-outer= 56 *(1783.5µs + 0.5µs*21) – 3*0.5µs= 100464µs-1.5µs=100462.5µs
Time required executing instructions outside the loop
12*0.5µs = 6µs
Total time = 6µs + 100462.5µs= 100468.5µs= 100.469ms
Example-5: Calculate the execution time required to execute the following instructions:
T-state required
LXI B, 12FFH 10
NXT: DCX B 6
XTHL 16
XTHL 16
NOP 4
NOP 4
MOV A, C 4
ORA B 4
Example-6: Calculate the count value to be loaded on register B to obtain a 94.5µs delay on a
processor with 2MHz. [Express the value in hexadecimal]
T-state required
MVI B, count 7
NXT: NOP 4
NOP 4
NOP 4
NOP 4
DCR B 4
JNZ NXT 10/7
HLT 5
Answer
Time delay = No T-states *count*period + No T-states outside the loop*period
94.5µs= 30*Count*0.5µs + (12-3)*0.5µs
94.5µs-4.5µs = Count*15µs
90µs=Count*15µs
Count = 6
B=06H
Example-7: Specify the number of times the following loop will be executed.
a) MVI A, 17H
NXT: ORA A
RLC
JNC NXT
HLT
Answer
4 times
b) MVI A, 17H
NXT: RLC
ORA A
JNC NXT
HLT
Answer
Example-8: Write a program to generate a continuous square wave with the period of 500µs.
Assume the system clock period is 325ns, and use bit D0 to output the square wave.
Answer
T-state required
MVI D, 55H 7
ROTATE: MOV A, D 4
RLC 4
MOV D, A 4
ANI 01H 7
OUT FFH 10
MVI B, Count 7
Delay: DCR B 4
JNZ Delay 10/7
JMP ROTATE 10
HLT
5
On-time=Off-time=250µs
On-time = (Count*14 - 3 + 46) * 325ns
Example-9: Write a program to generate a rectangular wave with a 200µs on-period and a 400µs
off-period. [Clock frequency of the system = 4MHz
Answer
T-state required
NXT: MVI A, 01H 7
OUT FFH 10
MVI B,Count1 7
NXT1: NOP 4
NOP 4
NOP 4
DCR B 4
JNZ NXT1 10/7
MVI A, 00H 7
OUT FFH 10
MVI C, Count2 7
NXT2: NOP
4
NOP
4
NOP
4
DCR C
4
JNZ NXT2
JMP NXT 10/7
HLT 10
5
The chip is a 40-pin chip. It is a general purpose used for interfacing parallel IO devices to the
microprocessor. The microprocessor accepts or sends data to or from the IO devices through the interface
modules known as ports. It has three separately accessible ports: A, B, and C. The width of each port is 8-
bit. The ports are divided into as Group-A and Group-B ports: Port-A and 4 MSBs of Port-C together
form Group-A where as Port-B and 4 LSBs of Port-C form Group-B. 8255 PPI has one programmable
register and is called programmable register. It is used to configure the ports in different modes.
Pin layout
This three-state bi-directional 8-bit buffer is used to interface the 8255 to the system data bus. Data is
transmitted or received by the buffer upon execution of input or output instructions by the CPU. Control
words and status information are also transferred through the data bus buffer.
The function of this block is to manage all of the internal and external transfers of both Data and Control
or Status words. It accepts inputs from the CPU Address and Control busses and in turn, issues commands
to both of the Control Groups.
The functional configuration of each port is programmed by the systems software. In essence, the CPU
"outputs" a control word to the 8255. The control word contains information such as "mode", "bit set",
"bit reset", etc., that initializes the functional configuration of the 8255. Each of the Control blocks
(Group A and Group B) accepts "commands" from the Read/Write Control logic, receives "control
words" from the internal data bus and issues the proper commands to its associated ports.
Pin description
A "low" on this input pin enables the entire 8255. While CS selects the entire chip, it is A0 and A1 that
selects the specific port. A0 and A1 are used to access ports A, B, C or the control register according the
table below.
CS bar A1 A0 SELECTION
0 0 0 PORT A
0 0 1 PORT B
0 1 0 PORT C
0 1 1 CONTROL
1 X X 8255 is disabled
RD (Read bar)
This control signal enables the read operation. A "low" on this input pin enables 8255 to send the data or
status information to the microprocessor on the data bus. In essence, it allows the microprocessor to "read
data from" the 8255 PPI port.
WR (Write bar)
This control signal enables the write operation. A "low" on this input pin enables the microprocessor to
write data or control words into the 8255 PPI port.
RESET
This is an active high signal input to the 8255. A "high" on this input initializes the control register to 00H
and all ports (A, B, C) are initialized as the input ports.
Ports A, B, and C
The 8255 contains three 8-bit ports (A, B, and C). All can be configured to a wide variety of functional
characteristics by the system software but each has its own special features or "personality" to further
enhance the power and flexibility of the 8255.
Port A (PA0-PA7)
This 8 bit port can be programmed as input or all pins as output or all pins as bidirectional port.
Port B (PB7-PB0)
This 8 bit port can be programmed all pins as input or all pins as output.
Port C (PC7-PC0)
One 8-bit data output latch/buffer and one 8-bit data input buffer (no latch for input). This port can be
divided into two 4-bit ports under the mode control. Each 4-bit port contains a 4-bit latch and it can be
used for the control signal output and status signal inputs in conjunction with ports A and B.
These pins are connected with the data pins of the microprocessor and used for transferring data between
8255 chip and the microprocessor.
Control word
The control word format of the 8255 is shown in the figure above. The contents of the control register are
called the control word that specifies the input/output functions of each port. The control word can be
accessed to write the control word by selecting AD0 and AD1, in high condition i.e. both ON. This
register is not available for read operation.
To configure the control register in BSR mode, set D7 of the control register to zero (D7=0). In BSR (Bit
Set/Reset) mode, the bits of port C are programmed individually.
D3 D2 D1 Pin of
port C
0 0 0 Pin 0
0 0 1 Pin 1
0 1 0 Pin 2
0 1 1 Pin 3
1 0 0 Pin 4
1 0 1 Pin 5
1 1 0 Pin 6
1 1 1 Pin 7
Example-1: Write a program that configures the control register in BSR mode, sets PC5 and Pc3 and then
reset them after some delay.
Solution
MVI C, FFH
MVI A, 0BH
OUT CWR
MVI A, 07H
OUT CWR
NXT: NOP
NOP
NOP
DCR C
JNZ NXT
MVI A, 0AH
OUT CWR
MVI A, 06H
OUT CWR
HLT
Programmable Modes of PPI (when D7=1)
Answer
a) Contents of the control register
Answer
a) Contents of the control register
1 0 0 0 1 0 1 1
b) MVI A, 8BH
OUT CWR
HLT
Example-3: Configure the ports of 8255 as follows: Port A as input, Port B as output,
PC0-PC3 as input, and PC4-PC7 as output in mode 0. Determine the content of the
control register and write an 8085 ALP to get data from port A and send it to Port B. In
addition, input data from PCL and send it out through PCU.
a)
1 0 0 1 0 0 0 1
b)
MVI A, 91H
OUT CWR
IN Port B
OUT Port B
IN Port C
ANI 0FH
RLC
RLC
RLC
RLC
OUT Port C
HLT
Example-4: Write an 8085 ALP to toggle all bits of PA continuously with some delay in
mode 0. [Configure all ports as output port and use Port A to send data]
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0
b) MVI A, 80H
OUT CWR
MVI A, AAH
Answer
a)
1 0 0 0 0 0 0 0
b)
MVI A, 80H
OUT CWR
MVI A, 00H
Again: OUT Port A
MVI C, FFH
NXT: NOP
NOP
NOP
DCR C
JNZ NXT
ADI 11H
CPI FFH
JNZ Again
HLT
Exercise-1: Write an 8085 ALP that generates the following signals on the oscilloscope.
a)
b)
c)
d)
Example -1: Write an 8085 ALP to display 5 at digit 4 of the multiplexed seven segment display
using common cathode type. [Hint send the code for five through port-A and digit number
through port-C]
Solution:
a)
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0
dp g f e d c b a
0 1 1 0 1 1 0 1
The hex code is 6DH
b) MOV A, 80H
OUT CWR
MVI A, 03H
OUT PortC
MVI A, 6DH
OUT PortA
HLT
One of the most powerful futures of the 8255 is the ability to handle handshaking signals.
Handshaking refers to the process of communicating back and forth between two intelligent
devices. Port-A and B are used for input or output while Port-C is used for handshaking signals.
In 8255, the specific lines from Port-C used for handshake signals vary according to the IO
function of a port. Therefore, input and output functions in mode 1 are discussed separately.
D7 D6 D5 D4 D3 D2 D1 D0
I/O I/O IBFA INTEA INTRA INTEB IBFB INTRB
This is an interrupt flip flop used to enable or disable the generation of the INTR signal. The two
flip-flops INTEA and INTEB I are set/reset using the BSR mode. PC4 is used to enable or disable
INTEA and PC2 is used to enable or disable INTEB.
PC6, 7
D7 D6 D5 D4 D3 D2 D1 D0
INTEA 1/0 1/0 INTRA INTEB INTRB
This is an output signal that goes low when the microprocessor unit writes data into the output
latch of the 8255. This signal indicates to an output peripheral that new data are ready to be read.
It goes high again after the 8255 receives an from the peripheral.
(Acknowledgment)
This is an input signal from a peripheral that must output a low when the peripheral receives the
data from the 8255 port.
This is an output signal, and it is set by the rising edge of the signal. This signal can be
used to interrupt the microprocessor unit to request the next data byte for output. This INTR is
set when , and INTE are all one and reset by the falling edge of .
This is an internal flip-flop to a port and needs to be set to generate the INTR signal. The two
flip-flops INTRA and INTRB are controlled by PC6 and PC2, respectively, through the BSR mode.
PC4, 5
Example calculate the contents of the control register to setup port A as input and port B as
output in mode 1.
Solution:
D7 D6 D5 D4 D3 D2 D2 D0
1 0 1 1 X 1 0 X
Table 17: Mode 2 control word Port B in mode 0 as input
D7 D6 D5 D4 D3 D2 D1 D0
1 1 X X X 0 1 1/0
Table 18: Mode 2 control word Port B in mode 1 as output
D7 D6 D5 D4 D3 D2 D1 D0
1 1 X X X 1 0 X
Example: determine the contents of the control register for the following configuration:
a) Setup Port a in mode 2, Port B in mode 0 as output port and PC2-PC0 pins as input
Solution:
Mode 2 control word Port B in mode 0 as input PC2‐PC0 as input
D7 D6 D5 D4 D3 D2 D1 D0
1 1 X X X 0 0 1
Port A as bidirectional port, Port B in mode 1 as input
D7 D6 D5 D4 D3 D2 D1 D0
1 1 X X X 1 1 X
8085 interrupts
Interrupt is a process where an external device can get the attention of the microprocessor. When
a device interrupts, it actually wants the microprocessor to give a service which is equivalent r to
asking the microprocessor to call a subroutine. This subroutine is called Interrupt Service
Routine (ISR).
Classification of Interrupts
i.e.: Responding to an interrupt may be immediate or delayed depending on whether the interrupt
is maskable or non-maskable and whether interrupts are being masked or not.
The 8085 microprocessor has only one none-maskable interrupt. The non-maskable interrupt is
not affected by the value of interrupt enable flip flop.
There are two ways of redirecting the execution to the ISR depending on whether the interrupt is
vectored or non-vectored.
When microprocessor receives an interrupt signal, it suspends the currently executing program
and jumps to an Interrupt Service Routine (ISR) to an incoming interrupt. Each interrupt will
most probably have its own ISR.
The detailed sequence that is common for both vectored and non-vectored interrupts:
RST 7.5
The RST 7.5 interrupt is the only 8085 interrupt that has memory.
If a signal on RST7.5 arrives while it is masked, a flip flop will remember the
signal.
When RST7.5 is unmasked, the microprocessor will be interrupted even if the
device has removed the interrupt signal.
This flip flop will be automatically reset when the microprocessor responds to an
RST 7.5 interrupt.
It is positive edge sensitive.
When a positive edge appears on the RST7.5 line, logic 1 is stored in the flip-flop
as a “pending” interrupt.
Since the value has been stored in the flip flop, the line does not
have to be high when the microprocessor checks for the interrupt to be
recognized.
The line must go to zero and back to one before a new interrupt is
recognized.
3. TRAP
An interrupt vector is a pointer to where the ISR is stored in memory and all interrupts are
mapped onto a memory area called the Interrupt Vector Table (IVT).
The IVT is usually located in memory page 00 (0000H - 00FFH).The purpose of the IVT is to
hold the vectors that redirect the microprocessor to the right place when an interrupt arrives.
• Example: Let a device interrupts the Microprocessor using the RST 7.5 interrupt line.
– Since the RST 7.5 interrupt is vectored interrupt, Microprocessor knows to which
memory location it has to go using a call instruction to get the ISR address.
RST7.5 is knows as Call 003Ch to Microprocessor. Microprocessor goes to 003C
location and will get a JMP instruction to the actual ISR address. The
Microprocessor will then, jump to the ISR location
8. RET instruction at the end of the ISR allows the MP to retrieve the return address from
the stack and the program is transferred back to where the program was interrupted.
2. Bit 3 (Mask Set Enable - MSE) is an enable for setting the mask (D0 to D2).
• If it is set to 0 the mask is ignored and the old settings remain.
• If it is set to 1, the new settings are applied.
N.B
The SIM instruction is used for multiple purposes and not only for setting interrupt masks.
3. Bit 5 is not used by the SIM instruction therefore its value is don’t care.
4. SDE (Serial Data Enable)
If this bit is equal to one, it enables the serial output. I.e. to implement serial output, this
bit needs to be enabled.
5. SOD (serial output data)
Bit D7 of the accumulator is latched into the SOD output line of the microprocessor to
make it available to serial peripheral if D6=1.
Example-1: Set the interrupt masks so that RST5.5 is enabled, RST6.5 is masked, and RST7.5 is
enabled.
Solution
Example-2: Calculate the control word to enable RST 7.5 and RST 6.5 and disables RST 5.5
interrupts and then write an 8085 ALP that performs the above functions.
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 1 0 0 1
EI
SIM
MVI A, 09H
HLT
Example-3: Calculate the control word to enable (unmask or set) RST 7.5 and RST 5.5 interrupt
and then write an 8085 ALP that performs the above functions.
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 1 0 1 0
EI
SIM
MVI A, 0AH
HLT
Example -4: Sometimes it is desirable to reset (mask or disable) the RST 7.5 service request flip-
flop under program control. Obtain the control word and write an 8085 ALP that performs the
above function.
D7 D6 D5 D4 D3 D2 D1 D0 Hex
value
0 0 0 0 1 1 0 0 0CH
0 0 0 1 1 0 0 0 18H
EI
SIM
MVI A, 0CH
HLT
2. The 8085 checks for an interrupt during the execution of every instruction.
3. If there is an interrupt, and if the interrupt is enabled using the interrupt mask, the
microprocessor will complete the executing instruction, and reset the interrupt flip flop.
4. The microprocessor then executes a call instruction that sends the execution to the
appropriate location in the interrupt vector table.
5. When the microprocessor executes the call instruction, it saves the address of the next
instruction on the stack.
6. The microprocessor jumps to the specific service routine.
7. The service routine must include the instruction EI to re-enable the interrupt process.
8. At the end of the service routine, the RET instruction returns the execution to where the
program was interrupted.
Pending Interrupts
• Since the 8085 has five interrupt lines, interrupts may occur during an ISR and remain
pending.
– Using the RIM instruction, it is possible to can read the status of the interrupt
lines and find if there are any pending interrupts.
• Bits 0‐2 show the current setting of the mask for each of RST 7.5, RST 6.5 and RST 5.5
• They return the contents of the three mask flip-flops.
• They can be used by a program to read the mask settings in order to
modify only the right mask.
• Bit 3 shows whether the maskable interrupt process is enabled or not.
• It returns the contents of the Interrupt Enable Flip Flop.
• It can be used by a program to determine whether or not interrupts are
enabled.
• Bits 4-6 show whether or not there are pending interrupts on RST 7.5, RST 6.5, and RST
5.5
• Bits 4 and 5 return the current value of the RST5.5 and RST6.5 pins.
• Bit 6 returns the current value of the RST7.5 memory flip flop.
• Bit 7 is used for Serial Data Input.
• The RIM instruction reads the value of the SID pin on the microprocessor
and returns it in this bit.
Example: Write an 8085 ALP that checks if there is a pending request at interrupt pin RST 7.5.
[If there is a pending interrupt at this pin send FFH through Port A otherwise send 00H through
Port C]
Solution
RIM
ANI 40H
CPI 40H
JNZ XX
MVI A, FFH
OUT Port A
JMP END
XX: MVI A, 00H
OUT Port C
END: NOP
HLT
The 8085 recognizes 8-restart instructions: RST0—RST7. These are one byte call instruction
that transfer the program execution to a specific location on page 00H, i.e. executing each of this
would send the execution to a predetermined hardwired memory location.
Restart Sequence
• The restart sequence is made up of three machine cycles
– In the 1st machine cycle:
• The microprocessor sends the INTA signal.
• While INTA is active the microprocessor reads the data lines expecting to
receive, from the interrupting device, the opcode for the specific RST
instruction.
– In the 2nd and 3rd machine cycles:
• The 16-bit address of the next instruction is saved on the stack.
• Then the microprocessor jumps to the address associated with the
specified RST instruction.
Issues in Implementing INTR Interrupts
• Can the microprocessor be interrupted again before the completion of the ISR?
– As soon as the 1st interrupt arrives, all maskable interrupts are disabled.
– They will only be enabled after the execution of the EI instruction.
Therefore, the answer is: “only if we allow it to”.
If the EI instruction is placed early in the ISR, other interrupt may occur before the ISR is done.
The Intel 8259A Programmable Interrupt Controller handles up to eight vectored priority interrupts for
the microprocessor. It is cascadable for up to 64 vectored priority interrupts without additional circuitry. It
is packaged in a 28-pin DIP, uses NMOS technology and requires a single a5V supply. Circuitry is static,
requiring no clock input. The 8259A is designed to minimize the software and real time overhead in
handling multi-level priority interrupts. It has several modes, permitting optimization for a variety of
system requirements. The 8259A is fully upward compatible with the Intel 8259. Software originally
written for the 8259 will operate the 8259A in all 8259 equivalent modes.
8259A.
16 I/O SLAVE PROGRAM/ENABLE BUFFER: This is a dual function pin. When in the
Buffered Mode it can be used as an output to control buffer transceivers (EN).
When not in the buffered mode it is used as an input to designate a master (SP e 1)
or slave (SP e 0).
INT 17 O INTERRUPT: This pin goes high whenever a valid interrupt request is asserted. It
is used to interrupt the microprocessor, thus it is connected to the microprocessor's
interrupt pin.
IR0-IR7 18-25 I INTERRUPT REQUESTS: Asynchronous inputs. An interrupt request is executed
by raising an IR input (low to high), and holding it high until it is acknowledged
(Edge Triggered Mode), or just by a high level on an IR input (Level Triggered
Mode).
26 I INTERRUPT ACKNOWLEDGE: This pin is used to enable 8259A interrupt-
vector data onto the data bus by a sequence of interrupt acknowledge pulses issued
by the microprocessor.
A0 27 I AO ADDRESS LINE: This pin acts in conjunction with the CS, WR, and RD pins.
PRIORITY RESOLVER
This logic block determines the priorities of the bits set in the IRR. The highest priority is selected and
strobed into the corresponding bit of the ISR during INTA pulse.
A LOW on this input enables the 8259A. No reading or writing of the chip will occur unless the device is
selected.
(WRITE bar)
A LOW on this input enables the CPU to write control words (ICWs and OCWs) to the 8259A.
(READ bar)
A LOW on this input enables the 8259A to send the status of the Interrupt Request Register (IRR), In
Service Register (ISR), the Interrupt Mask Register (IMR), or the Interrupt level onto the Data Bus.
A0
This input signal is used in conjunction with WR and RD signals to write commands into the various
command registers, as well as reading the various statuses registers of the chip. This line can be tied
directly to one of the address lines.
INTERRUPT SEQUENCE
The powerful features of the 8259A in a microcomputer system are its programmability and the interrupt
routine addressing capability. The latter allows direct or indirect jumping to the specific interrupt routine
requested without any polling of the interrupting devices. The normal sequence of events during an
interrupt depends on the type of CPU being used. The events occur as follows in an MCS-80/85 system:
1. One or more of the INTERRUPT REQUEST lines (IR7-IR70) are raised high, setting the
corresponding IRR bit(s).
2. The 8259A evaluates these requests, and sends an INT to the CPU, if appropriate.
3. The microprocessor acknowledges the INT and responds with an INTA pulse.
4. Upon receiving an INTA from the microprocessor, the highest priority ISR bit is set, and the
corresponding IRR bit is reset. The 8259A will also release a CALL instruction code (11001101) onto the
8-bit Data Bus through its D7-D0 pins.
5. This CALL instruction will initiate two more INTA pulses to be sent to the 8259A from the
microprocessor.
6. These two INTA pulses allow the 8259A to release its preprogrammed subroutine address onto the
Data Bus. The lower 8-bit address is released at the first INTA pulse and the higher 8-bit address is
released at the second INTA pulse.
7. This completes the 3-byte CALL instruction released by the 8259A. In the AEOI mode the ISR bit is
reset at the end of the third INTA pulse.
Otherwise, the ISR bit remains set until an appropriate EOI command is issued at the end of the interrupt
sequence.
CASCADE MODE
THE CASCADE BUFFER/COMPARATOR
This function block stores and compares the IDs of all 8259A's used in the system. The associated three
pins (CAS0-2) are outputs when the 8259A is used as a master and are inputs when the 8259A is used as
a slave. As a master, the 8259A sends the ID of the interrupting slave device onto the CAS0-2 lines. The
slave thus selected will send its preprogrammed subroutine address onto the Data Bus during the next one
or two consecutive INTA pulses.
The 8259A can be easily interconnected in a system of one master with up to eight slaves to handle up to
64 priority levels. The master controls the slaves through the 3 line cascade bus. The cascade bus acts like
chip selects to the slaves during the INTA sequence. In a cascade configuration, the slave interrupt
outputs are connected to the master interrupt request inputs. When a slave request line is activated and
afterwards acknowledged, the master will enable the corresponding slave to release the device routine
address during bytes 2 and 3 of INTA. The cascade bus lines are normally low and will contain the slave
address code from the trailing edge of the first INTA pulse to the trailing edge of the third pulse. Each
8259A in the system must follow a separate initialization sequence and can be programmed to work in a
different mode. An EOI command must be issued twice: once for the master and once for the
corresponding slave. An address decoder is required to activate the Chip Select (CS) input of each 8259A.
The cascade lines of the Master 8259A are activated only for slave inputs, non-slave inputs leave the
cascade line inactive (low).
In serial data transmission, bits of a byte are sent one after another along a single line starting with LSB.
The transmission format is concerned with issues such as synchronization, direction of data flow, speed
errors and medium of transmission.
The serial mode of data transmission can take place unilaterally or bilaterally. Usually the data
transmission takes place in any of the following types of digital modes.
Simplex mode
Half-duplex mode
Duplex (full duplex)mode
a) Simplex Mode
The data in simplex mode of transmission flows on a single channel i.e. on pair of wires in only
one direction as illustrated in the figure below.
In half-duplex mode of transmission the data flows on a single channel in both direction but not at
the same time.
Here the data can be transmitted from transmitter A to receiver B or from transmitter B to
receiver A.
Synchronization
Synchronously or
Asynchronously
a) Asynchronous serial data transmission
The asynchronous transmission is character oriented. Each character carries the information of the ‘start
bit’, and then ‘stop bits’ as indicated in the figure
below.
During transmission various types of errors can occur. These errors need to be checked an; therefore,
additional information for error checking is sent during the transmission. The receiver can check the
received data against the error check information, if the error is detected, the receiver either correct the
error or request the retransmission of that data segment.
Parity check
Check sum
Cyclic redundancy check
a) Parity check
Probably the most common and oldest method of error detection is the use of parity. While parity is used
in both asynchronous and synchronous data streams, it seems to find greater use in low-speed
asynchronous transmission applications; however, its use is not exclusive to this.
Parity works by adding an additional bit to each character word transmitted. The state of this bit is
determined by a combination of factors, the first of which is the type of parity system employed. The two
types are even and odd parity. The second factor is the number of logic 1 bits in the data character. In an
even parity system, the parity bit is set to a low state if the number of logic 1s in the data word is even. If
the count is odd, then the parity bit is set high. For an odd parity system, the state of the parity bit is
reversed. For an odd count, the bit is set low, and for an even count, it is set high.
EXAMPLE 3-1
What is the state of the parity bit for both an odd and an even parity system for the extended ASCII
character B?
SOLUTION
The extended ASCII character B has a bit pattern of 01000010 (42 H). The number of logic 1s in that
pattern is two, which is an even count. For an even parity system, the parity bit would be set low and for
an odd parity system, it would be set high.
To detect data errors, each character word that is sent has a parity bit computed for it and appended after
the last bit of each character is sent as illustrated in Figure 3-1. At the receiving site, parity bits are
recalculated for each received character. The parity bits sent with each character are compared to the
parity bits the receiver computes. If their states do not match, then an error has occurred. If the states do
match, then the character may be error free.
EXAMPLE 3-2
The ASCII character B is transmitted with an even-parity bit appended to it. Illustrate how the receiver
would detect an error.
SOLUTION
As shown in Figure 3-2a, the state of the even-parity bit for the ASCII B is low, so the complete data
stream for the character sent, starting with the least significant bit (LSB) is: 010000100. Notice, there are
now nine bits—eight bits for the extended ASCII character B and one for the parity bit. The breakdown of
the data stream is:
Suppose that the LSB becomes corrupted during transmission. The receiver receives the character as:
110000100. When the receiver computes a parity bit for the character data, it results in a high state of the
parity.
This is compared with the transmitted parity, which is a low state. Since they do not agree, the receiver
determines that an error has occurred.
Note that the receiver cannot determine which bit is bad, only that one of them is wrong.
A match between transmitted parity and receiver-calculated parity does not guarantee that the data has not
been corrupted. Indeed, if an even number of errors occurs in a single character, then the parity for the
corrupted data will be the same state as the good data. For instance, suppose the two lowest bits in the
character B were bad. The total number of ones in the data stream would still be an even count and the
parity bit calculated at the receiver would be a low state and would match the one transmitted. This does
not present a major problem, since the occurrence of two errors in an eight-bit character is excessive and
usually indicates a major problem in the system.
Such a problem would cause errors to occur in other characters and one of them would eventually be
detected. Since the occurrence of errors is extremely low, parity is successful in detecting more than 95%
of the errors that occur.
Review Questions
1. What is the state of the parity bit using an odd-parity system for the extended ASCII character M?
2. Why doesn’t a good match between transmitted and received parity bits guarantee that the character is
good?
EXAMPLE 3-10
What is the checksum value for the extended ASCII message “Help!”?
SOLUTION
The checksum value is found by adding up the bytes representing the Help! Characters:
H 0 1 0 0 1 0 0 0
e 0 1 1 0 0 1 0 1
l 0 1 1 0 1 1 0 0
p 0 1 1 1 0 0 0 0
! 0 0 1 0 0 0 0 1
Sum 0 0 0 1 0 0 0 0
One’s complement 1 1 1 0 1 1 1 1
Checksum 1 1 1 1 0 0 0 0
Review Questions
1. What is the 16-bit checksum value for the extended ASCII message “That’s a 10-4”? Do not
forget space characters!
2. Why are larger checksums preferred over shorter ones?
c) Baud Rate
The rate at which the bits are transmitted (bits/second) is called baud rate. Baud rate varies from device to
device.
Bit waiting time is calculated from a given baud rate.
Example: Determine the bit time (the delay between any two consecutive bits) if the baud rate of a given
device is 1200.
Answer
1200bits—1 second
1 bit --- 1/1200 second = 0.83ms
In addition to configuring the interrupt pins, the SIM instruction is used to output data serially through the
SOD line.
During serial transmission, D7 and D6 of the accumulator register are interpreted as follows:
In short the SIM instruction checks D6 of the accumulator register to send the bit at D7 of the
accumulator. If D6 is set to 1, the SIM instruction will send the bit at D7 of the accumulator. If D6 is 0,
nothing is transmitted through the SOD line.
Example: Write a subroutine to transmit an ASCII character stored in register B using the SOD one bit
port.
Solution
MVI C, 0BH
SUB A
NEXTBIT: MVI A, 80H
RAR
SIM
CALL BITTIME
STC
MOV A, B
RAR
MOV B, A
DCR C
JNZ NEXTBIT
RET
Besides reading the status of the interrupt pins, RIM instruction is used to input data serially to D7 of the
accumulator register from the SID line of the 8085 microprocessor.
Start
Read SID
Is it
high?
Wait for Half‐Bit Time
Setup Bit Counter
Wait Bit Time
Read SID
Save Bit
Decrement Bit counter
Are all bits
received? Return
Add Bit to previous Bits
Go back to get next bit
Example: Write a subroutine to receive an ASCII character using the 8085 SID pin.
Solution
Check: RIM
RAL
JC Check
CALL HALFTIME
MVI C, 08H
NEXTBIT: RIM
CALL BITTIME
RAL
DCR C
JZ RETURN
MOV A, B
RAR
MOV B, A
JMP NEXTBIT
RETURN: NOP
RET
The 8254 Programmable Interval Timer (PIT) can be programmed to operate in six modes and
has three 16-bit identical counters that can operate independently in any one of the six modes.
It has five control signal lines, namely; Chip select bar, A0, A1, Read bar and Write bar.
A1, A0
These lines are connected to the address bus of the processor. The address inputs select one of
the four internal registers within the 8254 as follows:
A1 A2 Function
0 0 Counter 0
0 1 Counter 1
1 0 Counter -2
1 1 Control Register
(Read bar)
Read causes data to be read from the 8254. A low on this pin informs the 8254 PIT the
microprocessor is ready to accept data in the form of count value.
(Write bar)
Write causes data to written to the 8254. A low on this pin enables the microprocessor to
configure control register and load the count value to the selected counter.
Chip select enables the 8254 for programming, reading and writing to a counter. No reading or
writing operations are performed by or on the 8254.
GRD
VCC
CLK
The clock input is the timing source for each of the internal counter.
OUT
Can have square wave, one shot and other waves for various duty cycles but no sine wave, or
saw tooth wave.
GATE
D0-D7
The D0-D7 data bus of the 8253/54 is a bidirectional bus connected to D0-D7 of the system data
bus.
D0
D0 chooses between a binary number divisor of 0000 to FFFFH or a BCD divisor of 0000 to
9999H.
• The highest number is 216 for binary and 104 for BCD.
• To get the highest count, the counter is loaded with zeros.
D3 D2 D1 Mode
0 0 0 Mode 0 Interrupt on terminal count
0 0 1 Mode 1 Programmable one-shot
X 1 0 Mode 2 Rate Generator
X 1 1 Mode 3 Square wave rate generator
1 0 0 Mode 4 Software triggered strobe
1 0 1 Mode 5 Hardware triggered strobe
D4 and D5
D4 and D5 are used for RL0 and RL1. RL0 and RL1 are used to indicate the size of the count
values and counter latching operation. In indicating the size of the count it has 3 options:
D7 and D5
D6 and D7 are used to select the 3 counters: counter 0, counter 1, or counter 2 and read back
operation. All counters are down counters and to program a given counter of the 8253/54, one
must send the count value to the specific counter’s register.
Example-1: Write a program that configures the 8254 in mode-0, select counter-0 and counts in BCD.
[COUNT value= 120 in decimal]
Solution
a)
D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 1 0 0 0 1
b) MVI A, 31H
OUT CWRT
MVI A, 20H
OUT CTR1
MVI A, 01H
OUT CTR1
HLT
Example-2: Pin Chip Select bar of a given 8253/54 is activated by binary address A7-A2=100101.
a) Find the port addresses assigned to the counters and control register of 8253/54.
b) Find the configuration for 8253/54 if the control register is performed as follows
MVI A, 36H
OUT CWRT
HLT
Solution
a)
Chip Select bar A1 A2 Port Port Address
A7 A6 A5 A4 A3 A2
1 0 0 1 0 1 0 0 Counter-0 94H
1 0 0 1 0 1 0 1 Counter-1 95H
1 0 0 1 0 1 1 0 Counter-2 96H
1 0 0 1 0 1 1 1 Control register 97H
b)
D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 1 0 1 1 0
Example-1: Configure control register of 8254 as follows: select counter-1, load 16-bit counter value in
mode-1 as binary counter and then write an 8085 ALP that configures OUT1 to output low pulse for 50µs
if the input clock frequency is 1MHz.
a) Count = Delay/input period = 50µs/ 1µs = 50 in decimal .To maintain a low pulse for 50µs at
the OUT pin of the selected counter; it should be initialized in mode 1.
D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 0 1 0
b) MVI A, 72H
OUT CWRT
MVI A, 32H
OUT CTR1
MVI A, 00H
OUT CTR1
HLT
Example-1: Write an 8085 ALP to generate a pulse every 50µs from counter 0. Configure it to count in
binary. [Input clock frequency is 2MHz]
a) Count = Delay/input period = 50µs/ 0.5µs = 100 in decimal or 64H
To generate a pulse every 50µs from counter 0, it should be initialized in mode 2.
D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 1 0 1 0 0
0 0 1 1 0 1 0 0
b) MVI A, 14H
OUT CWRT
MVI A, 64H
OUT CTR0
HLT
Or
MVI A, 34H
OUT CWRT
MVI A, 64H
OUT CTR0
MVI A, 00H
OUT CTR0
HLT
Example-2: Write a program to generate a pulse at the rate frequency of 638Hz from counter-2. The input
clock frequency to counter 2 is 1MHz.
a) Count = Delay/input period = 1567µs/ 1µs = 1567 in decimal .To generate a pulse every
1/638 s from counter 2; it should be initialized in mode 2.
D7 D6 D5 D4 D3 D2 D1 D0
1 0 1 1 0 1 0 1
b) MVI A, B5H
OUT CWRT
MVI A, 67H
OUT CTR2
MVI A, 15H
OUT CTR2
HLT
Example-1: Write an 8085 ALP to generate a 10 KHz square wave from counter-0 with input clock
frequency of 1MHz.
Solution
a) Count = Delay/input period = 1MHz/ 10 KHz = 100 in decimal or 64H
D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 1 0 1 1 0
b) MVI A, 36H
OUT CWRT
MVI A, 64H
OUT CTR0
MVI A, 00H
OUT CTR0
HLT
Example-2: Write instructions to generate a 1 KHz square wave from counter-1. [Configure it as a binary
counter and the input clock frequency for counter-one is 2MHz]
Solution
D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 1 1 0
b) MVI A, 76H
OUT CWRT
MVI A, D0H
OUT CTR1
MVI A, 07H
OUT CTR1
HLT