Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to write a program that takes two non-negative numbers from the user and raises the first input to the power of the second input. I am struggling a bit with this problem...but I have worked out some, unfinished code:

Power = """
00 read r1         #get n
01 read r2         #get m
02 copy r3, r1     #store old value of n
03 mul r6, r1, r1  #multiply n but itself and store new value
04 setn r4, 1      #set r4 = 1 
05 sub r5, r2, r4  #subtract 1 from m
06 jgtzn r4, 4     #if r4 > 0, then jump to line 4
07 write r6
08 halt

This is as far as I have gotten...Do you have any advice that may actually make this work?
Updated 9-Apr-15 8:22am
Sergey Alexandrovich Kryukov 9-Apr-15 15:08pm    
Use 3 'm' in hmmm... :-)

1 solution

One algorithm would be get integers A and B.
make power be P=1
while A is not zero
P= P times B
A = A - 1
print P
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900