需要MIPS体系结构循环帮助

需要MIPS体系结构循环帮助,mips,mips32,pcspim,Mips,Mips32,Pcspim,完成SPIM汇编语言程序loop2.s。 该程序将计算“数字”中元素的总和 其值小于或等于1000 我试图编程的代码,但输出来了,而我需要它是11 程序名称:loop2.s 将计算数组“number”中所有元素的总和 其值小于或等于1000 “数字”是一个包含5个整数元素的数组 “count”保存“numbers”中的元素数 输出格式必须为 “总和=11” t0-依次指向数组元素 t1-包含元素计数 t2-包含和 t3-数组中的每个单词依次为“数字” 您需要添加检查值是否为1000的代码,以

完成SPIM汇编语言程序loop2.s。 该程序将计算“数字”中元素的总和 其值小于或等于1000

我试图编程的代码,但输出来了,而我需要它是11

程序名称:loop2.s

  • 将计算数组“number”中所有元素的总和 其值小于或等于1000
  • “数字”是一个包含5个整数元素的数组
  • “count”保存“numbers”中的元素数

  • 输出格式必须为 “总和=11”

t0-依次指向数组元素 t1-包含元素计数

t2-包含和

t3-数组中的每个单词依次为“数字”


您需要添加检查值是否为1000的代码,以便将数字添加(或不添加)到$t2

process:
   lw $t3, ($t0)           # load word from the array

   # check if > 1000, and if it is, jump to don't_add (ie: skip the adding to sum)
   bgt $t3, 1000, dont_add


   add $t2, $t2, $t3       # add it to sum
dont_add:    
   add $t0, $t0, 4         # increment the pointer / get the next element of the array
   sub $t1, $t1, 1         # decrement the counter
   beqz $t1, done          # if counter = 0, then it's done
   j process

done:

您需要添加检查值是否为1000的代码,以便将数字添加(或不添加)到$t2

process:
   lw $t3, ($t0)           # load word from the array

   # check if > 1000, and if it is, jump to don't_add (ie: skip the adding to sum)
   bgt $t3, 1000, dont_add


   add $t2, $t2, $t3       # add it to sum
dont_add:    
   add $t0, $t0, 4         # increment the pointer / get the next element of the array
   sub $t1, $t1, 1         # decrement the counter
   beqz $t1, done          # if counter = 0, then it's done
   j process

done:

“然而,输出即将到来,而我需要它是11”请澄清“输出即将到来”的含义。显然,如果您想排除某些元素,您需要某种比较和条件分支。我建议您通过MIPS指令集引用查看哪些指令可用,您可以使用。“然而,输出即将到来,而我需要它是11”请澄清“输出即将到来”的含义。显然,如果要排除某些元素,您需要某种比较和条件分支。我建议您查看MIPS指令集引用,以查看哪些指令可用。您还应该将末尾的
beqz/j
指令替换为唯一指令
bne$t1,$zero,process
您还应将末尾的
beqz/j
指令替换为唯一指令
bne$t1,$zero,process