【发布时间】:2016-02-29 00:44:54
【问题描述】:
我目前正在寻找执行 n power2 函数的最佳方法。简而言之,MIPS 中的代码应该计算 2n。 n 是存储在$a0 中的正数。但是,截至目前,我的结果正在减少一次。
我的尝试
main:
# initialize
la $a0,3 #n counter
li $s0,2 #base number
li $s1,0 #calculated value
While:
beq $a0,$zero,exit #Checks if n is zero, if yes exit program
sllv $s1,$s0,$a0 #Shift left logical by n, this should do the math 2^n
exit:
【问题讨论】: