hmm汇编程序,将一个用户输入提升到下一个用户输入的功能 [英] hmm assembly program that raises one user input to the power of the next user input

查看:86
本文介绍了hmm汇编程序,将一个用户输入提升到下一个用户输入的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序,该程序从用户获取两个非负数,并将第一个输入提升到第二个输入的幂。我正在努力解决这个问题......但是我已经找到了一些未完成的代码:



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
"""
hmmmAssembler.main(Power)





这就是我已经得到了......你有什么建议可以让它真正起作用吗?



This is as far as I have gotten...Do you have any advice that may actually make this work?

推荐答案

一个算法就是得到整数A和B.

使权力为P = 1

而A不为零

P = P次B

A = A - 1

打印P
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


这篇关于hmm汇编程序,将一个用户输入提升到下一个用户输入的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆