我目前正在寻找执行 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: