assembly programs of 8085 microprocessor, there are many programs related to the computer architecture that will helpful for the programming in the assembly language. like addition of two 8bit number , subtraction, multiplication, division and table for 8085, array,etc ....
Also written all the procedure to write the programs in practical notebook for the practical exams in the colleges or universities.
2. 8085 program to find maximum and
minimum of 10 numbers
In CMP instruction:
If Accumulator > Register then carry and zero
flags are reset
If Accumulator = Register then zero flag is set
If Accumulator < Register then carry flag is set
Assumption – List of numbers from 2050H to
2059H and output at 2060H and 2061H.
9/8/2022 7:34 AM 2
3. Algorithm
• Maximum number is stored in B register and minimum in C
register
• Load counter in D register
• Load starting element in Accumulator, B and C register
• Compare Accumulator and B register
• 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
• Decrement D register
• If D>0 take next element in Accumulator and go to point 4
• If D=0, store B and C register in memory
• End of program
9/8/2022 7:34 AM 3
4. Program
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
9/8/2022 7:34 AM 4
5. 2009H JC MIN
Jump to MIN if not
maximum
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
9/8/2022 7:34 AM 5
6. 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
9/8/2022 7:34 AM 6
7. Explanation
• One by one all elements are compared with B and
C register.
• Element is compared with maximum, if it greater
than maximum then it is stored in B register. Else,
it is compared with minimum and if it is less than
minimum then it stored in C regiter.
• Loop executes 10 number of times.
• At the end of 10 iterations, maximum and
minimum are stored at 2060H and 2061H
respectively.
9/8/2022 7:34 AM 7
8. SMALLEST NUMBER IN A DATA ARRAY
Algorithm
1) Load the address of the first element of the array in HL pair
2) Move the count to B – reg.
3) Increment the pointer
4) Get the first data in A – reg.
5) Decrement the count.
6) Increment the pointer
7) Compare the content of memory addressed by HL pair with that of A - reg.
8) If carry = 1, go to step 10 or if Carry = 0 go to step 9
9) Move the content of memory addressed by HL to A – reg.
10) Decrement the count
11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12) Store the smallest data in memory.
13) Terminate the program.
9/8/2022 7:34 AM 8
9. Program
LXI H,4200 Set pointer for array
MOV B,M Load the Count
INX H Set 1st element as largest data
MOV A,M
DCR B Decremented the count
LOOP: INX H
CMP M If A- reg < M go to AHEAD
JC AHEAD
MOV A,M Set the new value as smallest
AHEAD:DCR B
JNZ LOOP Repeat comparisons till count = 0
STA 4300 Store the largest value at 4300
HLT
9/8/2022 7:34 AM 9
17. Sort an array in ascending order
Algorithm:
1. Initialize HL pair as memory pointer
2. Get the count at 4200 into C - register
3. Copy it in D - register (for bubble sort (N-1) times
required)
4. Get the first value in A - register
5. Compare it with the value at next location
6. If they are out of order, exchange the contents of A - register
and Memory
7. Decrement D - register content by 1
8. Repeat steps 5 and 7 till the value in D- register become
zero
9. Decrement C - register content by 1
10. Repeat steps 3 to 9 till the value in C - register becomes
zero
9/8/2022 7:34 AM 17
18. Program
LXI H,5000 ;Set pointer for array
MOV C,M ;Load the Count
DCR C ;Decrement Count
REPEAT: MOV D,C
LXI H,5001
LOOP: MOV A,M ;copy content of memory location to Accumulator
INX H
CMP M
JC SKIP ;jump to skip if carry generated
MOV B,M ;copy content of memory location to B - Register
MOV M,A ;copy content of Accumulator to memory location
DCX H ;Decrement content of HL pair of registers
MOV M,B ;copy content of B - Register to memory location
INX H ;Increment content of HL pair of registers
SKIP: DCR D ;Decrement content of Register - D
JNZ LOOP ;jump to loop if not equal to zero
DCR C ;Decrement count
JNZ REPEAT ;jump to repeat if not equal to zero
HLT ;Terminate Program
9/8/2022 7:34 AM 18
19. Result
Input:
Data 0: 05H in memory location 5000 -->array size
Data 1: 05H in memory location 5001
Data 2: 04H in memory location 5002
Data 3: 03H in memory location 5003
Data 4: 02H in memory location 5004
Data 5: 01H in memory location 5005
Output:
Data 0: 05H in memory location 5000 --> array size
Data 1: 01H in memory location 5001
Data 2: 02H in memory location 5002
Data 3: 03H in memory location 5003
Data 4: 04H in memory location 5004
Data 5: 05H in memory location 5005
9/8/2022 7:34 AM 19
20. Sort an array in descending order
START:MVI B, 00 ; Flag = 0
LXI H, 4150 ; Count = length of array
MOV C, M
DCR C ; No. of pair = count -1
INX H ; Point to start of array
LOOP:MOV A, M ; Get kth element
INX H
CMP M ; Compare to (K+1) th element
JNC LOOP 1 ; No interchange if kth >= (k+1) th
MOV D, M ; Interchange if out of order
MOV M, A ;
DCR H
MOV M, D
INX H
MVI B, 01H ; Flag=1
LOOP 1:DCR C ; count down
JNZ LOOP ;
DCR B ; is flag = 1?
JZ START ; do another sort, if yes
HLT ; If flag = 0, step execution
9/8/2022 7:34 AM 20
21. To add numbers in an array
Problem – Write an assembly language program
to add hexadecimal numbers stored in
continuous memory or in an array.
Assumption – Suppose the size of the array is
stored at memory location 2050 and the base
address of the array is 2051. The sum will be
stored at memory location 3050 and carry will
be stored at location 3051.
9/8/2022 7:34 AM 21
22. Algorithm
• Load the base address of the array in HL
register pair.
• Use the size of the array as a counter.
• Initialise accumulator to 00.
• Add content of accumulator with the content
stored at memory location given in HL pair.
• Decrease counter on each addition.
9/8/2022 7:34 AM 22
23. Program
2000 LDA 2050 A <- [2050]
2003 MOV B, A B <- A
2004 LXI H, 2051 H <- 20 and L <- 51
2007 MVI A, 00 A <- 00
2009 MVI C, 00 C <- 00
200B ADD M A <- A+M
200C INR M M <- M+1
200D JNC 2011
2010 INR C C <- C+1
2011 DCR B B <- B-1
2012 JNZ 200B
2015 STA 3050 3050 <- A
9/8/2022 7:34 AM 23
24. 2018 MOV A, C A <- C
2019 STA 3051 3051 <- A
201C HLT
Terminates the program
9/8/2022 7:34 AM 24
25. Explanation –
LDA 2050: load accumulator with content of location 2050
MOV B, A: copy contents of accumulator to register B
LXI H, 2051: store 20 to H register and 51 to L register
MVI A, 00: store 00 to accumulator
MVI C, 00: store 00 to register C
ADD M: add accumulator with the contents of memory location given in HL register
pair
INR M: increase M by 1
JNC 2011: if not carry, jump to location 2011 otherwise to the location given in PC
INR C: increase content of register C by 1
DCR B: decrease content of register B by 1
JNZ 200B: if not zero, jump to location 200B otherwise to the location given in PC
STA 3050: store contents of accumulator to memory location 3050
MOV A, C: copy contents of register C to accumulator
STA 3051: store contents of accumulator to memory location 3051
HLT: terminates the program
9/8/2022 7:34 AM 25
26. Square of a Number Using Look Up
Table
Algorithm
1. Initialize HL pair to point Look up table.
2. Get the data .
3. Check whether the given input is less than 9.
4. If yes go to next step else halt the program.
5. Add the desired address with the
accumulator content.
6. Store the result
9/8/2022 7:34 AM 26
27. Program and Result
LXI H,5000 ;Initialsie Look up table address
LDA 5050 ;Get the data
CPI 0A ;Check input > 9
JC AFTER ;if yes error
VI A,FF ;Error Indication
STA 5051
HLT
AFTER: MOV C,A ;Add the desired Address
MVI B,00
DAD B
MOV A,M
STA 5051 ;Store the result
HLT ;Terminate the program
9/8/2022 7:34 AM 27