8085 Micro-Processor Programs


Factorial of a number using 8085


Ø   An Assembly Language Program to find the factorial of a number using 8085?

Algorithm

1)      Load HL pair with the number whose factorial is to be found.
2)      Copy memory content to register E.
3)      Decrement register B content by 1.
4)      Increment the memory and decrement the number and store the numbers in the consecutive memory locations.
5)      Again load the number to the HL pair.
6)      Copy the number to the accumulator.
7)      Increment memory and copy the second number to register B.
8)      Copy the accumulator content to the register C as count.
9)      Initialize accumulator with 0.
10)  Add accumulator content with register B.
11)  Decrement count.
12)  If count = 0, then got next step else go to step 8.
13)  Copy accumulator content to memory
14)  Decrement register E by 1.
15)  If register E is not zero then go to step 6 else go to next step.
16)  Store the factorial in memory.
17)  Terminate the program.

Program

MEMORY
LABEL
MNEMONIC
HEX CODE
COMMENT
4200

LXI H,4100
21

Load the number to the HL pair
4201


00
4202


41
4203

MVI C,M
4E
Copy the number to register C
4204

MVI E,M
5E
Copy memory content to E
4205

DCR E
1D
Decrement E
4206
LOOP1
INX H
23
Increment memory
4207

DCR C
0D
Decrement C
4208

MOV M,C
71
Copy content of C to memory
4209

JNZ LOOP1
C2

Jump on non-zero to label LOOP1
420A


06
420B


42
420C

LXI H,4100
21
Load the number whose factorial is to be found in HL pair
420D


00
420E


41
420F
LOOP2
MOV A,M
7E
Copy memory content to accumulator
4210

INX H
23
Increment memory
4211

MOV B,M
46
Copy memory content to B
4212

MOV C,A
4F
Copy accumulator content to C
4213

MVI A,00
3E
Initialize A with 0
4214


00
4215
GO
ADD B
80
[A] ß [A] + [B]
4216

DCR C
0D
Decrement C
4217

JNZ GO
C2

Jump on non-zero to label GO
4218


15
4219


42
421A

MOV M,A
77
Copy accumulator content to memory
421B

DCR E
1D
Decrement E
421C

JNZ LOOP2
C2

Jump on non-zero to label LOOP2
421D


0F
421E


42
421F

STA 4500
32
Store accumulator content to memory
4220


00
4221


45
4222

HLT
76
Program ends

Observation

Input at           4100    :           05H

Output at         4500    :           78H        ----------- factorial

----------------------------------------------------------------------------------------

Square of an 8-bit number using 8085


Ø   An Assembly Language Program to find the square of an 8-bit number using 8085?

Algorithm

1)      Load the HL pair with the number whose square is to be found.
2)      Copy the number to C and B registers.
3)      Initialize D and A registers with 0.
4)      Add content of accumulator with register B.
5)      Check for carry.
6)      If no carry go to step 8 else go to next step.
7)      Increment content of D.
8)      Decrement content of C.
9)      If ZF = 0 then go to next step else go to step 4.
10)  Store the product and carry in memory.
11)  Terminate the program.

Program

MEMORY
LABEL
MNEMONIC
HEX CODE
COMMENT
4200

LXI H,4500
21

Load the number to the HL pair
4201


00
4202


45
4203

MVI A,M
7E
Copy the number to the accumulator
4204

MVI B,A
47
Copy the accumulator content to register B
4205

MVI D,00
16
Initialize D with 0
4206


00
4207

MOV C,A
4F
Copy accumulator content to C
4208

MOV A,D
7A
Copy content of D to accumulator
4209
GO
ADD B
80
[A] ß [A] + [B]
420A

JNC AHEAD
D2
Jump on no carry to the label AHEAD
420B


0E
420C


42
420D

INR D
14
Increment D
420E
AHEAD
DCR C
0D
Decrement C
420F

JNZ GO
C2

Jump on non-zero to the label GO
4210


09
4211


42
4212

STA 4100
32

Store the product to 4100
4213


00
4214


42
4215

MOV A,D
74
Copy carry to accumulator
4216

STA 4101
32

Store carry to 4101
4217


01
4218


41
4219

HLT
76
Program ends

Observation

Input at           4100    :           05H

Output at         4100    :           19H      ----------- Square
                        4101    :           00H      ----------- Carry

-----------------------------------------------------------------------------------

2 comments: