CH-2 INSTRUCTION SET & PROGRAMMING OF 8085
Marks: 10 (15)
Introduction:
Basically, the microprocessor receives data from input device in binary form. It processes the data in accordance with program stored in its memory. It sends the result in binary form to output device. Microprocessor performs specified actions to instructions in binary form.
The sequence of instructions that causes the microprocessor to perform a complete task is called program.
The collection of instructions that the microprocessor recognizes is known as its instruction set. It is specified by manufacturer. User must fully understand the instruction set of microprocessor.
Each instruction must contain sufficient amount of information to perform the desired operation. The instruction contains the following information-
The operation to be performed. It is known as (operation code) Op-Code. It is specified by suitable names known as mnemonics. For example, ADD for addition, SUB for subtraction.
The source of the operands to be used. Operand means data to be operated. For example, the instruction MOV A, B transfers the contents of register B to Accumulator. Here, the operand is in reg. B which is source of data.
The destination of result. After the operation has been performed, the result goes to destination. For example, MOV A, B instruction uses accumulator as the destination.
Addressing modes of 8085:
To perform any operation, we have to give the corresponding instructions to the microprocessor.
In each instruction, programmer has to specify 3 things:
Operation to be performed.
Address of source of data.
Address of destination of result.
The method by which the address of source of data or the address of destination of result is given in the instruction is called Addressing Modes. The term addressing mode refers to the way in which the operand of the instruction is specified. Intel 8085 uses the following addressing modes:
1. Direct Addressing Mode
2. Register Addressing Mode
3. Register Indirect Addressing Mode
4. Immediate Addressing Mode
5. Implicit Addressing Mode
1. Direct Addressing Mode:
In this mode, the address of the operand is given in the instruction itself.
Ex: - LDA 2500H Load the contents of memory location 2500H in Accumulator.
LDA is the operation.
2500 H is the address of source.
Accumulator is the destination.
2. Register Addressing Mode:
In this mode, the operand is in general purpose register.
Ex: - MOV A, B Move the contents of B register to A register.
MOV is the operation.
B is the data source.
Accumulator is the destination.
3. Register Indirect Addressing Mode:
In this mode, the address of operand is specified by a register pair.
Ex: - MOV A, M Move the contents of Memory location which is pointed to by HL register pair to A register.
MOV is the operation.
M is the memory location specified by H-L register pair.
Accumulator is the destination.
4. Immediate Addressing Mode:
In this mode, the operand is specified within the instruction itself.
Ex: - MVI A, 22H Move the content 22H to A register.
MVI is the operation.
22H is the immediate data.
Accumulator is the destination.
5. Implicit Addressing Mode:
If address of source of data as well as address of destination of result is fixed, then there is no
need to give any operand along with the instruction.
Ex: - CMA complements the Accumulator contents and stored into Accumulator.
CMA is the operation.
A is the source.
A is the destination.
Instruction set of 8085:
The instruction set of 8085 microprocessor is classified into the following types.
Data Transfer Instructions
Arithmetic Instructions
Logical Instructions
Branching Instructions
Control Instructions
Data transfer instructions:
This group of instructions copies data from location called source to another location called destination. The contents of the source register are not altered/destroyed.
Examples-
MOV B, C Copy contents of register C to register B
MVI B, 57H Load register B with data 57H
LDA 2034H Copy the contents of memory location 2034H to accumulator
STA 2035H Copy the content of accumulator to memory location 2035H
LDAX B Load the accumulator with contents of memory location pointed by reg. pair BC
STA X D Load the contents of memory location pointed by reg. pair DE to accumulator
LXI H, 2032H Load 16-bit data to reg. pair HL (H=20,L=32)
Arithmetic instructions:
These instructions perform arithmetic operations such as addition, subtraction, increment and decrement.8-bit as well as 16-bit addition/subtraction performed in 8085. 8-bit contents of register/memory location incremented/decremented using instructions in this group.
Examples-
ADD B Contents of B are added to contents of accumulator and result is stored in accumulator
ADI 2AH Data 2AH is added with contents of accumulator and result is added in accumulator
ADC B Contents of B and carry flag are added with contents of accumulator and result is stored in accumulator.
ACI 52H Data 52H and carry flag are added with contents of accumulator and result is stored in accumulator.
SUB D Contents of D are subtracted from accumulator and result is stored in accumulator
SUI 37H Data 37H is subtracted from contents of accumulator and result is stored in accumulator
SBB D Contents of D and borrow are subtracted from contents of accumulator and result is stored in accumulator
SBI 26H Data 26H and borrow are subtracted from contents of accumulator and result is stored in accumulator
INR B Contents of reg. B are incremented by 1 and result is stored in B
DCR D Contents of reg. D are decremented by 1 and result is stored in D
INX B Contents of reg. pair BC are incremented by 1 and result is stored in BC
DCX H Contents of reg. pair HL are decremented by 1 and result is stored in HL
DAD B Contents of reg. pair BC are added to content of HL pair and result is stored in reg. HL pair
Logical instructions:
These instructions perform logical operations such as ANDing, ORing, XORing, inverting etc. In all operations accumulator content is one operand and second operand can be register content, memory content or 8-bit data
Examples-
ANA B Contents of accumulator are logically ANDed with contents of B and result is stored in accumulator
ANI 86H Contents of accumulator are logically ANDed with data 86H and result is stored in accumulator
ORA D Contents of accumulator are logically ORed with contents of D and result is stored in accumulator
ORI 86H Contents of accumulator are logically ORed with data86 and result is stored in accumulator
CMP B Contents of register B are compared with the contents of the accumulator. Both contents are preserved. The result of the comparison is shown by setting the flags of follows:
if (A) < (B): carry flag is set (CY=1)
if (A) = (B): zero flag is set (ZF=1)
if (A) > (B) carry and zero flags are reset (CY=0)
CPI 89H The data (89H) is compared with the contents of the accumulator. The values being
compared remain unchanged. The result of the comparison is shown by setting the flags as follows:
if (A) < data: carry flag is set
(A) = data: zero flag is set
if (A) > data: carry and zero flags are reset
CMA Contents of accumulator are complemented
RLC Each binary bit of the accumulator is rotated left by one position. Bit D7 is placed in the position of D0 as well as in the Carry flag.
RRC Each binary bit of the accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag.
Branching Instructions:
These instructions allow user to alter the sequence of execution of the program either conditionally or unconditionally.
Examples-
Jump unconditionally-
JMP 2034H The program control is transferred unconditionally to the memory location 2034H
Jump conditionally-
JZ 2034H The program control is transferred to the memory location 2034H if result is zero
Opcode Description Flag Status
JC Jump on Carry CY = 1
JNC Jump on no Carry CY = 0
JP Jump on positive S = 0
JM Jump on minus S = 1
JZ Jump on zero Z = 1
JNZ Jump on no zero Z = 0
JPE Jump on parity even P = 1
JPO Jump on parity odd P = 0
Unconditional subroutine call-
CALL 2034H The program control is transferred to the memory location 2034H.
Before the transfer, the address of the next instruction after CALL is pushed onto the stack.
Call conditionally-
CZ 2034H The program control is transferred to the memory location 2034H if result is zero.
Before the transfer, the address of the next instruction after CALL is pushed onto the stack.
Opcode Description Flag Status
CC Call on Carry CY = 1
CNC Call on no Carry CY = 0
CP Call on positive S = 0
CM Call on minus S = 1
CZ Call on zero Z = 1
CNZ Call on no zero Z = 0
CPE Call on parity even P = 1
CPO Call on parity odd P = 0
Restart instructions-RST: RST instructions are used to transfer the control to interrupt service routine. These are 8 different instructions RST0 to RST7
Control instructions:
These instructions are for following operations-
Halt (HLT)
Set interrupt mask (SIM)
Read interrupt mask (RIM)
NO operation (NOP)
Stack operation
Examples-
HLT The CPU finishes executing the current instruction and halts
NOP No operation performed
PUSH B Contents of register pair BC are copied into stack
POP D Contents of two top bytes on stack to register pair DE
Interrupts in 8085:
Microprocessor is always connected to different input/output (I/O) devices like displays, printer, keyboard etc. which are called peripheral devices. These devices communicate with microprocessor.
Interrupt is a signal, send by an external device to the processor, to perform a particular task or work. Mainly in the microprocessor based system the interrupts are used for data transfer between the peripheral and the microprocessor. When a peripheral is ready for data transfer, it interrupts the processor by sending an appropriate signal to the interrupt pin of the processor. If the processor accepts the interrupt then the processor suspends its current activity and executes an interrupt service subroutine to complete the data transfer between the peripheral and processor. After executing the interrupt service routine the processor resumes its current activity. The 8085 has two types of interrupts as-
Software interrupts
Hardware interrupts
Software interrupts:
The software interrupts are program instructions. These instructions are inserted at desired locations in a program by programmer. While running a program, if software interrupt instruction is encountered, then the processor executes an interrupt service routine (ISR). There are eight software interrupts in 8085. They are RST 0, RST 1, RST 2, RST 3, RST 4, RST 5, RST 6 and RST 7.
Hardware interrupts:
The hardware interrupts are initiated by an external device by placing an appropriate signal at the interrupt pin of the processor. If the interrupt is accepted, then the processor executes an interrupt service routine (ISR). Processor keeps on checking the interrupt pins after every instruction. If the processor finds a valid interrupt signal, then the processor accepts the interrupt. The acceptance of the interrupt is acknowledged by sending an INTA signal to the interrupted device. The hardware interrupts of 8085 are TRAP, RST 7.5, RST 6.5, RST 5.5 and INTR.
Assembly language programming:
While working on a microprocessor we required to write different programs frequently. Microprocessor only understands binary information in coded form, called machine codes. Program should be written in machine code. But writing a program in machine code is not easy but tedious error prone. It takes long and speed of development decreases. As solution to this problem the instructions in programs are written not in direct machine code but in mnemonics form. This is called assembly language. Once written in assembly language the program the program can be coded in machine codes i.e. machine language.
Writing assembly language programs requires to follow the path of logical paths. Following are the steps involved in program writing-
1. Read the problem carefully
2. Break it down into small steps
3. Represent these small steps graphically like flowchart.
4. Write appropriate mnemonic instruction (assembly language) from instruction set.
5. Translate assembly language program into machine language.
To draw the flowchart of following are the symbols used-
Oval: It indicates start or stop the operation
Arrow: It indicates the flow with direction
Rectangle: It indicates process operation
Parallelogram: It indicates input/output operation
Diamond: It indicates decision making operation
Circle: with letter: It indicates continuation
Sample programs:
1. Store 8-bit data in memory
Algorithm:
Step1: load the accumulator with data
Step2: Store contents of accumulator in memory
Flowchart:
Mnemonics & operands Comment
MVI A, 52H ; Load accumulator with data 52H
STA 4000H ; Store contents of accu. in memory location 4000H
HLT ; Stop processing
2. Add two 8-bit (hex numbers) numbers.
Algorithm:
Step1: Load two hex numbers
Step2: Add the numbers
Step3: Store the result in memory
Flowchart:
Mnemonics & operands Comment
MVI A, 05H ; Load accumulator with first no. 05H
MVI B, 06H ; Load register B with second no. 06H
ADD B ; Add two nos.
STA 4000H ; Store the result in memory location 4000H
HLT ; Stop processing
Solved Programs
Write a program to add data at memory location 3005H & 3006H and store the result at memory location 3007H. Addition without carry)
Mnemonics & operand Comments
LXI H 3005H ; Load HL pair with 3005H
MOV A, M ; Load accu with contents of memory
INX H ; Increment memory pointer
ADD M ; Add contents of memory with contents of accu
INX H ; Increment memory pointer
MOV M, A ; Store contents of accu to memory
HLT ; Stop processing
Write the program to add two 8 bit numbers stored at memory location 4150H and 4151H. Store the result at memory location 4152H and store the carry at 4153H
Mnemonics & operand Comments
MVI C, 00 'Initialize C register to 00
LDA 4150H 'Load the value to Accumulator.
MOV B, A 'Move the content of Accumulator to B register.
LDA 4151H 'Load the value to Accumulator.
ADD B 'Add the value of register B to A
JNC XXXX 'Jump on no carry.
INR C 'Increment value of register C
XXXX: STA 4152H 'Store the value of Accumulator (SUM).
MOV A, C 'Move content of register C to Acc.
STA 4153H 'Store the value of Accumulator (CARRY)
HLT 'Halt the program.
Write a program to exchange the data at 5000H& 6000H memory location.
Mnemonics & operand Comments
LDA 5000H : "Getting the contents at5000M location into accumulator"
MOV B, A : "Save the contents into B register"
LDA 6000H : "Getting the contents at 6000H location into accumulator"
STA 5000H : "Store the contents of accumulator at address 5000H"
MOV A, B : "Get the saved contents back into A register"
STA 6000H : "Store the contents of accumulator at address 6000H"
HLT : 'Halt the program.
Subtract the contents of memory location 4001H from the memory location 4000H and place the result in memory location 4002H.
Mnemonics & operand Comments
LXI H, 4000H : "Load HL pair with4000H"
MOV A, M : "Load accumulator with content of memory"
INX H : "Increment memory pointer"
SUB M : "Subtract contents of memory from contents accumulator"
INX H : " Increment memory pointer "
MOV M, A : "Store result at 4002H"
HLT : "'Halt the program "
Write the program to multiply two 8 bit numbers stored at memory location 3000H and 3001H. Store the result at memory location 3002H .
Mnemonics & operand Comments
LXI H, 3000H Load H-L pair with address 3000H.
MOV B, M Move the 1st operand from memory to reg. B.
INX H Increment H-L pair.
MOV C, M Move the 2nd operand from memory to reg. C.
MVI A, 00H Initialize accumulator with 00H.
XXXX: ADD B Add B with A.
DCR C Decrement reg. C (counter).
JNZ XXXX Jump back to address XXXX if C ≠ 0.
INX H Increment H-L pair.
MOV M, A Move the result from accumulator to memory.
HLT Halt.
Questions
Marks wise Questions: 1M(4), 3M(1), 4M(2)
1. Fill in the blanks with given alternatives.
The invalid register pair for 8085 microprocessor is -------------
(a) BC (b) HL (c) SP (d)DE
PUSH instruction in 8085 affect ---------.
(a) HL register (b) Program counter (c) Stack pointer (d) None
The instruction JNZ of 8085 microprocessor is a -----------instruction.
(a) Branching (b) Conditional branching (c) Arithmetic (d) Data transfer
The instruction MOV B, A of 8085 microprocessor is an example of ------- addressing mode
(a) Direct (b) Register indirect (c) Register (d ) Implicit
MVI A instruction of 8085uses ---------addressing mode.
(a) Direct (b) Indirect (c) Immediate
DAD B instruction adds contents of --------- register pair to BC register pair.
(a) Accumulator (b) HL (c) DE
---------- instruction is logical instruction.
(a) ADD r (b) MVI r, data (c) ANI data
The instruction JNZ of 8085 microprocessor is -------- type of instruction.
(a) Branching (b) Conditional branching (c) Data transfer
-------- flag is affected in CMA instruction.
(a) All (b) No (c) Carry
Microprocessor 8085 has ----------bit wide data bus.
(a) 8 (b) 16 (c) 32
---------instruction would not affect zero flag.
(a) SUB A (b) CMP A (c) MVI A, 00H
--------- instruction is used for 16-bit addition.
(a) ADD (b) ADI (c) DAD
2. Match the following.
A B
(i) Oval (a) Input/output
(ii) Arrow (b) Process
(iii) Rectangle (c) Decision
(iv) Parallelogram (d) Start/stop
(v) Circle (e) Flow
(v) Diamond (f) Continuation
3. Answer the following.
Define the terms-(a) Program (b) Instruction (c) Op-code/mnemonics.
Which information the instruction contains?
What do you mean by addressing modes of microprocessor?
Name the addressing modes of 8085 microprocessor.
Explain direct addressing mode of 8085 with example.
Explain register addressing mode of 8085 with example.
Explain register indirect addressing mode of 8085 with example.
Explain immediate addressing mode of 8085 with example.
Explain direct addressing mode of 8085 with example.
Explain implicit addressing mode of 8085 with example.
Write the types of instruction of 8085 microprocessor.
Explain data transfer instructions of 8085 with example.
What are data transfer instructions? List five data transfer instructions.
Explain arithmetic instructions of 8085 with example.
Explain logical instructions of 8085 with example.
Explain branching instructions of 8085 with example.
Explain control instructions of 8085 with example.
Explain the following instructions with suitable example-
(i) MOV (ii) MVI (iii) LDA (iv) LXI (v) ADD (vi) ADI (vii) SUB (viii) INR (ix) DCR
(x) ANA (xi) ORA (xii) JC (xii) JNZ (xiii) CMP (xiv) HLT (xv) PUSH
Explain different interrupts in 8085 microprocessor.
Write the steps in assembly language programming.
Write simple assembly language to store 8-bit data in memory with flowchart.
Write simple assembly language to add two 8-bit numbers in memory with flowchart.
Draw different symbols used to draw flowchart. Explain each.