Sunteți pe pagina 1din 14

CHAPTER 2

8085 Instruction set and Assembly Language Programming


Instruction: An Instruction is a binary pattern designed inside a microprocessor to perform a
specific function. The entire group of instruction is called as Instruction Set, determines what
functions the microprocessor can perform.

Instruction Format:

An Instruction is a command to the microprocessor to perform a given task on specified data.


Each instruction has two parts.
--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”. It specifies the item to be
processed. It can be 8- or 16-bit data, a register or a memory address.

Addressing Modes:
The various formats of specifying the operands are called the Addressing Modes. The 8085
instruction set has the following addressing modes.
1. Immediate Addressing Mode.
2. Register Addressing Mode.
3. Direct Addressing Mode.
4. Indirect Addressing Mode.
1. Immediate Addressing Mode: Transferring the data into register. (Eg: MOV Rs, Data).
2. Register Addressing Mode: Transferring one register content into another register. (Eg:
MOV Rd, Rs).
3. Direct Addressing Mode: Reading/Writing data directly from Input / Output. (Eg: IN 8-bit
port Address).

Instruction Set of 8085 Microprocessor:

Since the 8085 is an 8-bit device it can have up to 28 (256) instructions. However, the
8085 only uses 246 combinations that represent a total of 74 instructions. Most of the
instructions have more than one format.
These instructions can be grouped into five different groups:
1. Data Transfer (Copy) Operations.
2. Arithmetic Operations.
3. Logic Operations.
4. Branch Operations.
5. Machine Control Operations.

Data Transfer (Copy) Operations:


The group of instructions copies data from a location called a source to another location called a
destination, without modifying the contents of the source. There are different types of data
transfer operations.
S.No Type Example
1. Between registers Copy the content of Register B into Register D
Specific data byte to register or a
2. Load register B with the data byte 32H
memory location
Between a memory location and a
3. From the memory location 2000H to register B
register
Between an I/O device and the
4. From an input keyboard to the accumulator
accumulator
From register pair BC to two memory locations
5. Between a register pair and the stack
defined as the stack

Arithmetic Operations:
These operations perform arithmetic operations such as addition, subtraction, increment and
decrement.

Logical Operations:
These instructions perform various logical operations such as logical AND, OR, Exclusive-OR,
Rotate, Compare and Complement with the contents of the accumulator.

Branching Operations:
The group of instructions such as Jump, Call, Return and Restart alters the sequence of program
execution either conditionally or unconditionally.

Machine Control Instructions:


These instructions control machine functions such as Halt, Interrupt, do nothing.
Data Transfer (Copy) Instructions Set:

Opcode Operand Description Example

Copy from Source to Destination


Rd, Rs Copy the data from Rs to Rd MOV B,C

MOV M, Rs Copy the data of Rs to Memory Location MOV M, B


Rd, M Copy the data present in Memory location to Rd MOV B,M

Move Immediate 8-bit Data


Rd, data Load 8-bit data in a register Rd. MVI B, 57H
MVI
M, data Load 8-bit data in a Memory location. MVI M, 57H

Load Accumulator
Copy the data byte into the accumulator from the
LDA 16-bit Address LDA 2034H
memory location specified by 16-bit address.
Load Accumulator Indirect
Copy the data byte into the accumulator from the
LDAX B/D Reg. Pair LDAX B
memory location indicated by a register pair.
Store Accumulator Direct
Copy the data byte from the accumulator into the
STA 16-bit Address STA 4350H
memory location specified by 16-bit address.
Store Accumulator Indirect
Copy the data byte from the accumulator into the
STAX Reg. Pair STAX B
memory location indicated by a register pair.
Load Register pair Immediate
Reg. Pair, 16-
LXI Load 16-bit data into a register pair LXI H, 2034H
bit data
Writing data to a Output device
8-bit (Port Send (write) data byte from accumulator to an
OUT OUT PORT1
Address) output device.
Reading data from an Input Device
8-bit (Port Accept (read) data byte from an input device and
IN IN PORT0
Address) place it in the accumulator.
Arithmetic Instruction Set:

Operand Description Example


Opcode
Add Register or Memory to Accumulator
Add the contents of register to contents of
R
accumulator
ADD ADD B
Add the contents of a memory location to
M
contents of accumulator.

Add Register or Memory to Accumulator with carry


Add the contents of register to contents of
R
accumulator with carry.
ADC ADC B
Add the contents of a memory location to
M
contents of accumulator with carry.

Add immediate data to accumulator

ADI 8-bit Data Add 8-bit data to contents of accumulator ADI 45H

Add immediate data to accumulator with carry


Add 8-bit data to contents of accumulator with
ACI 8-bit Data ACI 45H
carry.
Add register pair to H and L registers
Add the contents of register pair with contents of
DAD Reg. Pair DAD H
registers H and L
Subtract Register or Memory to Accumulator
Subtract the contents of register to contents of
R
accumulator
SUB SUB B
Subtract the contents of a memory location to
M
contents of accumulator.

Subtract Register or Memory to Accumulator with barrow


Subtract the contents of register to contents of
R
accumulator with barrow.
SBB SBB B
Subtract the contents of a memory location to
M
contents of accumulator with barrow.
Subtract immediate data to accumulator

SUI 8-bit Data Subtract 8-bit data to contents of accumulator SUI 45H

Subtract immediate data to accumulator with barrow


Subtract 8-bit data to contents of accumulator
SBI 8-bit Data SBI 45H
with barrow.
Increment Register or Memory by 1
R Increment the contents of a register by 1
INR INR B
M Increment the contents of a memory location by 1

Increment Register Pair by 1

INX R Increment the contents of a register pair by 1 INX H

Decrement Register or Memory by 1


R Decrement the contents of a register by 1
DCR DCR B
M Decrement the contents of a memory location

Increment Register Pair by 1

DCX R Decrement the contents of a register pair by 1 DCX H


Logical Instructions Set:

Opcode Operand Description Example

Compare Register or Memory with Accumulator


Compare the contents of register with contents of
R
accumulator for <1, >1 or =1.
CMP CMP B
Compare the contents of a memory location with
M
contents of accumulator for <1, >1 or =1.

Compare immediate with Accumulator


Compare 8-bit Data with contents of accumulator
CPI 8-bit Data CPI 89H
for <1, >1 or =1.

Logical AND Register or Memory with Accumulator


Logically AND the contents of register with
R
contents of Accumulator.
ANA ANA B
Logically AND the contents of Memory with
M
contents of Accumulator.

Logical AND immediate with Accumulator


Logically AND 8-bit data with contents of
ANI 8-bit Data ANI 89H
Accumulator.

Logical OR Register or Memory with Accumulator


Logically OR the contents of register with
R
contents of Accumulator.
ORA ORA B
Logically OR the contents of Memory with
M
contents of Accumulator.

Logical OR immediate with Accumulator


Logically OR 8-bit data with contents of
ORI 8-bit Data ORI 89H
Accumulator.

Logical Exclusive-OR Register or Memory with Accumulator


R Logically Exclusive-OR the contents of register
XRA XRA B
with contents of Accumulator.
M Logically Exclusive-OR the contents of Memory
with contents of Accumulator.

Logical Exclusive-OR immediate with Accumulator


Logically Exclusive-OR 8-bit data with contents
XRI 8-bit Data XRI 89H
of Accumulator.

Complement Accumulator

CMA Complement the contents of Accumulator CMA

Rotate each bit of Accumulator to Left/Right with/Without Carry


Rotate each bit in the accumulator to the left
RLC RLC
position.
Rotate each bit in the accumulator including carry
RAL RAL
to the left position.
Rotate each bit in the accumulator to the right
RRC RRC
position.
Rotate each bit in the accumulator including carry
RAR RAR
to the right position.
Branch Instruction Set:

Opcode Operand Description Example

Jump Unconditionally

Change the program sequence to the location


JMP 16-bit Address JMP 2034H
specified by the 16-bit address

Jump Conditionally

JC 16-bit Address Jump to 16-bit address on Carry CY=1 JC 2034H

JNC 16-bit Address Jump to 16-bit address on No Carry CY=0 JNC 2034H

JP 16-bit Address Jump to 16-bit address on Positive S=0(Sign flag) JP 2034H

JM 16-bit Address Jump to 16-bit address on Negative S=1 JM 2034H

JZ 16-bit Address Jump to 16-bit address on Zero flag Z=1 JZ 2034H

JNZ 16-bit Address Jump to 16-bit address on No Zero flag Z=0 JNZ 2034H

JPE 16-bit Address Jump to 16-bit address on parity flag even P =1 JPE 2034H

JPO 16-bit Address Jump to 16-bit address on parity flag odd P =0 JPO 2034H

Call Unconditionally
Change the program sequence to the location of a
CALL 16-bit Address CALL 2034H
sub routine specified by the 16-bit address
Call Conditionally

CC 16-bit Address Call a routine on 16-bit address on Carry CY=1 CC 2034H


Call a routine on 16-bit address on No Carry
CNC 16-bit Address CNC 2034H
CY=0
Call a routine on 16-bit address on Positive
CP 16-bit Address CP 2034H
S=0(Sign flag)
CM 16-bit Address Call a routine on 16-bit address on Negative S=1 CM 2034H

CZ 16-bit Address Call a routine on 16-bit address on Zero flag Z=1 CZ 2034H
Call a routine on 16-bit address on No Zero flag
CNZ 16-bit Address CNZ 2034H
Z=0
Call a routine on 16-bit address on parity flag
CPE 16-bit Address CPE 2034H
even P =1
Call a routine on 16-bit address on parity flag odd
CPO 16-bit Address CPO 2034H
P =0
Return from a subroutine Unconditionally
Return from the calling program after completing
RET RET
the subroutine sequence.
Return from a subroutine Unconditionally

RC Return on Carry CY=1 RC 2034H

RNC Return No Carry CY=0 RNC 2034H

RP Return on Positive S=0(Sign flag) RP 2034H

RM Return on Negative S=1 RM 2034H

RZ Return on Zero flag Z=1 RZ 2034H

RNZ Return on No Zero flag Z=0 RNZ 2034H

RPE Return on parity flag even P =1 RPE 2034H

RPO Return on parity flag odd P =0 RPO 2034H

Machine Control Instructions:

HLT  Stop processing and wait.

NOP  Do not perform any operation.


Writing Assembly Language Programming:

A microprocessor performs a task by reading and executing the set of instructions written in its
memory. This set of instructions, written in a sequence is called a program. Writing a program
is equivalent to giving specific commands to the microprocessor in a sequence to perform a task.
Steps:
Step 1: Read the problem carefully.
Step 2: Break it down into small steps.
Step 3: Represent these small steps in a possible sequence with a flowchart.
Step 4: Translate each block of flow chart into appropriate mnemonic instruction.
Step 5: Translate mnemonics into the machine code.
Step 6: Enter the machine code in memory and execute.
Step 7: Start troubleshooting.

Sample Program 1:

Problem Statement: Write a program to perform the following functions and verify the output.
1. Load register B with Number 37H.
2. Send the number to the output port.
Assembly Language Program:
Tasks to perform the operation: 1. Load register B with 37H.
2. Move the contents of register B to register A.
3. Send the number to the output port 01H.
4. End of program.
Assembly Language Code corresponding to each task:
MVI B, 37H  Moves immediate data of 37H into register B.
MOV A, B  Moves the contents of register B to Accumulator register A.
OUT, PORT1  this instruction sends the accumulator contents to output port.
HLT  end of program (Do Nothing).
Sample Program 2:

Problem Statement: Write a program to perform the following functions and verify the output.
1. Load the number 8BH in register D.
2. Load the number 6FH in register C.
3. Increment the contents of register C by one.
4. Add the contents of registers C and D and display the sum at the output port1.
Assembly Language Code corresponding to each task:
MVI D, 8BH  Moves immediate data of 8BH into register D.
MVI C, 6FH  Moves immediate data of 6FH into register C.
INR C  Increments the contents of register C by 1.
MOV A, C  Moves the contents of register C into accumulator register A.
ADD D  Adds the contents of register D to contents of accumulator register A.
OUT PORT1  this instruction sends the accumulator contents to output port.
HLT  end of program (Do Nothing).
Sample Program 3:

Problem Statement: Write a program to perform the following functions and verify the output.
1. Load the number 30H in register B.
2. Load the number 39H in register C.
3. Subtract 39H from 30H.
4. Display the answer at output port1.
Assembly Language Code corresponding to each task:
MVI B, 30H  Moves immediate data of 30H into register B.
MVI C, 39H  Moves immediate data of 39H into register C.
MOV A, B  Moves the contents of register B into accumulator register A.
SUB C  subtracts the contents of register C from contents of accumulator
register A.
OUT PORT1  this instruction sends the accumulator contents to output port.
HLT  end of program (Do Nothing).
Sample Program 4:

Problem Statement: Write a program to perform the following functions and verify the output.
 Store the data byte 32H into memory location 4000H.
Assembly Language Code corresponding to each task:
MVI A, 32H  Moves immediate data of 32H into accumulator register A.
STA 4000H  copies the accumulator register contents to 4000H memory location.
HLT  end of program (Do Nothing).
Sample Program 5:

Problem Statement: Write a program to perform the following functions and verify the output.
 Exchange the contents of memory locations 2000H to 4000H
Assembly Language Code corresponding to each task:
LDA 2000H  gets the contents in 2000H memory location into accumulator A.
MOV B, A  stores the contents of accumulator register A into register B.
LDA 4000H  gets the contents in 2000H memory location into accumulator A.
STA 2000H  copies the accumulator register contents to 2000H memory location.
MOV A, B  stores the contents of register B into accumulator register A.
STA 4000H  copies the accumulator register contents to 4000H memory location.
HLT  end of program (Do Nothing).
Sample Program 6:

Problem Statement: Write a program to perform the following functions and verify the output.
 Find the 2's complement of the number stored at memory location 4200H and store the
complemented number at memory location 4300H.
Assembly Language Code corresponding to each task:
LDA 4200H  gets the contents in 4200H memory location into accumulator A.
CMA  complement the accumulator register A contents.
ADI 01H  add the contents of accumulator register with immediate data 01H.
STA 4300H  copies the accumulator register contents to 4300H memory location.
HLT  end of program (Do Nothing).
Sample Program 7:

Problem Statement: Write a program to perform the following functions and verify the output.
 Find the 1’s complement of the number stored at memory location 2200Hand store the
complemented number at memory location 2300H.
Assembly Language Code corresponding to each task:
LDA 2200H  gets the contents in 2200H memory location into accumulator A.
CMA  complement the accumulator register A contents.
STA 2300H  store the accumulator register contents in 2300H memory location.
HLT  terminate the program.

ADDRESSING MODES
Every instruction of a program has to operate on a data. The method of specifying the
data to be operated by the instruction is called Addressing.
The 8085 has the following 5 different types of addressing.
1. Immediate Addressing Mode
2. Direct Addressing Mode
3. Register Addressing Mode
4. Register Indirect Addressing Mode
5. Implied Addressing Mode
Immediate Addressing
In immediate addressing mode, the data is specified in the instruction itself. The data
will be apart of the program instruction. All instructions that have ‘I’ in their
mnemonics are of Immediate addressing type.
Eg.MVI B, 3EH- Move the data 3EH given in the instruction to B register.

Direct Addressing
In direct addressing mode, the address of the data is specified in the instruction. The data
will be in memory. In this addressing mode, the program instructions and data can be
stored in different memory blocks. This type of addressing can be identified by 16-bit
address present in the instruction.
Eg.LDA 1050H- Load the data available in memory location 1050H in accumulator.

Register Addressing
In register addressing mode, the instruction specifies the name of the register in which
the data is available. This type of addressing can be identified by register names (such
as ‘A’, ‘B’....) in the instruction.
Eg. MOV A, B -Move the content of B register to A register.
Register Indirect Addressing
In register indirect addressing mode, the instruction specifies the name of the register in
which the address of the data is available. Here the data will be in memory and the
address will be in the register pair. This type of addressing can be identified by letter
‘M’ present in the instruction.
Eg. MOV A, M - The memory data addressed by HL pair is moved to A register.

Implied Addressing
In implied addressing mode, the instruction itself specifies the type of operation and
location of data to be operated. This type of instruction does not have any address,
register name, immediate data specified along with it. Eg. CMA - Complement the
content of accumulator.

S-ar putea să vă placă și