100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
C to MIPS Actual Full Exam Questions With Correct Answers Success Guaranteed.. $12.99   Add to cart

Exam (elaborations)

C to MIPS Actual Full Exam Questions With Correct Answers Success Guaranteed..

 6 views  0 purchase
  • Course
  • MIPS
  • Institution
  • MIPS

arithmetic expression int f, g, h, i, j; $s0 (g + h) - (i + j) f = (g + h) - (i + j); $s1 i + j - correct answer MIPS add $s0, $s1, $s2 # $s0 = g + h add $s1, $s3, $s4 # $s1 = i + j sub $s0, $s0, $s1 # f = (g + h) - (i + j) simple if stateme...

[Show more]

Preview 2 out of 13  pages

  • August 22, 2024
  • 13
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • MIPS
  • MIPS
avatar-seller
RealGrades
C to MIPS

arithmetic expression



int f, g, h, i, j; $s0 (g + h) - (i + j)

f = (g + h) - (i + j); $s1 i + j - correct answer MIPS



add $s0, $s1, $s2 # $s0 = g + h

add $s1, $s3, $s4 # $s1 = i + j

sub $s0, $s0, $s1 # f = (g + h) - (i + j)



simple if statement:

if ( i == j ) $s1 i

i++ ; $s2 j

j-- ; - correct answer assuming $s1 stores i and $s2 stores j:

bne $s1, $s2, L1 # branch if !( i == j )

addi $s1, $s1, 1 # i++

L1: addi $s2, $s2, -1 # j--



Conditional: if-else:



if ( i == j ) $s1 i

i++ ; $s2 j

else

j-- ;

j += i ; - correct answer Once we've done the if-body, we need to jump over
the else-body

bne $s1, $s2, ELSE # branch if !( i == j )

, addi $s1, $s1, 1 # i++

j NEXT # jump over else

ELSE: addi $s2, $s2, -1 # else j--

NEXT: add $s2, $s2, $s1 # j += i



Conditional: compound condition with AND:



if ( i == j && i == k ) // if ( <cond1> && <cond2> )

i++ ; // if body

else $s1 i

j-- ; // else body $s2 j

j = i + k ; $s3 k - correct answer bne $s1, $s2, ELSE # cond1: branch if !( i == j )

bne $s1, $s3, ELSE # cond2: branch if !( i == k )

addi $s1, $s1, 1 # if-body: i++

j NEXT # jump over else

ELSE: addi $s2, $s2, -1 # else-body: j--

NEXT: add $s2, $s1, $s3 # j = i + k



Conditional: compound condition with OR:



if ( <cond1> || <cond2> )

i++ ; // if-body $s1 i

else $s2 j

j-- ; // else-body $s3 k

j = i + k ; - correct answer beq $s1, $s2, IF # cond1: branch if ( i == j )

# Notice branch on TRUE

bne $s1, $s3, ELSE # cond2: branch if ! ( i == k )

IF: addi $s1, $s1, 1 # if-body: i++

j NEXT # jump over else

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller RealGrades. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76669 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.99
  • (0)
  Add to cart