0% found this document useful (0 votes)
5 views

Lab3

This document outlines the tasks for CS204's third lab focused on RISC-V ISA using the Venus simulator, with a deadline of March 4, 2021. It includes various programming tasks such as loading values into memory, implementing control instructions, and writing procedures for different operations. Additionally, students are encouraged to document their learnings and insights from the lab experience.

Uploaded by

2022mcb1318
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab3

This document outlines the tasks for CS204's third lab focused on RISC-V ISA using the Venus simulator, with a deadline of March 4, 2021. It includes various programming tasks such as loading values into memory, implementing control instructions, and writing procedures for different operations. Additionally, students are encouraged to document their learnings and insights from the lab experience.

Uploaded by

2022mcb1318
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS204 - Computer Architecture

Practice Lab - 3
Date: 26th Feb 2021.
Not graded. Deadline: 4th Mar 2021. Attempt at the earliest.
Working with RISC - V using Venus

This is our third lab with RISC-V ISA and Venus simulator. Below tasks are not
exhaustive but are only indicative for your practise. Keep up the practice of arranging
your code using the assembler directives. Also, continue to preload the data you want to
work with.
As you start exploring with control instructions, having a visual of PC of each instruc-
tion will be very handy. So, start observing PC in Venus https://venus.cs61c.org/ (Dont
worry about Cache right now, we’ll look at it in-depth in Module 3 of the course).

Few of the tasks are repeat of tasks you attempted in Lab 2, with a small change. So
you need not explicitly work on Lab 2 tasks if you have not completed them.

Task 1: Task 1 of Lab 2 was to load the value 0xdeadbeef at the memory location
0x1000000. Most likely you would have used instructions like li and la to fill the registers
with such 32bit values. Try to do the same task by avoiding li and la instructions as they
are pseudo instructions.
a) Think about using logical instructions for this (Task 4 in Lab 2 ?).
b) Use instructions lui and auipc.

Task 2: In the previous lab, one of the tasks was -


Use the shift and bit-wise operations to complete the task.
Write RISC-V code that extracts bits 16 down to 11 from register x5 and uses the value
of this field to replace bits 31 down to 26 in register x6 without changing the other bits of
registers x5 or x6. (Be sure to test your code using x5 = 0 and x6 = 0xffffffff. Doing so
may reveal a common oversight.)
Let’s modularize this task - read the bit positions “16”,“11”,“31”, “26” from memory lo-
cations and perform the same task on values read into registers x5 and x6 from memory.
Come up with a procedure for this.

Task 3: Realizing a ‘switch’ statement in RISC-V: Part II


In the previous lab, one of the tasks was -
Assume that there is a switch statement with three possible cases other than default. Write
a RISC-V code to realize this switch.
a) We have studied the jal and jalr instructions in class. Using these instructions, redo the
same task.
b) Now, after you complete (a), move the switch functionality to a procedure. Remember
that x0, x1, x2 have their own specific purpose.

Task 4: In the previous lab, one of the tasks was -


Realizing a loop in RISC-V.
Using the control instructions we have studied in class, write a code that will perform the
following tasks on elements in an array. For simplicity, consider an array of 10 elements
in range [-50, 50]. As usual, preload the values of the 10 elements into the memory (Hint:
Did you try var1: .word 10, -20, 30, 40, 5 ? ) and load one of the registers with
the base address of this array.
1. Perform addition of all the elements.
2. Add those elements which are greater than a value, say, 5.
3. Consider only the positive elements which are below a value, say, 40.
4. Add only the negative elements.
5. Add all the elements which are greater than or equal to 35, considering them as unsigned.

In this lab, write a single code to perform one (selected as a number read from a memory
location) of the five tasks, using a switch statement. Further, write each of the tasks as a
procedure. You can reuse your code of previous lab.

Task 5: Procedure calling a procedure


Write a program that calls a procedure to return with the final grade for a subject (say,
your favourite CA!). The procedure would in turn call other procedures like - proc best4,
proc best5, weighted avg, grade, etc. Assume 7 theory assignements (pick best 4), 7 quizzes
(pick best 5), 4 lab assignments (pick 3), 2 lab tests, 1 lab project, 1 mid term and 1 end
term exam. Weightage of each - 5%, 10%, 5%, 10%, 10%, 25%, 35%, respectively. To
make things interesting, let us assume we have only 10 (x0 - x9) registers at our disposal
(in stead of 32!). Remember that x0, x1, x2 have their own specific purpose too. Consider
just integers and neglect any decimals.

Task 6: Write a procedure “MEMCMP” for performing a byte-by-byte comparison of


two sequences of bytes in the memory. The procedure should accept three input parameters
in registers representing the first address (x5), the second address (x6), and the length of
the sequences to be compared (x10). It should use a register (x11) to return the count of
number of comparisons that are a mismatch.

Task 7: Write a procedure “ALLCAPS” that accepts a single parameter in a register


(x13) representing the starting address STRNG in the memory for a string of ASCII char-
acters in successive bytes representing an arbitrary collection of sentences, with a NULL
control character at the end of the string. The task of the procedure is to scan the string
beginning at address in x13 and replace every occurrence of a lower-case letter (‘a’ - ‘z’)
with the corresponding upper-case letter (‘A’ - ‘Z’).

Task 8: Let’s look at recursion now!


1. Write a recursive procedure for calculating factorial of a given number.
2. For better understanding of how recursion is different from iterative process, write iter-
ative version of calculating factorial of a given number.

Task 9: Once you are finished with all the above tasks, upload a single text file docu-
menting your learnings and interesting aspects that you have noticed in Lab3. Write point-
wise statements and not paragraphs. You can also mention any of the programs/logics that
you have (or want to) explore with RISC-V ISA. Upload the file by 4th Mar 2021 11.55PM.

You might also like