100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
EECS 112/CSE 132>Organization of Digital Computers(Solutions Week 4) $17.49   Add to cart

Exam (elaborations)

EECS 112/CSE 132>Organization of Digital Computers(Solutions Week 4)

 2 views  0 purchase
  • Course
  • Institution

EECS 112/CSE 132>Organization of Digital Computers(Solutions Week 4)

Preview 3 out of 16  pages

  • May 6, 2022
  • 16
  • 2021/2022
  • Exam (elaborations)
  • Questions & answers
avatar-seller
Organization of Digital Computers

EECS 112/CSE 132

Solutions Week 4




Problem 1
Consider the following RISC-V loop:
LOOP: beq x6, x0, DONE
addi x6, x6, -1
addi x5, x5, 2
jal x0,
LOOP
DONE:
a. Assume that the register x6 is initialized to the value 10. What is the final
value in register x5 assuming the x5 is initially zero?


x6 = 10 , x5 = 0
LOOP: beq x6, x0, DONE // 𝑥6 = 10 ≠ 0
addi x6, x6, -1 // 𝑥6 = 10 − 1 = 9
addi x5, x5, 2 // 𝑥5 = 0 + 2 = 2
jal x0, LOOP // jump to LOOP

LOOP: beq x6, x0, DONE // 𝑥6 = 9 ≠ 0
addi x6, x6, -1 // 𝑥6 = 9 − 1 = 8
addi x5, x5, 2 // 𝑥5 = 2 + 2 = 4
jal x0, LOOP // jump to LOOP

….
LOOP: beq x6, x0, DONE // 𝑥6 = 1 ≠ 0
addi x6, x6, -1 // 𝑥6 = 1 − 1 = 0
Page 1 of 16

, addi x5, x5, 2 // 𝑥5 = 18 + 2 = 20
jal x0, LOOP // jump to LOOP

LOOP: beq x6, x0, DONE // 𝑥6 = 0 = 0

DONE:


x5 = 20

b. For the loop above, write the equivalent C code. Assume that the registers
x5 and x6 are integers acc and i, respectively.

for (i=10; i>0;
i--) acc =
acc + 2;


Problem 2
Translate the following C code to RISC-V assembly code. Use a minimum number
of instructions. Assume that the values of a, b, i, and j are in registers x5, x6, x7,
and x29, respectively. Also, assume that register x10 holds the base address of the
array D.


for (i=0; i<a; i++)
for (j=0; j<b; j++)
D [ 4 * j ] = i + j;


x5 = a , x6 = b , x7 = i , x29 = j
add x7, x0, x0 // = 0
LOOP1: beq x7, x5, DONE // go to DONE if =
addi x7, x7, 1 // = + 1
add x29, x0, x0 // = 0
Page 2 of 16

, Page 3 of 16

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 Pronurse. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

78310 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
$17.49
  • (0)
  Add to cart