I am in a Computer Assembly and Organization class at my school, and we have a piece of code in MIPS MARS that I can not figure out. Our teacher doesn't teach out of the book so there is no way for me to know how to code this in MIPS MARS. I understand how to assign the initial values into the $s registers, but have no idea how to code the if statements or how they should look. Any help would be appreciated because I can't learn from this teacher to save my life. We are supposed to code the following in MIPS MARS assembly language:
1) Use the MARS assembler submit a working program that will convert the following High level Java statement to MIPS Assembly code? (60 pts) Code the following branching statements. Let a = 10, b = 16, c = 16, d = 6, use register $s0 for a, $s1 for b and so forth.
if(a==b){
Z = a+a;
Z=Z+b+c+d;
}
if(a==b){
Z=a;
Else{
Z = (a+b+c)-d;
}
if (a != b){
Z=a;
Else{
Z = (a+b+c)-d;
}
- Go through a loop from 1 to 10 times, write out the loop counter.
- Calculate the summation of 10 numbers using a loop. Write out the result.
b
... if you can't figure out from the hint what is it actually doing, try to google the particular instruction (also most of the branch instructions are pseudo-instructions). One warning, if you would search for assembly conditional branching, and you will find some nice explanation for different CPU, it may talk about something like "flags". There's no such thing in MIPS, MIPS branching is always based on values provided as arguments to the branch instruction, so search for MIPS only. – Ped7gslt
will set destination to1
when first argument is less than second argument (otherwise value set is0
). In your task these would not help much, but sometimes having0/1
without branching is enough to calculate desired result. – Ped7g