Microprocessor 2
Microprocessor 2
The 8085 microprocessor includes the instruction set of 8088A and two
additional instructions.
– The first part is the task or operation to be performed. This part is called the
“opcode” (operation code).
– The second part is the data to be operated on Called the “operand”.
Example: MOV, MVI, IN, OUT, LDA, STA, LDAX, STAX, LXI,
LHLD,SHLD, XCHG
Opcode Operand Description
MOV Rd, Rs Copy from source to destination.
Rd, M
Dr VP Dubey
MOV Rd, Rs Copy the contents of source register to destination
register
Rd or Rs : A,B,C,D,E,H,L
Dr VP Dubey
-Copies the contents of memory location specified
by16 –bit address
- the contents of source is not changed
Example: LDA 2500H
LDAX B/D register pair Load accumulator direct
1-byte instruction
This instruction only uses the BC or DE pair.
– It does not accept the HL pair
LDAX B Copy the 8-bit contents of the memory location
specified by the BC register pair into the
Accumulator
LDAX D -copies the contents of memory location specified
by DE pair register into the accumulator
-The contents of the register pair and the memory
location are not changed
LXI RP, 16-bit data Load register pair(RP) immediate
-3-byte instruction
-loads 16-bit data in the specified register pair
LXI B, 16-bit data Load 16-bit number immediate in BC pair register
LXI D, 16-bit data Load 16-bit number immediate in DE pair register
LXI H, 16-bit data Load 16-bit number immediate in HL pair register
LXI SP, 16-bit data Load 16-bit address immediate in stack pointer
register
The upper two digits are placed in the 1st register of the pair and the
lower two digits(8-bits) in the 2nd register.
LXI B, 30 00
B 30 00 C
Dr VP Dubey
STA 16-bit Store Accumulator Direct
address
e.g. STA 3502H; store the contents of accumulator to the memory
location 3502H
STAX Reg. Pair Store accumulator indirect
STAX B Copy the contents of accumulator into the memory
location specified by the contents of the B,C register
pair.
Dr VP Dubey
XTHL None Exchange H–L with top of stack
- The contents of L register are exchanged with the
location pointed out by the contents of the SP.
-The contents of H register are exchanged with the
next location (SP + 1).
Arithmetic Operations
These instructions perform the following arithmetic operations:
Addition
Subtract
Increment
Decrement
Opcode operands Description
Dr VP Dubey
-The result is stored in accumulator.
-If the operand is memory location, its address
is specified by H-L pair.
Example: ADD C or ADD M
ADI 8-bit data Add immediate to accumulator
-The 8-bit data is added to the contents of accumulator.
-The result is stored in accumulator.
-All flags are modified to reflect the result of the
addition.
Example: ADI 35H
ACI 8-bit data Add immediate to accumulator with carry
-The 8-bit data and the Carry Flag (CY) are added to the
contents of accumulator.
-The result is stored in accumulator.
-All flags are modified to reflect the result of the addition
ADC R/M Add register or memory to accumulator with
carry
-The contents of register or memory and Carry
Flag (CY) are added to the contents of accumulator.
-The result is stored in accumulator.
-If the operand is memory location, its address is
specified by H-L pair
-All flags are modified to reflect the result of the addition
Example: ADC D or ADC M
DAD. Reg. Pair Double addition
-Add register pair to H and L register
-the 16-bit contents of specified register pair are added to
the contents of the HL register pair and sum is saved in
the HL register pair.
-The contents of source registers are not altered
DAA None Decimal Adjust Accumulator
-1-byte instruction
Dr VP Dubey
-The contents of accumulator are changed from binary
value to two 4-digit binary coded decimal(BCD) digits.
-This is only instruction that uses auxiliary
flag(internally) to perform the binary to BCD conversion.
Example:
• DAD RP HL ← HL + RP
• Only instruction that performs 16-bit addition.
• Only CY Flag is affected.
• Takes 3 machine cycles for execution.
E.g.
• DAD B HL ← HL + BC
• DAD D HL ← HL + DE
• DAD H HL ← HL + HL
• DAD SP HL ← HL + SP
Dr VP Dubey
-All flags are modified to reflect the result of
subtraction
Example: SUB C or SUB M
SUI 8-bit data Subtract immediate from accumulator
-The 8-bit data is subtracted from the contents of
accumulator.
-The result is stored in accumulator.
-All flags are modified to reflect the result of the
subtraction
Example: SUI 35H
SBB R/M Subtract register or memory from accumulator
with borrow
-The contents of the register or memory location and
Borrow Flag (i.e. CY) are subtracted from the contents of
the accumulator.
-The result is stored in accumulator.
-If the operand is memory location, its address is
specified by H-L pair.
-All flags are modified to reflect the result of
subtraction.
Example: SBB B or SBB M
SBI 8-bit data Subtract immediate from accumulator with
borrow
-The 8-bit data and the Borrow Flag (i.e. CY) is
subtracted from the contents of the accumulator.
-The result is stored in accumulator.
-All flags are modified to reflect the result of
subtraction.
Example: SBI 55 H
INR R/M Increment register or memory by 1
-The result is stored in the same place.
-If the operand is a memory location, its address is
specified by the contents of H-L pair.
Dr VP Dubey
INX Reg.pair Increment register pair by 1
-The contents of register pair are incremented by 1.
-The result is stored in the same place.
Example: INX H
DCR R/M Decrement register or memory by 1
-The result is stored in the same place.
-If the operand is a memory location, its address is
specified by the contents of H-L pair.
DCX Reg.pair Decrement register pair by 1
-The contents of register pair are decremented by 1.
-The result is stored in the same place.
Example: DCX SP
Dr VP Dubey
• DCR M – Decrement the indirect byte by 1 (memory location
specified by HL Pair).
– ((HL)) ← ((HL)) – 1
– Affects all the flags except CY.
– Indirect Addressing Mode.
– 1-byte instruction
– Takes 3 Machine Cycles (Fetch, Read and Write) for execution.
Logic Operations
These instructions perform logical operations on data stored in registers,
memory and status flags.
*All operations are performed in context to Accumulator.
The logical operations are:
AND
OR
XOR
Rotate
Compare
Complement
–ANA, ANI, ORA, ORI, XRA , XRI, RAL, RLC, RAR, RRC, CMP, CPI, CMA
Source: Accumulator and
– An 8-bit number
– The contents of a register
– The contents of a memory location
• Destination: Accumulator
Carry & Auxiliary carry flags are fixed and don’t convey useful
information.
• NOT => CMA
Dr VP Dubey
• Bitwise XOR => XRA
Logical instructions
Opcode operands Description
CMA NONE Complement the contents of ACC.
ANA R/M AND Accumulator with Register/Memory
ANI 8-bit AND Accumulator with an 8-bit number
ORA R/M OR Accumulator with Register/Memory
ORI 8-bit OR Accumulator with an 8-bit number
XRA R/M XOR Accumulator with Register/Memory
XRI 8-bit XOR Accumulator with an 8-bit number
Explanation:
• CMA A ← NOT (A)
– None of the Flags are affected.
LOGICAL AND
• ANA R ;A ← A AND R
Dr VP Dubey
e.g. ANI F0H A ← A AND F0H
• ANI F0H, would MASK the Lower nibble of A.
LOGICAL OR
• ORA R ; A ← A OR R
• E.g. ORA D ; A ← A OR D
• ORA M ; A ← A OR ((HL))
LOGICAL XOR
• XRA R ; A ← A XOR R
– E.g. XRA D ; A ← A XOR D
Dr VP Dubey
XRI FFH, would Complement the content of A.
Accumulator is Complemented.
Complement:
• 1’s complement of the contents of the accumulator.
CMA No operand
Compare
– Compare the contents of a register or memory location with the contents of
the accumulator for equality, greater than or less than.
Dr VP Dubey
memory location to the contents of the
accumulator.
if (A) < (register(R))/memory(M)): carry flag is set
if (A) = (R/M): zero flag is set
if (A) > (R/M): carry and zero flags are reset.
Example:
Let initially A = 45H and B = 30H
Execution of CMP B means
– Perform A–B = 45H-30H= 15H = (0001 0101)B
After Execution of CMP B
Dr VP Dubey
– A = 45H and B = 30H
– Flags SF=0, ZF=0, PF=0, AC=0, CY=0.
– Note that both A & B, remains unaffected from compare but
all the flags are affected.
Uses
CY=1 A<B,
CY=0 A≥B,
(CY=0 AND ZF=0) A>B
• CMP R FLAGS ← A - R
– E.g. CMP D FLAGS ← A - D
Rotating Accumulator(Acc)
• RAR Rotate Acc Right through Carry
Dr VP Dubey
CY A7, A7 A6, ….. A1 A0 , A0 CY
Example:
RAR Rotate Acc Right through Carry
CY A7, A7 A6, ….. A1 A0 , A0 CY
81H
Dr VP Dubey
- Each binary bit of the accumulator is rotated right by one bit
position
A7 A6, ….. A1 A0 , A0 A7 , A0 CY
CY=0 1 0 0 0 0 0 0 1
CY=1 1 1 0 0 0 0 0 0
Rotating Accumulator
• RAL Rotate Acc Left through Carry
CY ← A7, A7 ← A6, ……. A1 ← A0 , A0 ← CY
CY=0 A7 A6 A5 A4 A3 A2 A1 A0
Example
Before RAL Instruction
AA H
CY=0 1 0 1 0 1 0 1 0
Dr VP Dubey
After 1st RAL Instruction
54 H
1 0 1 0 1 0 1 0 0
CY A7 A6 A5 A4 A3 A2 A1 A0
AA H
0 1 0 1 0 1 0 1 0
55 H
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
Dr VP Dubey
Opcode operands Description
CMC None Complement carry
Dr VP Dubey
• PCH ← 50H and PCL ← 00H, finally PC=5000H,
showing address of instruction to be executed.
• It takes 3 Machine Cycles for execution.
Conditional JMPs
- The conditional jump instructions allow the microprocessor to take
decisions based on certain conditions indicated by flags
- The jump instruction used only four flags
Carry flag, Zero flag, Sign flag and Parity flag
- Two jump instructions are associated with each flag
Opcode Operand Description
JC 16-bit Jump if a Carry Generated(CF=1)
i.e. Jump on Carry(CF = 1).
Dr VP Dubey
• Executes similar to JZ but checks for ZF=0 before
jump. If ZF=0 then jump otherwise don’t jump.
-Before the transfer, the address of the next instruction after CALL (the
contents of the program counter) is pushed onto the stack.
-Before the transfer, the address of the next instruction after the call (the contents
of the program counter) is pushed onto the stack
Dr VP Dubey
Parity is NOT SET i.e. Call on PF = 0.
Return Instruction
Opcode Operand Description
RET None Return unconditionally
-The two bytes from the top of the stack are copied into the program counter,
and program execution begins at the new address
-The two bytes from the top of the stack are copied into the program counter,
and program execution begins at the new address.
Dr VP Dubey
Stack, I/O and Machine Control Operations
Microprocessor understands the language of 0’s and 1’s only .This language is
called Machine Language
Dr VP Dubey
A program known as Assembler is used to convert a Assembly
language program to machine language
Assembly language programmes are usually written in a standard form so that they
can be easily translated to machine language by an assembler program (may be self
on cross assembler). In general, the assembly language statements have four
sectors in general known as fields
Label field: The first field of ALP statement is the label field. A label is a symbol
used to represent an address that is not specifically known or it is a name to be
assigned to an instruction’s location. The lebel field is usually ended with a colon
(:).
Mnemonic field: This field contains the mnemonic for the instruction to be
performed. Sometimes mnemonics are referred to as operation codes or opcode. It
may consist of pseudo mnemonics.
Operand field: Operand field consists of operand and operands - either constants
or variables with reference to the instruction in the mnemonic field. It may be any
register, data, or address on which the instruction is to be performed.
Comment field: A very important part of an ALP is the comment field. For most
assemblers, the comment field is started with a semicolon (;).
A simple Program
Dr VP Dubey
JMP START ; go back to beginning and read the switches again
Register Addressing.
Immediate Addressing.
Direct Addressing.
Indirect Addressing.
Implicit Addressing
Register Addressing
The designated data item is present in one of the general purpose register of 8085.
This mode is primarily used to specify variables.
e.g. MOV C, H
MOV RD, RS – Copy the content of Source Register (RS) into Destination Register
(RD).
RS and RD can be any of the general purpose registers (A, B, C, D, E,
H, L).
Dr VP Dubey
Examples MOV A, D; MOV H, C; MOV A, A etc.
49 such Opcodes are there for MOV RD, RS.
This is a 1-byte instruction.
Takes 1-Machine Cycle (Opcode Fetch) to execute.
None of the Flags are affected.
Example: MOV RD, RS , ADD R, SUB R, ADC R, SBB R etc
A Simple program:
Register A has data 20H and Register D has data 30H. Write an 8085 ALP
(Assembly Language Program) that copies the data in A to Register E and data in
D to Register L.
HLT ; Stop
Immediate Addressing
The designated data item immediately follows the Opcode and hence the name
Immediate Addressing. This mode is used to specify the constant data.
Write an 8085 ALP (Assembly Language Program) that adds two data items 20H
and 30H and store the result in Register C and E.
Dr VP Dubey
MOV C, A ; Get result in C.
MOV E, A ; Get result in E.
HLT ; Stop.
Example: MVI DATA8 ;ADI DATA8; ACI DATA8; SUI DATA8; SBI DATA8; LXI
Rp
Direct Addressing
In this mode, the designated data item is stored in memory and the memory address
is specified directly in the instruction.
e.g. LDA 5000H, Load accumulator directly from the contents of memory
address 5000H.
A ← (5000H).
A → (5000H).
A Simple program
Two data items are stored at locations 2050H and 2051H. Write an 8085 ALP
(Assembly Language Program) to copy these data at memory locations 2100H and
2101H.
HLT
Write an 8085 ALP to add two data items and store the result in memory.
Dr VP Dubey
ADD B ; Add the data.
HLT ; Stop.
L ← (5000H).
H ← (5001H).
L → (5000H).
H → (5001H).
Indirect Addressing
The designated data item is stored in memory and the memory address is specified
through a register pair (i.e. indirectly) in the instruction. This addressing mode is
most suitable for tabular processing.
e.g. MOV B, M
B ← ((HL)).
MOV R, M
R ← ((HL)).
MOV M, R
Dr VP Dubey
Copy an 8-bit data indirectly into memory from register R.
R ((HL)).
R can be any of the 8-bit general purpose registers (A, B, C, D, E, H,
L).
14 Opcodes are there for both the MOVes.
They are 1-byte instructions but take 2-Machine Cycles to execute.
Execution of MOV M, B is explained next.
A Simple Program
Two data items are stored at locations 2500H and 2501H. Write an 8085 ALP to
add two data items stored in memory and store the result in memory at 2502H.
LXI H, 2500H ; Pointer to 1st Data in HL Pair.
MOV A, M ; Get 1st Data in A.
LXI H, 2501H ; Pointer to 2nd Data in HL Pair.
MOV B, M ; Get 2nd Data in B.
ADD B ; Add data.
LXI H, 2502H ; Pointer to Result in HL Pair.
MOV M, A ; Store result in memory at 2502H.
HLT ; Stop
Example: INX Rp ; DCX Rp; ADD M; ADC M; SUB M; SBB M; MVI M,
DATA8; LDAX Rp; STAX Rp
Implicit Addressing
The designated data item is stored in CPU registers or machine component but the
name of operand is not defined in the instruction.
HL DE.
Dr VP Dubey
Timing diagram of 8085 microprocessor
The 8085 microprocessor has 5 basic machine cycles. They are given as below
Dr VP Dubey
Memory Read Machine Cycle Memory Write Machine Cycle
Dr VP Dubey
Fetching the Opcode 34H from the memory 4105H. (OF cycle)
Let the memory address (M) be 4250H. (MR cycle -To read Memory
address and data)
Let the content of that memory is 12H.
Increment the memory content from 12H to 13H. (MW machine cycle)
Dr VP Dubey
• Stack is defined in the program LXI SP, which loads the 16-bit memory
address in the stack pointer register.
• Programmer can store and retrieve the contents of a register pair using
PUSH and POP instructions.
PUSH SP
Dr VP Dubey
– E.g. PUSH D
(SP-1) ← D
(SP-2) ← E
SP ← SP – 2
• PUSH PSW
(SP-1) ← A
(SP-2) ← FLAG
SP ← SP – 2
– E.g. POP B
C ← (SP)
B ← (SP+1)
SP ← (SP + 2)
• POP PSW
FLAG ← (SP)
A ← (SP+1)
SP ← SP + 2
Dr VP Dubey
A
simple program
Write an 8085 ALP to set Flag Status as SF=1, ZF=0, AC=1, CY=0, and
PF=1
Solution:
Dr VP Dubey
FLAG: SF ZF X AC X PF X CY
1 0 0 1 0 1 0 0 = 94H
MVI B, 00H
MVI C, 94H
PUSH B
POP PSW
SUBROUTINE
• It is a group of instructions, which are written separately from the main
program
• Subroutines are called many times in main program
Dr VP Dubey
Dr VP Dubey