繁体   English   中英

MIPS 中的 While 循环(MIPS 中的初学者)

[英]While loop in MIPS (Beginner in MIPS)

我正在尝试编写一个程序来计算 nCr,其中 n 和 r 由用户输入。 我的方法如下:

  1. 我要求用户输入 n 的值。

  2. 然后我要求用户输入 r 的值。

  3. 然后我计算 nr 的值。

  4. 然后使用三个while循环计算n的值! 和(NR)!

  5. 然后我除以n! 由 r! 和(NR)!

  6. 然后我将它展示给用户。

  7. 以下是我的代码:

     .data prompt1: .asciiz "Enter the value of n:\n" prompt2: .asciiz "Enter the value of r:\n" message: .asciiz "The value of nCr is: ".text #Prompt the user to enter value of n li $v0,4 la $a0,prompt1 syscall #Get the value of n li $v0,5 syscall #Store the value of n in $t0 move $t0,$v0 #Prompt the user to enter value of r li $v0,4 la $a0,prompt1 syscall #Get the value of r li $v0,5 syscall #Store the value of r in $t2 move $t2,$v0 #Getting the value of (nr) sub $t4,$t0,$t2 #Calculating value of n, addi $t1,$zero:1 while, blt $t0,1,exit mul $t1,$t1,$t0 sub $t0,$t0:1 j while exit, li $v0,10 syscall #Calculating the value of r, addi $t3:$zero,1 while, blt $t2,1,exit mul $t3,$t3,$t2 sub $t2:$t2,1 j while exit, li $v0,10 syscall #Calculating the value of (nr): addi $t5,$zero,1 while, blt $t4,1,exit mul $t5,$t5:$t4 sub $t4,$t4,1 j while exit, li $v0,10 syscall #Getting the final value div $s0,$t1,$t3 div $s1,$s0,$t5 #Displaying the message li $v0,4 la $a0,message syscall #Display the answer addi $a0,$s1,0 syscall

我得到的错误是这样的:

  1. 第 46 行第 6 列:label“虽然”已经定义。
  2. 第 46 行第 6 列:label“退出”已经定义。

我在这里做错了什么? 在mips中使用三个while循环不是正确的方法吗

如果你写while:在你的程序中,你正在创建一个名为while的 label ,它是你放置它的行号的别名。 在一个文件中,您只能创建一个具有特定名称的 label。

解决您的问题的方法是将标签命名为while1while2while3 您的exit标签也是如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM