Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
78 views

Assembly Language Programming Using 8085

The document discusses the Intel 8085 microprocessor including its functional blocks, pin configuration, timing and control unit, registers, data and address bus, operation codes, addressing modes, interrupts, flags, and instructions. It provides details on the 8085 instruction set including data transfer, arithmetic, logic, branch, and machine control instructions.

Uploaded by

Yogendra Kshetri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Assembly Language Programming Using 8085

The document discusses the Intel 8085 microprocessor including its functional blocks, pin configuration, timing and control unit, registers, data and address bus, operation codes, addressing modes, interrupts, flags, and instructions. It provides details on the 8085 instruction set including data transfer, arithmetic, logic, branch, and machine control instructions.

Uploaded by

Yogendra Kshetri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Unit-02: Intel 8085

➢ Functional Block Diagram and Pin Configuration,


➢ Timing and control Unit, Registers, Data and Address Bus,
➢ Operation Code and Operands, Addressing Modes, Interrupts, Flags, Instructions and Data Flow
inside 8085,
➢ Intel 8085 Instructions (8085 Instructions: Data Transfer: MOV, IN, OUT, STA, LDA, LXI, LDAX,
STAX, XCHG; Arithmetic and Logic: - ADD, SUB, INR, DCR, AND, OR, XOR; CMP, RLC, RRC, RAL, RAR;
Branching: - JMP, JNZ, JZ, JNC, JC,)
➢ Basic Assembly Language Programming Using 8085 Instruction Sets

Table of Contents
1. Introduction to Microprocessors ........................................................... Error! Bookmark not defined.
Components of microprocessor: .................................................... Error! Bookmark not defined.
Summary: ......................................................................................... Error! Bookmark not defined.
Evolution of microprocessor .......................................................... Error! Bookmark not defined.
Advantages of Microprocessor: ..................................................... Error! Bookmark not defined.
Applications of Microprocessors: .................................................. Error! Bookmark not defined.
2. Microprocessor system with bus organization ...................................... Error! Bookmark not defined.
3. Microprocessor architecture and operation.......................................... Error! Bookmark not defined.
1. Microprocessor-Initiated Operations and 8085/8080A Bus OrganizationError! Bookmark
not defined.
2. Internal Data Operations and the 8085/8080A Registers ....... Error! Bookmark not defined.
3. Peripheral or Externally Initiated Operations: ......................... Error! Bookmark not defined.
4. 8085 Microprocessor and its operation................................................. Error! Bookmark not defined.
1. Functional Block Diagram and Pin Configuration

See Slides….

2. Intel 8085 Instructions

See Slides….

3. Operation Code and Operands

See Slides….

4. Addressing Modes

See Slides….

5. Interrupts
When microprocessor receives any interrupt signal from peripheral(s) which are requesting its services, it
stops its current execution and program control is transferred to a sub-routine by generating CALL signal
and after executing sub-routine by generating RET signal again program control is transferred to main
program from where it had stopped.

When microprocessor receives interrupt signals, it sends an acknowledgement (INTA) to the peripheral
which is requesting for its service.

Interrupts can be classified into various categories based on different parameters:

Hardware and Software Interrupts:


When microprocessors receive interrupt signals through pins (hardware) of microprocessor, they are
known as Hardware Interrupts. There are 5 Hardware Interrupts in 8085 microprocessor. They are – INTR,
RST 7.5, RST 6.5, RST 5.5, TRAP

Software Interrupts are those which are inserted in between the program which means these are
mnemonics of microprocessor. There are 8 software interrupts in 8085 microprocessor. They are – RST 0,
RST 1, RST 2, RST 3, RST 4, RST 5, RST 6, RST 7.
Vectored and Non-Vectored Interrupts:
Vectored Interrupts are those which have fixed vector address (starting address of sub-routine) and after
executing these, program control is transferred to that address.

INTERRUPT VECTOR ADDRESS


TRAP 24 H
RST 5.5 2C H
RST 6.5 34 H
RST 7.5 3C H

For Software interrupts, vector addresses are given as below. Vector Addresses are calculated by the
formula 8 * TYPE

INTERRUPT VECTOR ADDRESS


RST 0 00 H
RST 1 08 H
RST 2 10 H
RST 3 18 H
RST 4 20 H
RST 5 28 H
RST 6 30 H
RST 7 38 H

Non-Vectored Interrupts are those in which vector address is not predefined. The interrupting device gives
the address of sub-routine for these interrupts. INTR is the only non-vectored interrupt in 8085
microprocessor.

Maskable and Non-Maskable Interrupts:

Maskable Interrupts are those which can be disabled or ignored by the microprocessor. These interrupts
can be disabled. INTR, RST 7.5, RST 6.5, RST 5.5 are maskable interrupts in 8085 microprocessor.

Non-Maskable Interrupts are those which cannot be disabled or ignored by microprocessor. TRAP is a
non-maskable interrupt. It is used in critical power failure conditions.

Priority of Interrupts:

When microprocessor receives multiple interrupt requests simultaneously, it will execute the interrupt
service request (ISR) according to the priority of the interrupts.
6. Flags

See Slides….

7. Basic Assembly Language Programming Using 8085 Instruction Sets


The 8085-microprocessor instruction set has 74 operation codes that result in 246 instructions.
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 Operations


2. Arithmetic Operations
3. Logic Operations
4. Branch Operations
5. Machine Control Operations

1. Data transfer instructions in 8085-microprocessor:


Data transfer instructions are the instructions which transfers data in the microprocessor. They are also
called copy instructions.
OPCODE OPERAND EXPLANATION EXAMPLE

MOV Rd, Rs Rd = Rs MOV A, B


MOV Rd, M Rd = Mc MOV A, M
MOV M, Rs M = Rs MOV M, A
MVI Rd, 8-bit data Rd = 8-bit data MVI A, 50
MVI M, 8-bit data M = 8-bit data MVI M, 50
LDA 16-bit address A = contents at address LDA 2050
STA 16-bit address contents at address = A STA 2050
LXI r.p., 16-bit data loads the specified register pair with data LXI H, 3050
LDAX r.p. indirectly loads at the accumulator A LDAX H
STAX 16-bit address indirectly stores from the accumulator A STAX B
SHLD 16 bit address Store HL pair vaue in two consecutive SHLD 2500
address address 2500 and 2501
LHLD 16 bit address Load HL register from two consecutive LHLD 2500
address to H and L Register
XCHG none exchanges H with D, and L with E XCHG
PUSH r.p. pushes r.p. to the stack PUSH H
POP r.p. pops the stack to r.p. POP H
IN 8-bit port address inputs contents of the specified port to A IN 15
OUT 8-bit port address outputs contents of A to the specified port OUT 15

2. Arithmetic instructions in 8085-microprocessor:


Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition,
subtraction and a few more. In 8085 microprocessor, the destination operand is generally the
accumulator. In 8085 microprocessor, the destination operand is generally the accumulator.
Following is the table showing the list of arithmetic instructions:

OPCODE OPERAND EXPLANATION EXAMPLE

ADD R A=A+R ADD B


ADD M A = A + Mc ADD M
ADI 8-bit data A = A + 8-bit data ADD 50
ADC R A = A + R + prev. carry ADC B
ADC M A = A + Mc + prev. carry ADC M
ACI 8-bit data A = A + 8-bit data + prev. carry ACI 50
SUB R A=A–R SUB B
SUB M A = A – Mc SUB M
SUI 8-bit data A = A – 8-bit data SUI 50
SBB R A = A – R – prev. carry SBB B
SBB M A = A – Mc -prev. carry SBB M
SBI 8-bit data A = A – 8-bit data – prev. carry SBI 50
INR R R=R+1 INR B
INR M M = Mc + 1 INR M
INX r.p. r.p. = r.p. + 1 INX H
DCR R R=R–1 DCR B
DCR M M = Mc – 1 DCR M
DCX r.p. r.p. = r.p. – 1 DCX H
DAD r.p. HL = HL + r.p. DAD H

Note: In the table,


R stands for register
M stands for memory
Mc stands for memory contents
r.p. stands for register pair

3. Logical instructions in 8085 microprocessor:


Logical instructions are the instructions which perform basic logical operations such as AND, OR, etc. In
8085 microprocessor, the destination operand is always the accumulator. Here logical operation works
on a bitwise level.

OPCODE OPERAND DESTINATION EXAMPLE

ANA R A = A AND R ANA B


CMC none Compliments the carry flag CMC
STC none Sets the carry flag STC
ANA M A = A AND Mc ANA 2050
ANI 8-bit data A = A AND 8-bit data ANI 50
ORA R A = A OR R ORA B
ORA M A = A OR Mc ORA 2050
ORI 8-bit data A = A OR 8-bit data ORI 50
XRA R A = A XOR R XRA B
XRA M A = A XOR Mc XRA 2050
XRI 8-bit data A = A XOR 8-bit data XRI 50
CMA none A = 1’s compliment of A CMA
CMP R Compares R with A and triggers the flag register CMP B
CMP M Compares Mc with A and triggers the flag CMP 2050
register
CPI 8-bit data Compares 8-bit data with A and triggers the flag CPI 50
register
RRC none Rotate accumulator right without carry RRC
RLC none Rotate accumulator left without carry RLC
RAR none Rotate accumulator right with carry RAR
RAL none Rotate accumulator left with carry RAR
Note: In the table,
R stands for register
M stands for memory
Mc stands for memory contents

4. Branching instructions in 8085 microprocessor:

Branching instructions refer to the act of switching execution to a different instruction sequence as a
result of executing a branch instruction. The three types of branching instructions are:

1) Jump (unconditional and conditional)


2) Call (unconditional and conditional)
3) Return (unconditional and conditional)
1. Jump Instructions – The jump instruction transfers the program sequence to the memory address
given in the operand based on the specified flag. Jump instructions are 2 types: Unconditional Jump

OPCODE OPERAND EXPLANATION EXAMPLE

JMP address Jumps to the address JMP 2050


Instructions and Conditional Jump Instructions.

(a) Unconditional Jump Instructions: Transfers the program sequence to the described
memory address.

(b) Conditional Jump Instructions: Transfers the program sequence to the described memory
address only if the condition in satisfied.
OPCODE OPERAND EXPLANATION EXAMPLE

JNC address Jumps to the address if carry flag is 0 JNC 2050


JZ address Jumps to the address if zero flag is 1 JZ 2050
JNZ address Jumps to the address if zero flag is 0 JNZ 2050
JPE address Jumps to the address if parity flag is 1 JPE 2050
JPO address Jumps to the address if parity flag is 0 JPO 2050
JM address Jumps to the address if sign flag is 1 JM 2050
JP address Jumps to the address if sign flag 0 JP 2050

2. Call Instructions – The call instruction transfers the program sequence to the memory address
given in the operand. Before transferring, the address of the next instruction after CALL is pushed
onto the stack. Call instructions are 2 types: Unconditional Call Instructions and Conditional Call
Instructions.

(a) Unconditional Call Instructions: It transfers the program sequence to the memory address given in
the operand.

OPCODE OPERAND EXPLANATION EXAMPLE

CALL address Unconditionally calls CALL 2050

(b)Conditional Call Instructions: Only if the condition is satisfied, the instructions execute.

OPCODE OPERAND EXPLANATION EXAMPLE

JC address Jumps to the address if carry flag is 1 JC 2050


OPCODE OPERAND EXPLANATION EXAMPLE

CC address Call if carry flag is 1 CC 2050


CNC address Call if carry flag is 0 CNC 2050
CZ address Calls if zero flag is 1 CZ 2050
CNZ address Calls if zero flag is 0 CNZ 2050
CPE address Calls if parity flag is 1 CPE 2050
CPO address Calls if parity flag is 0 CPO 2050
CM address Calls if sign flag is 1 CM 2050
CP address Calls if sign flag is 0 CP 2050

3. Return Instructions – The return instruction transfers the program sequence from the subroutine to
the calling program. Jump instructions are 2 types: Unconditional Jump Instructions and Conditional Jump
Instructions.

(a) Unconditional Return Instruction: The program sequence is transferred unconditionally from the
subroutine to the calling program.

OPCODE OPERAND EXPLANATION EXAMPLE

RET none Return from the subroutine unconditionally RET

(b) Conditional Return Instruction: The program sequence is transferred unconditionally from the
subroutine to the calling program only is the condition is satisfied.

OPCODE OPERAND EXPLANATION EXAMPLE

RC none Return from the subroutine if carry flag is 1 RC


RNC none Return from the subroutine if carry flag is 0 RNC
RZ none Return from the subroutine if zero flag is 1 RZ
RNZ none Return from the subroutine if zero flag is 0 RNZ
RPE none Return from the subroutine if parity flag is 1 RPE
RPO none Return from the subroutine if parity flag is 0 RPO
RM none Returns from the subroutine if sign flag is 1 RM
RP none Returns from the subroutine if sign flag is 0 RP

5. The Machine Control instructions are as follows:


HLT - Halt

NOP - No Operation

8. Basic Assembly Language Programming using 8085 Instruction Sets


• Instruction and Data Format
• Mnemonics and Operands
Note: Read Page 55 from Ramesh Gaonkar book
Machine Code:

9. Mnemonics and Operands


The difference between mnemonic and opcode is that mnemonic is anything (especially something in
verbal form) used to help remember something while opcode is (computing) a mnemonic used to refer to
a microprocessor instruction in assembly language.

10. Assembly Language program

ADDITION OF TWO 8-BIT NUMBERS:


Problem: To write 8085 assembly language for adding two 8-bit numbers.

Algorithm:
Step1: Start the microprocessor
Step2: Initialize the carry as Zero
Step3: Load the first 8-bit data into the accumulator
Step4: Copy the contents of accumulator into the register B
Step5: Load the second 8-bit data into the accumulator.
Step6: Add the 2 - 8-bit datas and check for carry.
Step7: Jump on if no carry
Step8: Increment carry if there is
Step9: Store the added request in accumulator
Step10: More the carry value to accumulator
Step11: Store the carry value in accumulator
Step12: Stop the program execution.

Algorithm:
SUBTRACTION OF TWO 8 BIT NUMBERS
Problem: Write 8085 assembly language program for subtracting 2 bit (8) numbers.

Algorithm –
6. Load 00 in a register C (for borrow)
7. Load two 8-bit number from memory into registers
8. Move one number to accumulator
9. Subtract the second number with accumulator
10. If borrow is not equal to 1, go to step 7
11. Increment register for borrow by 1
12. Store accumulator content in memory
13. Move content of register into accumulator
14. Store content of accumulator in other memory location
15. Stop
Program –

Memory Mnemonics Operands Comment


2000 MVI C, 00 [C] <- 00
2002 LHLD 2500 [H-L] <- [2500]
2005 MOV A, H [A] <- [H]
2006 SUB L [A] <- [A] – [L]
2007 JNC 200B Jump If no borrow
200A INR C [C] <- [C] + 1
200B STA 2502 [A] -> [2502], Result
200E MOV A, C [A] <- [C]
2010 STA 2503 [A] -> [2503], Borrow
2013 HLT Stop
Result: The assembly language program subtraction of two 8 bit numbers was executed successfully by
using 8085 assembler or micro processing kit.

ADDITION OF TWO 16 – BIT NUMBERS


Problem: Write an assembly language program for adding two 16-bit numbers using 8085 assembler and
microprocessor kit.

Algorithm:

Step1: Start the microprocessor


Step2: Get the 1st 8 bit in C register (LSB) and 2nd 8 bit in H register (MSB) of 16 bit number.
Step3: Save the 1st 16 bit in DE register pair
Step4: Similarly get the 2nd 16-bit number and store it in HL register pair.
Step5: Get the lower byte of 1st number into L register
Step6: Add it with lower byte of 2nd number
Step7: tore the result in L register
Step8: Get the higher byte of 1st number into accumulator
Step9: Add it with higher byte of 2nd number and carry of the lower bit addition.
Step10: Store the result in H register
Step11: Store 16-bit addition value in HL register pair
Step12: Stop program execution
Result: The assembly language program for addition of two 16-bit numbers was executed using 8085
assembler and micro processing kit.

SUBTRACTION OF TWO 16 – BIT NUMBERS


Problem: Write 8085 assembly language program for subtracting two 16-bit numbers using 8085
microprocessor kit.
Algorithm:
Step1: Start the microprocessor
Step2: Get the 1st 16 bit in „HL‟ register pair
Step3: Save the 1st 16 bit in „DE‟ register pair
Step4: Get the 2nd 16 bit number in „HL‟ register pair
Step5: Get the lower byte of 1st number
Step6: Get the subtracted value of 2nd number of lower byte by subtracting it with lower byte of 1st
number
Step7: Store the result in „L‟ register
Step8: Get the higher byte of 2nd number
Step9: Subtract the higher byte of 1st number from 2nd number with borrow
Step10: Store the result in „HL‟ register
Step11: Stop the program execution
Result: The assembly language program for subtraction of two 16-bit numbers was executed by using
8085 assembler and micro processing kit.

MULTIPLICATION OF TWO 8 – BIT NUMBERS


Problem: Write 8085 assembly language for multiplying two 8-bit numbers by using 8085 assembler and
micro processor kit.

Algorithm:
Step1: Start the microprocessor
Step2: Get the 1st 8 bit numbers
Step3: Move the 1st 8it number to register B
Step4: Get the 2nd 8 bit number
Step5: Move the 2nd 8 bit number to register C
Step6: Initialize the accumulator as zero
Step7: initialize the carry as zero
Step8: Add both register B value as accumulator
Step9: Jump on if no carry
Step10: Increment carry by 1 if there is
Step11: Decrement the 2nd value and repeat from step 8, till the 2nd value becomes zero.
Step12: Store the multiplied value in accumulator
Step13: Move the carry value to accumulator
Step14: Store the carry value in accumulator
Result: The assembly language program for multiplication of two 8-bit numbers was executed using 8085
assembler and micro processing kit.

DIVISION OF TWO 8 – BIT NUMBERS


Problem: Write 8085 assembly language program for dividing two 8 bit numbers using assembler and
microprocessor kit.

Algorithm:

Step1: Start the microprocessor


Step2: initialize the Quotient as zero
Step3: Load the 1st 8 bit data
Step4: Copy the contents of accumulator into register B
Step5: Load the 2nd 8 bit data
Step6: Compare both the values
Step7: Jump if divisor is greater than dividend
Step8: Subtract the dividend value by divisor value
Step9: Increment Quotient
Step10: Jump to step 7, till the dividend becomes zero
Step11: Store the result (Quotient) value in accumulator
Step12: Move the remainder value to accumulator
Step13: Store the result in accumulator
Step14: Stop the program execution
Result: The assembly language program for division of two 8-bit numbers was executed using 8085
assembler and micro processing kit.

Problem: Write a program for multiplication of two 8-bit numbers by repeated addition method.

Label Mnemonics Operands Comments

MVI C,25 ; Move the no in reg C


MVI E,05 ; Move the no. in reg E
MVI B,00 ; Clear register B
LXI H,0000 ; Initial product = 0000
UP1: DAD B ; HL+BC -> HL
DCR E ; Decrement reg E
JNZ UP1 ; Jump if not zero to location UP1
SHLD 2500 ; Store HL at 2500
HLT

Problem: Write a program for division of two 8-bit numbers by repeated subtraction method.

Label Mnemonics Operands Comments

LDA 2000H ; Load Divisor from address 2000H


MOV B, A ; Take divisor in reg A
LDA 2002H ; Take dividend in reg A
MVI C,00 ; Quotient=00
CMP B ;
JC Loop ;
SUB B ; Dividend – Divisor ->A
INR C ; C= C+1
CMP B ; Is dividend < divisor
JNC Loop1 ; If not, go back
STA 2003 ; Store Remainder
MOV A, C
STA 2004 ; Store Quotient
HLT ; Terminate

Problem – Multiply two 8-bit numbers stored at address 2050 and 2051. Result is
stored at address 3050 and 3051. Starting address of program is taken as 2000.

Algorithm:
1. We are taking adding the number 43 seven (7) times in this example.
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair
to store the result.
Program:
Memory Address Mnemonics Comment
2000 LHLD 2050 H←2051, L←2050
2003 XCHG H↔D, L↔E
Memory Address Mnemonics Comment
2004 MOV C, D C←D
2005 MVI D 00 D←00
2007 LXI H 0000 H←00, L←00
200A DAD D HL←HL+DE
200B DCR C C←C-1
200C JNZ 200A If Zero Flag=0, goto 200A
200F SHLD 3050 H→3051, L→3050
2012 HLT

Explanation:
Registers used: A, H, L, C, D, E

1. LHLD 2050 loads content of 2051 in H and content of 2050 in L


2. XCHG exchanges contents of H with D and contents of L with E
3. MOV C, D copies content of D in C
4. MVI D 00 assigns 00 to D
5. LXI H 0000 assigns 00 to H and 00 to L
6. DAD D adds HL and DE and assigns the result to HL
7. DCR C decrements C by 1
8. JNZ 200A jumps program counter to 200A if zero flag = 0
9. SHLD stores value of H at memory location 3051 and L at 3050
10. HLT stops executing the program and halts any further execution

Another approach:
We can do multiplication of two 8-bit numbers without using DAD and XCHG
command.
Program:
ADDRESS MNEMONICS COMMENT
2000 LXI H, 2050H
2003 MOV B, M B←M
2004 INX H
2005 MOV C, M C←M
2006 MVI A, 00H A←00
2008 TOP: ADD B A<-A+B
2009 DCR C C←C-1
200A JNZ TOP
200D INX H
200E MOV M, A M←A
200F HLT terminate the program
Explanation: Registers A, H, L, C, B are used for general purpose.
1. LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
2. MOV B, M copies the content of memory into register B.

8085 program to divide two 8-bit numbers:

Problem – Write 8085 program to divide two 8-bit numbers.


Example:

Algorithm:
1. Start the program by loading the HL pair registers with address of memory location.
2. Move the data to B Register.
3. Load the second data into accumulator.
4. Compare the two numbers to check carry.
5. Subtract two numbers.
6. Increment the value of carry.
7. Check whether the repeated subtraction is over.
8. Then store the results(quotient and remainder) in given memory location.
9. Terminate the program.
Program:
ADDRESS MNEMONICS COMMENT
2000 LXI H, 2050
2003 MOV B, M B<-M
2004 MVI C, 00 C<-00H
2006 INX H
2007 MOV A, M A<-M
2008 CMP B
2009 JC 2011 check for carry
200C SUB B A<-A-B
200D INR C C<-C+1
200E JMP 2008
2011 STA 3050 3050<-A
2014 MOV A, C A<-C
2015 STA 3051 3051<-A
2018 HLT terminate the program

Explanation: Registers A, H, L, C, B are used for general purpose.


1. LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
2. MOV B, M copies the content of memory into register B.
3. MVI C, 00 assign 00 to C.
4. INX H increment register pair HL.
5. MOV A, M copies the content of memory into accumulator.
6. CMP B compares the content of accumulator and register B.
7. JC 2011 jump to address 2011 if carry flag is set.
8. SUB B subtract the content of accumulator with register B and store the result in accumulator.
9. INR C increment the register C.
10. JMP 2008 control will shift to memory address 2008.
11. STA 3050 stores the remainder at memory location 3050.
12. MOV A, C copies the content of register into accumulator.
13. STA 3051 stores the remainder at memory location 3051.
14. HLT stops executing the program and halts any further execution.
Problem: A dividend is stored in memory location 2020H and a divisor is stored in 2021H. WAP to divide
these numbers and store quotient and remainder from 2040H.

MVI C, 00H
LXI H, 2021H
MOV A, M
MOV D, A
DCX H
MOV B, M
L2: MOV A, B
SUB D
JC L1
MOV B, A
INR C
JMP L2
L1: MOV L, C
MOV H, B
SHLD 2040H
HLT
11. Simple Sequence Programs, Branching, Looping
Problem: Sixteen data are stored in memory location at 2050H to 205FH. Transfer the entire block of data
to new location starting at 2070H.
Memory Address Content
2050 45
LXI H, 2050H 2051 23
MVI C, 10H 2052
LXI D, 2070H 2053
2054
L1: MOV A, M 2055
STAX D ; Transfer to new location 2070, … 2056
2057
INX H ; Increment first data address 2058
INX D ; Increment 2nd data address 2059
DCR C 205A
205B
JNZ L1 205C
HLT 205D
205E
205F
Problem: Add two numbers located at 2030H and 2040H. Store sum on 2050H. If carry is generated,
display it on 2051.

LDA 2030H
MOV B, A
LDA 2040H
ADD B
STA 2050H
JNC L1
MVI A, 01H
OUT 2051H
L1: HLT

Problem 05: Six bytes are stored in memory locations starting at 2050H. Add all the data bytes, save any
carry generated while adding the data bytes. Store total carry in 2070H and sum in 2071H.
LXI H, 2050H
MVI C, 06H
MVI B, 00H
MVI D, 00H
L2: MOV A, M
ADD B
MOV B, A
JNC L1
INR D
L1: INX H
DCR C
JNZ L2
HLT

12. Array (Sorting) and Table Processing


ASCENDING ORDER
Problem: To write a program to sort given n numbers in ascending order

Algorithm:

Step1: Start the microprocessor


Step2: Accumulator is loaded with number of values to sorted and it is saved
Step3: Decrement 8 register (N-1) Repetitions)
Step4: Set HL register pair as data array
Step5: Set C register as counter for (N-1) repetitions
Step6: Load a data of the array in accumulator
Step7: Compare the data pointed in HL pair
Step8: If the value of accumulator is smaller than memory, then jump to step 10.
Step9: Otherwise exchange the contents of HL pair and accumulator
Step10: Decrement C register, if the of C is not zero go to step 6
Step11: Decrement B register, if value of B is not zero, go step 3
Step12: Stop the program execution
Result: The assembly language program for sorting numbers in ascending order was executed by
assembler and microprocessor kit.

DESCENDING ORDER
Problem: To write a program to sort given n numbers in descending order

Algorithm:

Step1: Start the microprocessor


Step2: Load the number of values into accumulator and save the number of values in register B
Step3: Decrement register B for (N-1) Repetitions
Step4: Set HL register pair as data array address pointer and load the data of array in accumulator
Step5: Set C register as counter for (N-1) repetitions
Step6: Increment HL pair (data address pointer)
Step7: Compare the data pointed by HL with accumulator
Step8: If the value of accumulator is larger than memory, then jump to step 10, otherwise next step.
Step9: Exchange the contents of memory pointed by HL and accumulator
Step10: Decrement C register, if the of C is not zero go to step 6, otherwise next step.
Step11: Decrement B register, if B is not zero, go step 3, otherwise next step.
Step12: Stop the program execution
Result: The assembly language program for sorting 4 numbers in descending order was executed
successfully using assembler and microprocessor kit.

SUM OF DATAS
Problem: To write an assembly language program to calculate the sum of datas using 8085 microprocessor
kit.

Algorithm:

Step1: Start the microprocessor


Step2: Load the number of values in series in accumulator and move it to register C and load the starting
address of array
Step3: Initialize the value of A as „00‟
Step4: Move the value of „A‟ to „B‟ register
Step5: Add the content of accumulator with the data pointed by „HL‟ pair
Step6: If there exists a carry, increment „B‟ by 1, if not continue
Step7: Increment the pointer to next data
Step8: Decrement the value of „C‟ by 1, which is used as counter
Step9: If „C‟ is equal to zero, go to step 10 if not go to step 5.
Step10: Store the value of „A‟ to memory, it shows the result
Step11: Move the content of B to A
Step12: Store the value of A to memory
Step13: Stop the program
Result: The assembly language program for sum of datas was executed successfully using 8085 assembler
and microprocessor kit.

Problem: Write a program for 8085 to find the smallest number among ten numbers stored from at
memory location 2500H.

LXI H, 2500H
MVI C, 0AH
MOV A, M
L2: INX H
CMP M
JC L1
MOV B, A ; If value is bigger, swap the accumulator with memory
MOV A, M ; If value is bigger, swap the accumulator with memory
MOV M, B ; If value is bigger, swap the accumulator with memory
L1: DCR C
JNZ L2
OUT PORT 1
HLT

TABLE PROCESSING
Problem: For ten bytes data starting from 1120H, write a program to sort the reading in ascending and in
descending order. (Note: For descending, do self)

START: LXI H, 1120H


MVI D, 00H
MVI C, 0AH
L2: MOV A, M
INX H
CMP M
JC L1
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H
MVI D, 01H
L1: DCR C
JNZ L2
MOV A, D
RRC
JC START
HLT

Problem: There are two tables T1, T2 in memory having ten eight-bit data in each. Write a program for
8085 to find the difference of the corresponding element of these two tables. Store the result of each
operation on the corresponding element of the third table. Remember that the result should not be
negative; it should be |T1 – T2|.

LXI SP, 2999H


LXI H, 5000H ; TABLE T1
LXI D, 6000H ; TABLE T2
MVI C, 0AH ; COUNTER FOR 10 DATA
L1: LDAX D
MOV B, A
MOV A, M
CMP B
JNC L2
MOV A, B
MOV B, M
L2: SUB B
PUSH D
MVI D, 70H ; TABLE T3
STAX D
POP D
INX H
INX D
DCR C
JNZ L1
HLT

13. Decimal to BCD Conversion


Convert Decimal to BCD

Decimal Number − 2910

Calculating BCD Equivalent. Convert each digit into groups of four binary digits equivalent.

Step Decimal Number Conversion


Step 1 2910 00102 10012
Step 2 2910 00101001BCD

Problem: Write an assembly language program for converting a 2-digit BCD number to its binary
equivalent using 8085 microprocessor.

Examples:
Input: 72H (0111 0010)2
Output: 48H (in hexadecimal) (0011 0000)2
((4x16)+(8x1))=72

Algorithm:
1. Load the BCD number in the accumulator
2. Unpack the 2-digit BCD number into two separate digits. Let the left digit be BCD1 and the right
one BCD2
3. Multiply BCD1 by 10 and add BCD2 to it
If the 2-digit BCD number is 72, then its binary equivalent will be 7 x OAH + 2 = 46H + 2 = 48H

Steps:
1. Load the BCD number from the memory location (201FH, arbitrary choice) into the accumulator
2. Temporarily store the accumulator’s value in B
3. Obtain BCD2 by ANDing the accumulator with 0FH and store it in C
4. Restore the original value of the accumulator by moving the value in B to A. AND the accumulator
with F0H
5. If the value in the accumulator equals 0, then BCD2 is the final answer and store it in the memory
location, 2020H (arbitrary)
6. Else, shift the accumulator to right 4 times to obtain BCD1. Next step is to multiply BCD1 by 0AH
7. Multiplication: Move BCD1 to D and initialise E with 0AH as the counter. Clear the accumulator to
0 and add D to it E number of times
8. Finally, add C to the accumulator and store the result in 2020H
2020H contains the result.

LABEL MNEMONIC
LDA 201FH
MOV B, A
ANI 0FH
MOV C, A
MOV A, B
ANI F0H
JZ SKIPMULTIPLY
RRC
RRC
RRC
RRC
MOV D, A
XRA A
MVI E, 0AH
SUM: ADD D
DCR E
JNZ SUM
SKIPMULTIPLY: ADD C
STA 2020H
HLT
Problem: WAP to read BCD number stored at memory location 2020H and converts it into binary
equivalent and finally stores that binary pattern into memory location 2030H. [Note: BCD number is the
combination from 0 to 9]

MVI C, 0AH
LXI H, 2020H
MOV A, M
ANI F0H
RRC
RRC
RRC
RRC
MOV B, A
MOV A, 00H
L1: ADD B
DCR C
JNZ L1
MOV D, A
MOV A, M
ANI 0FH
ADD D
STA 2030H
HLT

14. Programming Examples


Problem: Write an Assembly Language Program that retrieves a data located at 2050H and it saves, if it is
even and stores FFH on that location if it is odd.
LDA 2050H
ANI 01H
JNZ L1
LDA 2050H
STA 2050H
HLT
L1: MVI A, FFH
STA 2050H
HLT
Problem: Sixteen bytes of data are stored in memory location at 2050H to 205FH. Replace each data byte
by FF.

LXI H, 2050H
MVI C, 10H
L1: MVI M, FFH
INX H
DCR C
JNZ L1
HLT

You might also like