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

Microprocessor Programming Lab Manual

Programming in microprocessor 8085 command

Uploaded by

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

Microprocessor Programming Lab Manual

Programming in microprocessor 8085 command

Uploaded by

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

Prg #1, ADDITION OF TWO 8 BIT NUMBERS

AIM: To perform addition of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading the first data into Accumulator.

2) Move the data to a register (B register).

3) Get the second data and load into Accumulator.

4) Add the two register contents.

5) Check for carry.

6) Store the value of sum and carry in memory location.

7) Terminate the program.

PROGRAM:

MVI C, 00 Initialize C register to 00

LDA 4150 Load the value to Accumulator.

MOV B, A Move the content of Accumulator to B register.

LDA 4151 Load the value to Accumulator.

ADD B Add the value of register B to A

JNC LOOP Jump on no carry.

INR C Increment value of register C

LOOP: STA 4152 Store the value of Accumulator (SUM).

MOV A, C ;Move content of register C to Acc.

STA 4153 Store the value of Accumulator (CARRY)

HLT Halt the program.

OBSERVATION:

Input: 80 (4150)
80 (4251)

Output: 00 (4152)
01 (4153)
RESULT: Thus the program to add two 8-bit numbers was executed.
Prg #2, SUBTRACTION OF TWO 8 BIT NUMBERS

AIM: To perform the subtraction of two 8 bit numbers using 8085.

ALGORITHM:

1. Start the program by loading the first data into Accumulator.

2. Move the data to a register (B register).

3. Get the second data and load into Accumulator.

4. Subtract the two register contents.

5. Check for carry.

6. If carry is present take 2’s complement of Accumulator.

7. Store the value of borrow in memory location.

8. Store the difference value (present in Accumulator) to a memory

9. location and terminate the program.

PROGRAM:

MVI C, 00 Initialize C to 00

LDA 4150 Load the value to Acc.

MOV B, A Move the content of Acc to B register.

LDA 4151 Load the value to Acc.

SUB B

JNC LOOP Jump on no carry.

CMA Complement Accumulator contents.

INR A Increment value in Accumulator.

INR C Increment value in register C

LOOP: STA 4152 Store the value of A-reg to memory address.

MOV A, C Move contents of register C to Accumulator.

STA 4153 Store the value of Accumulator memory address.

HLT Terminate the program.


OBSERVATION:

Input: 06 (4150)

02 (4251)

Output: 04 (4152)

01 (4153)

RESULT: Thus the program to subtract two 8-bit numbers was executed.
Prg #3, MULTIPLICATION OF TWO 8 BIT NUMBERS

AIM: To perform the multiplication of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading HL register pair with address of memory location.

2) Move the data to a register (B register).

3) Get the second data and load into Accumulator.

4) Add the two register contents.

5) Check for carry.

6) Increment the value of carry.

7) Check whether repeated addition is over and store the value of product and carry

in memory location.

8) Terminate the program.

PROGRAM:
MVI D, 00 Initialize register D to 00

MVI A, 00 Initialize Accumulator content to 00

LXI H, 4150

MOV B, M Get the first number in B - reg

INX H

MOV C, M Get the second number in C- reg.

LOOP: ADD B Add content of A - reg to register B.

JNC NEXT Jump on no carry to NEXT.

INR D Increment content of register D

NEXT: DCR C Decrement content of register C.

JNZ LOOP Jump on no zero to address

STA 4152 Store the result in Memory

MOV A, D

STA 4153 Store the MSB of result in Memory

HLT Terminate the program.


OBSERVATION:

Input: FF (4150)

FF (4151)

Output: 01 (4152)

FE (4153)

RESULT: Thus the program to multiply two 8-bit numbers was executed.
Prg #4, DIVISION OF TWO 8 BIT NUMBERS

AIM: To perform the division of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading HL register pair with address of memory location.

2) Move the data to a register(B register).

3) Get the second data and load into Accumulator.

4) Compare the two numbers to check for carry.

5) Subtract the two numbers.

6) Increment the value of carry .

7) Check whether repeated subtraction is over and store the value of product and carry in memory location.

8) Terminate the program.

PROGRAM:

LXI H, 4150

MOV B, M Get the dividend in B – reg.

MVI C, 00 Clear C – reg for qoutient

INX H

MOV A, M Get the divisor in A – reg.

NEXT: CMP B Compare A - reg with register B.

JC LOOP Jump on carry to LOOP

SUB B Subtract A – reg from B- reg.

INR C Increment content of register C.

JMP NEXT Jump to NEXT

LOOP: STA 4152 Store the remainder in Memory

MOV A, C

STA 4153 Store the quotient in memory

HLT Terminate the program.

OBSERVATION:
Input: FF (4150)

FF (4251)

Output: 01 (4152) ---- Remainder

FE (4153) ---- Quotient

RESULT: Thus the program to divide two 8-bit numbers was executed.
Prg #5, LARGEST NUMBER IN AN ARRAY OF DATA

AIM: To find the largest number in an array of data using 8085 instruction set.

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 = 0, go to step 10 or if Carry = 1 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 largest data in memory.

13) Terminate the program.

PROGRAM:

LXI H,4200 Set pointer for array

MOV B,M Load the Count

INX H

MOV A,M Set 1st element as largest data

DCR B Decrement the count

LOOP: INX H

CMP M If A- reg > M go to AHEAD

JNC AHEAD

MOV A,M Set the new value as largest

AHEAD: DCR B
JNZ LOOP Repeat comparisons till count = 0

STA 4300 Store the largest value at 4300

HLT

OBSERVATION:

Input: 05 (4200) ----- Array Size

0A (4201)

F1 (4202)

1F (4203)

26 (4204)

FE (4205)

Output: FE (4300)

RESULT: Thus the program to find the largest number in an array of data was executed
Prg #6, SMALLEST NUMBER IN AN ARRAY OF DATA

AIM: To find the smallest number in an array of data using 8085 instruction set.

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.

PROGRAM:

LXI H,4200 Set pointer for array

MOV B,M Load the Count

INX H

MOV A,M Set 1st element as largest data

DCR B Decrement 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

OBSERVATION:

Input: 05 (4200) ----- Array Size

0A (4201)

F1 (4202)

1F (4203)

26 (4204)

FE (4205)

Output: 0A (4300)

RESULT: Thus the program to find the smallest number in an array of data was executed
Prg #7, ARRANGE AN ARRAY OF DATA IN ASCENDING ORDER

AIM: To write a program to arrange an array of data 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

PROGRAM:

LXI H,4200

MOV C,M

DCR C

REPEAT: MOV D,C

LXI H,4201

LOOP: MOV A,M

INX H

CMP M

JC SKIP

MOV B,M

MOV M,A

DCX H
MOV M,B

INX H

SKIP: DCR D

JNZ LOOP

DCR C

JNZ REPEAT

HLT

OBSERVATION:

Input: 4200 05 (Array Size)

4201 05

4202 04

4203 03

4204 02

4205 01

Output: 4200 05(Array Size)

4201 01

4202 02

4203 03

4204 04

4205 05

RESULT: Thus the given array of data was arranged in ascending order.
Prg #8, ARRANGE AN ARRAY OF DATA IN DESCENDING ORDER

AIM: To write a program to arrange an array of data in descending 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

PROGRAM:

LXI H,4200

MOV C,M

DCR C

REPEAT: MOV D,C

LXI H,4201

LOOP: MOV A,M

INX H

CMP M

JNC SKIP

MOV B,M

MOV M,A

DCX H

MOV M,B

INX H
SKIP: DCR D

JNZ LOOP

DCR C

JNZ REPEAT

HLT

OBSERVATION:

Input: 4200 05 (Array Size)

4201 01

4202 02

4203 03

4204 04

4205 05

Output: 4200 05(Array Size)

4201 05

4202 04

4203 03

4204 02

4205 01

RESULT: Thus the given array of data was arranged in descending order.
Prg# 9
AIM: To write a program to find square of any number.

Algorithm –

1. Assign 20 to register H, 50 to register L and 00 to accumulator A


2. Load the content of memory location which is specified by M in register B
3. Add content of M in accumulator A and decrement value of B by 01
4. Check if B holds 00, if true then store the value of A at memory location 3050 otherwise go to step 3

Program –

MVI H 20 H <- 20

MVI L 50 L <- 50

MVI A 00 A <- 00

MOV B, M B <- M

ADD M A <- A + M

DCR B B <- B – 01

JNZ 2007 Jump if ZF = 0

STA 3050 M[3050] <- A

HLT END

Explanation – Registers used A, H, L, B and indirect memory M:

1. MVI H 20 – initialize register H with 20


2. MVI L 50 – initialize register L with 50
3. MVI A 00 – initialize accumulator A with 00
4. MOV B, M – moves the content of memory location which is indirectly specified by M in register B
5. ADD M – add the content of memory location which is indirectly specified by M in accumulator A
6. DCR B – decrement value of register B by 1
7. JNZ 2007 – jump to memory location 2007 if ZF = 0, i.e register B does not contain 0
8. STA 3050 – stores value of A in 3050
9. HLT – stops executing the program and halts any further execution’
Prg# 10
Aim: Write an assembly language program in 8085 microprocessor to generate Fibonacci series.

Algorithm –

1. Initialize register H with 30 and register L with 50, so that indirect memory M points to memory location 3050.
2. Initialize register B with 00, register C with 08 and register D with 01.
3. Move the content of B in M.
4. Increment M by 1 so that M points to next memory location.
5. Move the content of D in M.
6. Move the content of B in accumulator A.
7. Add the content of D in A.
8. Move the content of D in B.
9. Move the content of A in D.
10. Increment M by 1 so that M points to next memory location.
11. Move the content of A in M.
12. Decrements C by 1.
13. Jump to memory location 200C if ZF = 0 otherwise Halt the program.
Program –

LXI H, 3050 H <- 30, L <- 50


MVI C, 08 C <- 08
MVI B, 00 B <- 00
MVI D, 01 D <- 01
MOV M, B M <- B
INX H M <- M + 01
MOV M, D M <- D
MOV A, B A <- B
ADD D A <- A + D
MOV B, D B <- D
MOV D, A D <- A
INX H M <- M + 01
MOV M, A M <- A
DCR C C <- C – 01
JNZ 200C Jump if ZF = 0
HLT END

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

1. LXI H 3050: assigns 30 to H and 50 to L.


2. MVI B, 00: assigns 00 to B.
3. MVI C, 08: assigns 08 to C.
4. MVI D, 01: assigns 01 to D.
5. MOV M, B: moves the content of B in M.
6. INX H: increment M by 1.
7. MOV M, D: moves the content of D in M.
8. MOV A, B: moves the content of B in A.
9. ADD D: add the content of D and A. Store the result in A.
10. MOV B, D: moves the content of D in B.
11. MOV D, A: moves the content of A in D.
12. INX H: increment M by 1.
13. MOV M, A: moves the content of A in M.
14. DCR C: decrements C by 1.
15. JNZ 200C: jump to memory location 200C if ZF = 0.
16. HLT: stops executing the program and halts any further execution.

You might also like