Click here to Skip to main content
14,775,044 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I need to write a program with MIPS for an evaluation of an exam. If someone gets ≥ 40 points, he succeeded and if he gets <40 points, he failed.

At the beginning the variable "Success" get's 99, which means that we do not know if someone succeeded or not.

The task is to complete the program so that we get 1 for successful and 0 for not successful.



.data
Points : .word 42 # Exampoints
Success : .word 99 # 0 No, 1 Yes, 99 We don't know
Minimum: .word 40 # MinimumToSucceed 40 Points

.text
.globl main
.
.
.

What I have tried:

.data
Points : .word 42 # Exampoints
Success : .word 99 # 0 No, 1 Yes, 99 We don't know
Minimum: .word 40 # MinimumToSucceed 40 Points

.text
.globl main

main:

lw $2,Points
lw $3,Minimum
lw $4,Success

loop:blt $2,$3,end
li $4,1

end:li $4,0

li $2,10 #these two last lines are just to complete
syscall #the program without errors (not task related)

Oh i just discovered a problem: If i use numbers lower than 0 or greater than 99 for "Points", it still gives me 1 for sucessful (e.g 105 > 40) and 0 for failed (e.g. -5 < 40).

How can i integrate this in my program?
Posted
Updated 9-Jan-20 5:32am
v2
Comments
Kris Lantz 9-Jan-20 9:38am
   
This smells like homework. Have you attempted the problem, so that one might offer some guidance, over just the solution?
Kornfeld Eliyahu Peter 9-Jan-20 9:50am
   
Have you done ANYTHING on your own?
CP not much for a code-request site... It is more about help-yourself and CP will join in...
Patrice T 9-Jan-20 10:20am
   
Use Improve question to update your question.
So that everyone can pay attention to this information.
Kris Lantz 9-Jan-20 10:28am
   
You can check to make sure data is within the 0-99 bounds before checking the success/failed.
Member 14711617 9-Jan-20 10:43am
   
Is it possible to write a text with assembler? I do not know how to say "Number too big or too low".
Kris Lantz 9-Jan-20 10:48am
   
I personally am not familiar with MIPS syntax, but the first slide here might be useful. https://courses.cs.vt.edu/cs2506/Fall2014/Notes/L04.MIPSAssemblyOverview.pdf
Member 14711617 9-Jan-20 10:57am
   
Okay thanks tho. The only way to solve this problem i could think of is to add another line at .data, called "Lowest" for example. Since "Success" is already set to 99, a "Highest" won't be neccessary. At main it would look like this:

loop:blt $2,$5,fail # if lower than 0
loop:bgt $2,$4,fail # if greater than 99
loop:blt $2,$3,end
.
.
.
But we are not allowed to change the lines at .data afaik.

Tbh i think i will ignore this problem and just finish my task without considering points of lower than 0 or higher than 99. Since i solved the other tasks well, 1-2 points less won't matter. Thanks for your help :D

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900