MIPS:确定测试分数列表是否通过/未通过 [英] MIPS: determine if a list of test scores are pass/fail

查看:90
本文介绍了MIPS:确定测试分数列表是否通过/未通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个MiPS程序,该程序将检查15个测试分数的列表.合格标准为50分.到终端的输出将包括各个类别的得分以及通过和不及格的学生人数.带有输入提示和输出语句...下面是我编写的程序,但是它没有用....请我....我不知道我是否做错了..

I am writing a MiPS program that will examine a list of 15 test scores. And it is going to input from the terminal.Well, the passing criterion is the score of 50. the ouptuts to the terminal will include the scores in each category and the number of students passing and failing. with input prompts and output statements...Below is the program i wrote but it didnt work....Please i need....i dont know if i m doing it wrong..

.globl main
.text

主要: li $ t0,0#通过成绩计数器 la $ t1,传递#pointer传递数组
li $ t2,0#不及格的计数器 la $ t3,传递数组的指针失败 li $ t4,0#总计数器 li $ t5,0 li $ t6,0

main: li $t0, 0 #counter for passing grades la $t1, pass #pointer for pass array
li $t2, 0 #counter for failing grades la $t3, fail #pointer for pass array li $t4, 0 #overall counter li $t5, 0 li $t6, 0

循环: li $ v0,4#系统调用打印字符串 la $ a0,提示#加载字符串 syscall

loop: li $v0, 4 #system call for print string la $a0, prompt #load string syscall

li $v0, 5           #system call for read integer
syscall             #read integer

bltu $v0, 50, else      #if $v0 < 50 branch to else (failing grade)
sw $v0, 0($t1)          #store word in pass array
addi $t1, $t1, 4        #t1 = t1 + 4 (increment pass pointer)
addi $t0, $t0, 1        #t0 = t0 + 1 (increment pass counter)
b l_end             #branch over else statement

其他: sw $ v0,0($ t3)#将字存储在失败数组中 addi $ t3,$ t3,4#t3 = t3 + 4(递增失败指针) addi $ t2,$ t2,1#t1 = t1 + 1(失败计数递增)

else: sw $v0, 0($t3) #store word in fail array addi $t3, $t3, 4 #t3 = t3 + 4 (increment fail pointer) addi $t2, $t2, 1 #t1 = t1 + 1 (increment fail counter)

l_end: addi $ t4,$ t4、1#总计数器递增 bltu $ t4,15,循环#if t4< = 15分支循环

l_end: addi $t4, $t4, 1 #increment overall counter bltu $t4, 15, loop #if t4 <= 15 branch to loop

li $v0, 4           #system call for print string
la $a0, o_pasc          #load string
syscall             #output "Number of Passing Scores:

la $v0, 1           #system call for print integer
add $a0, $t0, 0         #load value of pass counter into $a0
syscall             #output value

li $v0, 4           #system call for print string
la $a0, o_fasc          #load string
syscall             #output "Number of Failing Scores: "

la $v0, 1           #system call for print string
add $a0, $t2, 0         #load value of fail counter into $a0
syscall             #output value

输出及格分数

li $v0, 4           #setup output   
la $a0, o_pass          #setup text
syscall             #output string o_pass

la $t1, pass            #load address of pass pointer to t1
lw $a0, 0($t1)          #load word at $t1 into $a0
li $v0, 1           #system call for print integer

loop_a: bleu $ t0,$ t5,lp_a_end#如果t0< = t5分支到lp_a_end syscall#输出单项得分

loop_a: bleu $t0, $t5, lp_a_end #if t0 <= t5 branch to lp_a_end syscall #output single score

li $v0, 4           #system call for print string
la $a0, o_coma          #load string
syscall             #ouput comma and space

li $v0, 1           #setup output
addi $t1, $t1, 4        #move pointer down by 1 word
lw $a0, 0($t1)          #move word at pointer into $a0
addi $t5, $t5, 1        #add 1 to counter

b loop_a            #branch to top

lp_a_end:

la $t5, 0           #clear t5 (counter)
li $v0, 4           #setup output
la $a0, o_fail          #setup text
syscall             #output string o_fail

la $t3, fail            #load address for fail pointer into $t3
lw $a0, 0($t3)          #load word at mem addy $t3 into $a0
li $v0, 1           #system call for print integer

loop_b: bleu $ t2,$ t5,lp_b_end#如果t2 <= t5分支到lp_a_end syscall#输出单项得分

loop_b: bleu $t2, $t5, lp_b_end #if t2 <= t5 branch to lp_a_end syscall #output single score

li $v0, 4           #system call for print string
la $a0, o_coma          #load string
syscall             #output comma and space

li $v0, 1           #setup output
addi $t3, $t3, 4        #move pointer down by 1 word
lw $a0, 0($t3)          #load word from mem addy $t3 to $a0
addi $t5, $t5, 1        #add 1 to counter

b loop_b            #branch to top

lp_b_end:

li $v0, 4           #setup output
la $a0, o_brk           #setup text
syscall             #output line break

li $v0, 10          #loads 10 to $v0
syscall             #ends program

推荐答案

似曾相识通常是矩阵中的一个小故障"

"A deja vu is usually a glitch in the Matrix"

很确定我已经看到了这一点:

Pretty sure i've seen this around:

MIPS程序来确定测试成绩的通过/失败

编辑:一些建议:尝试简化事情.逐步构建您的程序.例如,尝试避免系统调用,请使用硬编码输入来测试比较逻辑.然后,进行系统调用.您是否正确使用数组?我已经看到,您保留了两个单独的计数器来为数组建立索引,并保留其中的元素计数.我认为那是容易出错的.也许您应该使用计数器来索引数组(乘以4).点击链接,如果有任何具体疑问,我将很乐意为您提供帮助.

EDIT: Some advice: Try to simplify things. Build your program bit by bit. For example, try to avoid syscalls, use hardcoded inputs to test your comparing logic. Then, go for syscalls. Are you using arrays correctly? I've seen that you keep two separate counters for indexing the array, and keeping count of the elements inside it. I think that that is error prone. Maybe you should use the counter to index the array (multiplying it by 4). Follow the link, i'll be happy to help if any specific doubts appear.

我不太喜欢SPIM模拟器.我知道许多大学都在课程中使用它,但是我认为这是一个错误,因为它的环境非常有限.

I don't like SPIM simulator much. I know that many universities use it for their courses, but i think that is a mistake, since it is a very limited environment.

另一项编辑(按热门"需求): 我已经读了一段时间的代码,并且注意到了一些事情.

ANOTHER EDIT (by "popular" demand): I've read your code for a while, and i noticed some things.

  • 将值加载到寄存器中以与零进行比较.不要这样做,请使用$ zero寄存器.

  • You load values into registers for comparison against zero. Don't do this, use the $zero register.

li $ t5,0

li $t5,0

li $ t6.0

li $t6.0

用于

bleu $t0,$t5,lp_a_end       #if t0 <= t5 branch to lp_a_end 

应该是

bleu $t0,$zero,lp_a_end

  • 说明的使用

    • Usage of instructions

      bltu $ v0,50,否则#if $ v0< 50分支到其他(不及格)

      bltu $v0, 50, else #if $v0 < 50 branch to else (failing grade)

      分支指令带有两个寄存器和一个标签.不注册,中介,标记

      branch instructions take two registers and a label. Not register, inmediate, label

      应该是:

         li   $t5,50
         bltu $v0,$t5,else
      

      我的猜测是,您使系统调用徒劳无功.当您无法使输出正常工作时,为什么还要花哨您的输出呢?除此之外,一旦开始准备系统调用,就执行它.不要像在

      My guess is that you are complicating yourself in vain with the syscalls. Why are you fancying your output when you cant get it to work? In addition to that, once you start preparing for a syscall, execute it. Dont put a branch instruction in the middle, like in

              la $t3, fail                    #load address for fail pointer into $t3
              lw $a0, 0($t3)                  #load word at mem addy $t3 into $a0
              li $v0, 1        
      loop_b: bleu $t2, $t5, lp_b_end         #if t2 <= t5 branch to lp_a_end 
              syscall                         #output single score
      

      这很令人困惑.也许您应该尝试以下方法:

      This is quite confusing. Maybe you should try something like:

      #Is there anything to print in the array? If not, goto lp_b_end
      bleu $t2,$zero,lp_b_end
      
      #Ok, we know we are not pointing at an invalid position of the array.       
      la $t3, fail                    #load address for fail pointer into $t3
      lw $a0, 0($t3)                  #load word at mem addy $t3 into $a0
      li $v0, 1 
      syscall
      

      最后,在使用syscall时尝试保持约定.例如,仅将寄存器$ a0和$ v0用于系统调用.不要将它们用于其他任何用途.如果您将整数读入$ v0,则在执行其他操作之前将其移至$ t0.

      Finally, try to keep a convention when you use syscalls. For example, use registers $a0 and $v0 only for syscalls. Dont use them for anything else. If you read an integer into $v0, then move it to $t0 before doing anything else.

      这就是我现在能想到的.正如某人在欺骗邮件(Rob Kennedy)中所说,请尝试也请教您的讲师,这就是为什么他得到报酬(我不是您的讲师,只是帮助之手).

      That's all i can think of right now. As someone said in the dupe post (Rob Kennedy), try asking your instructor as well, that's why he gets paid (i'm not your instructor, just a helping hand).

      这篇关于MIPS:确定测试分数列表是否通过/未通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆