用于确定测试成绩通过/失败的 MIPS 程序
我正在编写一个 MiPS 程序,该程序将检查 15 个测试分数的列表。 它将从终端输入。 通过标准是 50 分。终端的输出将包括每个类别的分数以及通过和失败的学生人数。 我应该使用输入提示和输出语句。 请我需要一些帮助,只需要一些建议如何去做。
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'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
I have a loop:
addi $t1,$t1,-1
li $v0,4
la $a0,prompt
syscall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不想放弃它,所以我会提出一些指导方针。
您应该阅读汇编器、链接器和 Spim 模拟器。 这有很多帮助。
所以就这样了。
创建两个 15 字数组。
将循环控制变量加载到某些寄存器上。
现在在这个循环中读取值
然后读取该值(假设您将其存储在寄存器 t4 中)并决定是否将其存储在失败向量或通过向量中。
完成所有 15 个值后,打印出向量。 这有点棘手。
在使用您的程序之前,您应该用一些无效值填充两个向量,例如 -1。
因此,当您将矢量打印到屏幕时,当您发现其中一个无效值时,应该停止。 当你这样做时,保留一个计数器来显示有多少通过/失败。
在伪代码
汇编中(填空)
另一个棘手的问题是这些向量的索引。 由于它们是单词数组,因此您应该将循环控制变量(C 中的经典 i 变量)乘以 4(假设为 32 位单词)来索引向量。 如果它们是字节数组,则不需要乘法。 如果它们是短数组...(好吧,你明白我的意思)
例如:
让变量 i 存储在寄存器 $t1 中
结果是:
所以现在你可以加载/存储到passed_vector[i]
解决这类问题的一种方法(即用汇编语言编写)是用C(或你知道的其他语言)编写程序,然后将其逐条指令翻译成汇编。
I don´t want to give it away, so i´ll throw some guidelines.
You should read Assemblers, linkers and the Spim simulator. It´s a lot of help.
So here it goes.
Create two 15- word arrays.
Load on some register the loop control variable.
Now inside this loop read values
Then read this value (suppose you have it in register t4) and decide whether to store it in fail vector, or pass vector.
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.
In pseudo-code
assembly (fill in the blanks)
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)
For example:
and let variable i be stored in register $t1
would turn out as:
So now you could load/store to passed_vector[i]
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.
好的,这是如何加载两个整数数组(仅此而已)
Ok, here's how to load both integer arrays (and only that)