0

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

QtSpim 的结果

4

1 回答 1

3

“失败”不是一个信息量很大的陈述。无论如何,正确的语法beg $a0,$zero,j Exitbeq $a0, $zero, exit但你甚至不需要那个检查。你应该加载not因为is$s0和should be 。102^01sll $s0, 2, $a0sllv $s0, $s0, $a0

于 2016-02-29T00:48:36.913 回答