Professional Documents
Culture Documents
Semester – IV
Paper – III; Unit – I
Microprocessor 8085 & Programs
4) Simple programs
1) Introduction to Microprocessor 8085
A single Integrated Circuit (IC) has all the functional components of a CPU namely
Arithmetic Logic Unit (ALU), Control Unit and registers.
The 8085 microprocessor is an 8-bit processor that includes on its chip most of the logic
circuitry for performing computing tasks and for communicating with peripherals.
1. Introduction to …. Continue
Features
8 bit microprocessor(8085 microprocessor can read or write or
perform arithmetic and logical operations on 8-bit data at time)
It has 8 data lines and 16 address lines hence capacity is 216 = 64
kB of memory
Cock frequency is 3 MHz
It requires +5V power supply.
It is a single chip NMOS device implemented with 6200 transistors.
It provides 74 instructions with five addressing modes.
It provides 5 hardware interrupt and 8 software interrupts.
1. Introduction to …. Continue
The typical processor system Bus: A shared group of wires used for
consists of: communicating signals among devices
• address bus: the device and the location within
▪ CPU (central processing unit) the device that is being accessed
▪ ALU (arithmetic-logic unit) • data bus: the data value being communicated
▪ Control Logic
▪ Registers, etc… • control bus: describes the action on the address
▪ Memory and data buses
▪ Input / Output interfaces CPU: Core of the processor, where instructions
Interconnections between these are executed
units: • High-level language: a = b + c
• Assembly language: add r1 r2 r3
▪ Address Bus • Machine language: 0001001010111010101
▪ Data Bus
1. Introduction to …. Continue
I. 8085 ARCHITECTURE
ALU
9
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
Register Section
a) Temporary Register
b) General Purpose Register
c) Special Purpose Registers
a) Temporary Registers
• In 8085 available temporary register are temporary data register and W and Z
registers. These registers are not available to the programmer, but 8085 uses t
hem internally to hold temporary data during execution of some instructions.
• W and Z are two 8-bit temporary registers, used to hold 8-bit
data/address during execution of some instructions.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
i. Accumulator
c). Special Purpose Register
ii. Status or Flag Register
iii. Instruction Register
iv. Program Counter
v. Stack Pointer
i. Accumulator
• The accumulator is an 8-bit register that is a part of arithmetic/logic unit (ALU).
• This register is used to store 8-bit data and to perform arithmetic and logical operatio
ns.
• The result of an operation is stored in the accumulator. The accumulator is also ident
ified as register A.
• It also works as a via register for I/O accesses i.e. it reads data from input device and
similarly can transfer data to output device.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
A flag register contains a number of flags either to indicate certain conditions arising
after arithmetic and logical operations or to control certain operations.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
The flags which indicate conditions are known as condition flags. The flags which are used to control certain
operations are called control flags.
A flag is a flip-flop which is set or reset by the processor to indicate certain conditions or set/reset by the
programmer to control certain operations.
• Carry flag(CY): If an operation performed in ALU generates the carry from D7 to next stage then CY flag is s
et, else it is reset.
• Auxiliary carry(AC): If an operation performed in ALU generates the carry from lower nibble (D0 to D3) to
upper nibble (D4 to D7) AC flag is set, else it resets.
• Zero flag(z): If an operation performed in ALU results 0value of entire 8-bits then zero flag is set, else it resets
• Sign flag(s): If MSB bit =0 then the number is positive, else it is negative.
• Parity flag(p):If the result contains even no. of ones this flag is set and for odd no. of ones this flag is reset.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
Temporary store for the current instruction of a program. Latest instruction sent here
from memory prior to execution. Decoder then takes instruction and decodes or interprets
the instruction. Decoded instruction then passed to next stage.
There is an Instruction decoder which decodes the information's present in the Instruction
register for further processing.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
v. Stack Pointer
The stack pointer is also a 16-bit register used as a memory pointer. It points to a memory
location in R/W memory, called the stack. The beginning of the stack is defined by loading 16-
bit address in the stack pointer.
Stack pointer is also a 16-bit register which is used as a memory pointer.
Stack pointer maintains the address of the last byte that is entered into stack.
Each time when the data is loaded into stack, Stack pointer gets decremented.
ALU
The ALU performs the actual numerical and logic operation such as add,
subtract, AND, OR, etc. Uses data from memory and from Accumulator to
perform arithmetic. Always stores result of operation in Accumulator.
Address Buffer
The contents of the stack pointer and program counter are loaded into the address buffer and address-
data buffer.
These buffers are then used to drive the external address bus and address-data bus.
As the memory and I/O chips are connected to these buses, the CPU can exchange desired data to the
memory and I/O chips.
The address-data buffer is not only connected to the external data bus but also to the internal data bus
which consists of 8-bits.
The address data buffer can both send and receive data from internal data bus.
The contents of the stack pointer and program counter are loaded into the address buffer and address-
data buffer. These buffers are then used to drive the external address bus and address-data bus. As the
memory and I/O chips are connected to these buses, the CPU can exchange desired data to the memory
and I/O chips.
The address-data buffer is not only connected to the external data bus but also to the internal data bus
which consists of 8-bits. The address data buffer can both send and receive data from internal data bus.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
Interrupt Control
Consider that a microprocessor is executing the main program. Now whenever
the interrupt signal is enabled or requested the microprocessor shifts the
control from main program to process the incoming request and after the
completion of request, the control goes back to the main program.
For example an Input/output device may send an interrupt signal to notify that
the data is ready for input. The microprocessor temporarily stops the
execution of main program and transfers control to I/O device. After
collecting the input data the control is transferred back to main program.
II. FUNCTION OF EACH BLOCK 2). Architecture… Continue…
It accepts data from instruction decoder and generates micro steps to perform it ,in addition it accepts clock
inputs for synchronizing operations.
This unit consists of an oscillator and controller sequencer which sends control signals needed for internal and
external control of data and other units.
Bus Organization
What is a Bus?
It is a set of pins, wires or signals having common functions as
bus.
Data Bus
Bidirectional
Transferring data
Control Bus
• Synchronization signals
• Timing signals
• Control signal
2). Architecture… Continue…
System Bus :-wires connecting memory &
I/O to microprocessor
Address Bus
Unidirectional
Data Bus
Bidirectional
Transferring data
Control Bus
• Synchronization signals
• Timing signals
• Control signal
2). Architecture… Continue…
Address Bus
The bus over which the microprocessor sends out the address of a
memory location or I/O location is called as the address bus.
In 8085 microprocessor, Address bus is of 16 bits. This means that
Microprocessor 8085 can transfer maximum 16 bit address which
means it can address 65,536 different memory locations.
This bus is multiplexed with 8 bit data bus. So, the most significant
bits (MSB) of address goes through Address bus and LSB goes
through multiplexed data bus.
In 8085 address bus is 16 bit A – A
0 15
2). Architecture… Continue…
Data Bus
It is bi-directional as Microprocessor requires to send or
receiver data. The data bus also works as bus in 8 bits long.
A data bus simply carries data. Internal buses carry
information within the processor, while external buses carry
data between the processor and the memory. Typically, the
same data bus is used for both read/write operations.
When it is a write operation, the processor will put the data on
to the data bus. When it is the read operation, the memory
controller will get the data from the specific memory block
and put it in to the data bus.
The data bus in8085 is of 8 parallel lines D – D
0 7
2). Architecture… Continue…
Control Bus
The control bus is used for sending control signals to the memory and
I/O devices. The CPU sends control signal on the control bus to enable
the outputs of addressed memory devices or I/O port devices.
The 8085 MP Instruction set has 74 operation codes that results in 246 instructions.
The set includes all the 8080A instructions plus two additional (SIM & RIM related to serial
I/O) instructions.
There are 5 different kinds of I-sets:-
1. Data transfer/copy I-set:
2. Arithmetic I-set:
(*ADD *SUB *INR (increment1) *DCR (decrement1)
3. Logic and Bit Manipulation I-set:
*AND (ANA/I) *OR (ORA/I) *X-OR (XRA/I) *Compare(CMP/CPI)
4. Branch I-set:
5. Stack, Input/output and Machine control I-set:
3. Instruction set Conti…
33
Instruction format (Writing a program using IS)
Instructions typically consist of
Opcode (Operation Code)
◼ defines the operation to be performed (e.g. opcode for ADD B is 80H)
(Source/Destination) Operand
◼ what’s being operated on (e.g. In instruction MOV A, B the registers A (Destination) & B (Source) are
operabds)
The 8085 Instruction set typically have 0, 1 or 2 operands and consists of one,
two and three byte instructions. The first byte is always opcode.
OpCode (1 byte) OpCode(1 byte) Opd (1 byte)
Instruction lengths
36
Instruction encoding
37
Operation Encoding
2n operations needs at least n bits
Operand Encoding
Depends on the addressing modes and access space.
◼ For example: An operand in direct register addressing mode requires at most 3 bits if the the
number of registers it can be stored is 8.
With a fixed instruction length, more encoding of operations means less
available bits for encoding operands
Tradeoffs should be concerned
3. Instruction set Conti…
Example 1
38
A machine has:
16 bit instructions
16 registers (i.e. 4-bit register addresses)
Instructions could be formatted like this:
Assembly Machine
Assembler
Language Language
Program
Program Code
4. Simple programs Conti…..
Assembly language program
Assembly Language of 8085 to add two numbers
Make a Flowchart:
Start
• Load 1st no. in register D
Load Registers D, E • Load 2nd no. in register E
• Stop processing
Stop
4. Simple programs Conti…..
Program
Memory
Address: Opcode: Operands: Comments:
MVI D, 2H ; Load 1st no. in register D
MVI E, 3H ; Load 2nd no. in register E
MOV A, D ; Copy register D to A
ADD E ; Add register E to A
MOV C, A ; Copy A to register C
HLT ; Stop processing
4. Simple programs Conti…..
2 Program:
Add two 8-bit numbers. Result can be more than 8-bits (Use Carry).
10011001 99H A
Register B Register C
+
10011001 99H B Step-1 Copy A to C
Step-2
0
1 10011001
00110010 32H
99H A a) Clear register B
b) Increment B by 1
CY
4. Simple programs Conti…..
Make a Flowchart
Start
Copy D to A
Increment B
No
Add A and E
Copy A to C
Stop
4. Simple programs Conti…..
Program
Memory Mnemonics (OR)
Address: Opcode: Operands: Comments:
MVI D, 2H ; Load 1st no. in register D
MVI E, 3H ; Load 2nd no. in register E
MOV A, D ; Copy register D to A
ADD E ; Add register E to A
MOV C, A ; Copy A to register C
JNC END ; Use Conditional Jump instructions
MVI B, 0H ; Clear register B
INR B ; Increment B
HLT ; Stop processing
4. Simple programs Conti…..
3 Program:
Calculate the sum of series of numbers. The length of the series is in memory location 2300H and series itself begins from memory
location 2301H. The result of sum is stored in memory location 2500H and the carry is stored on location 2501H.
No Is
Carry = 1 Load (2500H) = Sum
(2501H) = Carry
Yes
Carry = Carry + 1
Stop
Pointer = Pointer + 1
Counter = Counter - 1
No Is
Count = 0
Yes
4. Simple programs Conti…..
Program
Memory
Address: Opcode: Operands: Comments:
LDA 2300H
MOV C, A ; Initialize counter
LXI H, 23001H ; Initialize pointer
SUB A ; Sum = 0
MOV B, A ; Initialize carry = 0
BACK : ADD M ; Sum (L) = Sum + data
JNC Loop ; Check Carry
INR B ; Add carry
Loop : INX H ; Increment Pointer
DCR C ; Decrement counter
JNZ Back ; Check if counter not 0 repeat
STA 2500H ; Store Sum
MOV A, B
STA 2501H ; Store Carry
HLT ; Stop processing
4. Simple programs Conti…..
4 Program:
Write an assembly language program in 8085 microprocessor to find maximum and
minimum of 10 numbers.
Analyze the Problem
List of numbers from 2050H to 2059H and output at 2060H and 2061H.
Sample Problem
1. Maximum number is stored in B register and minimum in C register
2. Load counter in D register
3. Load starting element in Accumulator, B and C register
4. Compare Accumulator and B register
5. If carry flag is not set then transfer contents of Accumulator to B. Else, compare Accumulator with
C register, if carry flag is set transfer contents of Accumulator to C
6. Decrement D register
7. If D>0 take next element in Accumulator and go to point 4
8. If D=0, store B and C register in memory
9. End of program
ADDRESS LABEL INSTRUCTION COMMENT
2000H LXI H, 2050H Load starting address of list
2003H MOV B, M Store maximum
2004H MOV C, M Store minimum
2005H MVI D, 0AH Counter for 10 elements
2007H LOOP MOV A, M Retrieve list element in Accumulator
2008H CMP B Compare element with maximum number Draw the Flow
2009H JC MIN Jump to MIN if not maximum Chart ?
200CH MOV B, A Transfer contents of A to B as A > B
200DH MIN CMP C Compare element with minimum number
200EH JNC SKIP Jump to SKIP if not minimum
2011H MOV C, A Transfer contents of A to C if A < minimum
2012H SKIP INX H Increment memory
2013H DCR D Decrement counter
2014H JNZ LOOP Jump to LOOP if D > 0
2017H LXI H, 2060H Load address to store maximum
201AH MOV M, B Move maximum to 2060H
201BH INX H Increment memory
201CH MOV M, C Move minimum to 2061H
201DH HLT Halt