8085 program to find nth power of a number

MicrocontrollerMicroprocessor8085

In this program we will see how to find nth power of a number.

Problem Statement

Write 8085 Assembly language program to find nth power of a number. The base is stored at location 8000H, and the exponent is stored at 8001H. Store the result at 8002H.

Discussion

In 8085, we cannot perform the multiplication operation directly. Here we are writing a subroutine to perform the multiplication by using repetitive addition. To perform nth power of a number, we have to multiply the number n times. The n value is used as a counter. If the base is 03H, exponent is 05H, then the result is F3H (243D)

Input

Address
Data


8000
03
8001
05

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80
 
LXI H,8000H
Initialize HL pair
F003
46
 
MOV B,M
Take Base to B
F004
23
 
INX H
Point to next location
F005
4E
 
MOV C,M
Take exponent to C
F006
16, 01
 
MVI D, 01H
Initialize D with 01H
F008
CD, 12, F0
LOOP
CALL MUL
Call the subroutine to multiply
F00B
0D
 
DCR C
Decrease C by 1
F00C
C2, 08, F0
 
JNZ LOOP
Jump to Loop
F00F
23
 
INX H
Point to next location
F010
72
 
MOV M,D
Store D into memory
F011
76
 
HLT
Terminate the program
F012
58
MUL
MOV E,B
Load B to E
F013
AF
 
XRA A
Clear accumulator to store result
F014
82
ML
ADD D
Add D to A
F015
1D
 
DCR E
Decrement E
F016
C2, 12, F0
 
JNZ ML
If Z = 0, jump to ML
F019
57
 
MOV D,A
Transfer contents of A to D
F01A
C9
 
RET
Return result

Output

Address
Data
8002
F3
raja
Published on 11-Mar-2019 07:19:35
Advertisements