MIPS程序确定测试等级的通过/失败 [英] MIPS program to determine pass/fail for test grades

查看:59
本文介绍了MIPS程序确定测试等级的通过/失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个MiPS程序,它将检查15个测试分数的列表.并且它将从终端输入.合格标准为50分.终端的输出将包括每个类别的得分以及合格和不及格的学生人数.我应该使用输入提示和输出语句.请我需要一些帮助,只需要一些建议就可以了.

I'm writing a MiPS program that will examine a list of 15 test scores. And it is going to input from the terminal. The passing criterion is the score of 50. The outputs to the terminal will include the scores in each category and the number of students passing and failing. I should use input prompts and output statement. Please I need some help, just need some advice how to do it.

main:
 li $t1,15         #load 15 into $t1

 la $a1,array      #load a pointer to array into $a1

我有一个循环:

addi $t1,$t1,-1

li $v0,4

la $a0,prompt

syscall

推荐答案

我不想放弃它,所以我会提出一些指导原则.

I don´t want to give it away, so i´ll throw some guidelines.

您应该阅读组装器,链接器和Spim模拟器.有很多帮助.

You should read Assemblers, linkers and the Spim simulator. It´s a lot of help.

就这样.

创建两个15字的数组.

Create two 15- word arrays.

 .data
 fail_vector: .word  -1,-1,-1 ...    #15 invalid words 
 passed_vector: .word  -1,-1,-1 ...  #15 invalid words 

在某些寄存器上加载循环控制变量.

Load on some register the loop control variable.

 li $t1,15
 beq $t1,$zero,END
 addiu $t1,$t1,-1

现在在此循环中读取值

 syscall...     #SYS_READ

然后读取该值(假设您将其保存在寄存器t4中),并决定是将其存储在失败向量还是通过向量中.

Then read this value (suppose you have it in register t4) and decide whether to store it in fail vector, or pass vector.

     addiu t4,t4,-50     #subtract 50 from input value. 
     blez  t4,FAILED     #If its lower than 0, then read value is lower than 50 ->FAIL
PASSED:
     #STORE VALUE INTO passed_vector

FAILED:
     #STORE VALUE INTO failed_vector

完成所有15个值后,请打印出矢量.这有点棘手. 在使用程序之前,应使用无效值(例如-1)填充两个向量. 因此,当您将矢量打印到屏幕上时,当您发现此无效值之一时,应该停止操作.而当您使用它时,请保留一个计数器,以显示通过/失败的数量.

When you are done with all the 15 values, print out the vectors. This is kind of tricky. Before using your program, you should fill both vectors with some invalid value, like -1. So when you are printing vector to screen, you should stop when you find one of this invalid values. And while you are at it, keep a counter to show how many passed / failed.

使用伪代码

for both arrays
   for (i in (0,15) and array[i] not -1)
        print array[i]
        add 1 to scores count //to count passed - failed test scores.

组装(填空)

END:
     li $t4,15
     li $t1,0
     beq $t1,$t4,EXIT   #condition. While ( i < 15) kind of thing.
     addiu $t1,$t1,-1

     #print out vectors and keep count on other registers
     #then print them out.

     syscall... #SYS_WRITE

EXIT: #exit syscall here.

另一个棘手的问题是这些向量的索引.由于它们是单词数组,因此应将循环控制变量(C中的经典i变量)乘以4(假定为32位单词)以对向量进行索引.如果它们是字节数组,则不需要乘法.如果它们是短数组...(好吧,我明白了)

Another tricky issue is the indexing of these vectors. Since they are arrays of words, then you should multiply by 4 (assuming 32 bit words) the loop control variable (classical i variable in C) to index the vector. If they were byte arrays, then no multiplication would be needed. And if they were short arrays...(well, you get my point)

例如:

passed_vector[i] #(C style sintax)

,然后让变量i存储在寄存器$ t1中 会变成:

and let variable i be stored in register $t1 would turn out as:

  sll $t2,$t1,2             #i * sizeof(word)
  la  $a0,passed_vector     #$a0 points to passed_vector
  add $a0,$a0,$t2           #$a0 now points to passed_vector + i   

所以现在您可以加载/存储到passed_vector [i]

So now you could load/store to passed_vector[i]

  sw  $t3,0($a0)            #0($a0) is passed_vector[0]
  lw  $t3,0($a0)

解决这类问题的一种方法(即用汇编编写)是用C(或您知道的其他某种语言)编写程序,然后逐条指令将其翻译为汇编.

One way of solving these kind of things (that is, writing in assembly) is to write the program in C ( or some other language that you know ), and then translating it to assembly, instruction by instruction.

这篇关于MIPS程序确定测试等级的通过/失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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