Assembly 汇编:在以下代码和一般情况下,需要在内存堆栈中保存值

Assembly 汇编:在以下代码和一般情况下,需要在内存堆栈中保存值,assembly,mips,Assembly,Mips,我希望你能帮我解决以下问题 我被要求在MIPS程序集中实现函数is_cube,它接收n作为参数,并检查它是否是一个多维数据集。例如,8(2^3)和1000(10^3)是立方体 我编写了以下代码: # UNTITLED PROGRAM .data str: .asciiz "Please enter your number >" str1: .asciiz "The number is a cube" str2: .asciiz "The number is not a cube"

我希望你能帮我解决以下问题

我被要求在MIPS程序集中实现函数is_cube,它接收n作为参数,并检查它是否是一个多维数据集。例如,8(2^3)和1000(10^3)是立方体

我编写了以下代码:

# UNTITLED PROGRAM

.data   

str: .asciiz "Please enter your number >"
str1: .asciiz "The number is a cube"
str2: .asciiz "The number is not a cube"


.text

 main:  

   li $v0 4
   la $a0 str
   syscall

   li $v0 5
   syscall


   move $t0 , $v0
   li $t1, 0
   blt $t0, $zero, negative


  negative:
    sub $t5, $zero, 1
mul $t0, $t0, $t5



 is_cube: 

  addi $t1, $t1, 1
  sgt $t2, $t1, $t0
  bne $t2, $zero, There_is_not 
  mul $t3, $t1, $t1
  mul $t4 ,$t3, $t1
  beq $t4, $t0, There_is

  jal is_cube



 There_is:

   li $v0 4
   la $a0 str1
   syscall

   jal end

 There_is_not:

   li $v0 4
   la $a0 str2
   syscall

   jal end


 end: 
它可以工作,无需通过
$sp
和所有这些过程将
$s0
保存在堆栈中。我的问题是:不保存它可以吗?如果是,我应该什么时候使用它


非常感谢。

您还没有实现函数。您已经实现了一个循环,它碰巧使用了
jal
而不是普通的分支指令。执行从main开始,然后从
下降到从
is\u cube
开始的循环,然后当循环在
处终止时,有
没有
使用
jal end
,而不是另一条分支指令

与x86不同,
jal
指令不会将程序计数器的当前值推送到堆栈中,因此此代码正好在MIPS上工作


如果这是家庭作业,在提交此代码之前,您应该回到您关于在汇编程序中编写函数的说明。

我不理解这个问题。你没有在任何地方使用$s0。。。你为什么要保存它?