This lab will introduce you to the RISC-V assembly language programming using RARS. You will write aprogram with nested loops in the file Lab3.asm to write a specific pattern to a file by the name...

1 answer below »

This lab will introduce you to the RISC-V assembly language programming using RARS. You will write a

program with nested loops in the file Lab3.asm to write a specific pattern to a file by the name of

lab3_output.txt (which is generated by running your Lab3.asm file and does not exist prior to this action)

Make sure you properly follow the steps mentioned in the RARS site to download and install RARS on

your machine. Please approach a TA or tutor in your lab section if you have issues installing RARS on your

machine!

Since this is your very first foray into assembly programming, please read this document thoroughly without

skipping any sections!



CSE12 Lab 3: Looping in RISC-V Assembly Due November 11, 2022, 11:59 PM Minimum Submission Requirements Ensure that your Lab3 folder contains the following files (note the capitalization convention): ○ Lab3.asm This MUST have the correct file name (Lab3.asm) Else there is a penalty of 100% ○ README.txt Commit and push your repository ○ Complete the Google Form (link within the text) with the correct commit ID of your final submission. You absolutely MUST complete this Google Form correctly in order to be graded for Lab3. Failure to do so will result in a penalty of 100%. Objective This lab will introduce you to the RISC-V assembly language programming using RARS. You will write a program with nested loops in the file Lab3.asm to write a specific pattern to a file by the name of lab3_output.txt (which is generated by running your Lab3.asm file and does not exist prior to this action) Make sure you properly follow the steps mentioned in the RARS site to download and install RARS on your machine. Please approach a TA or tutor in your lab section if you have issues installing RARS on your machine! Since this is your very first foray into assembly programming, please read this document thoroughly without skipping any sections! Resources Much like how a high-level program has a specific file extension (.c for C, .py for python) RARS based RISC-V programs have an .asm extension. In the Lab3 folder in the course Google Slide, you will see 7 assembly files. They are meant to read (and understood) in sequence: 1. firstRARSprogram.asm – This program just prints “Hello World” on the output console. 2. add.asm – This program accepts two integers as user inputs and prints their addition result on the output console. 3. multiply.asm – This program accepts two integers as user inputs and prints their multiplication result on the output console. This file specifically shows you how to do loops in assembly 4. fileWriteDemo.asm – This program creates a file for write, and then writes a line of text into the file. Basically, it shows the basics to do a file Write in RARS. 5. fileReadDemo.asm – This program reads the file generated by the above .asm file and reads out its contents on the output console. Basically, it shows the basics to do a file Read in RARS. 6. patternDisplayDemo.asm – This program inputs a number n from user and generates a “* * * ….” Pattern depending on the value of n. This pattern is written into a file. Understanding how this code works will help you in writing the pattern required of this lab assignment into a file as well. 7. Lab3.asm – Some starter code has already been provided in this file which you will need to complete and then push to your Lab3 folder in your git repo. The starter code mainly revolves around macros that have been created for your benefit to create and write to the file lab3_output.txt. Please download these files and make sure to open them in RARS Text editor only. Else the comments and other important code sections won’t be properly highlighted and can be a hindrance to learning assembly language intuitively. Steps on opening, assembling and running an .asm file are provided later in this document. These 7 files have enough comments in the source code to jumpstart your understanding of RISC-V assembly programming if the lectures have not yet covered certain topics in assembly programming. Beyond these three files, you should have all the required resources in the Lecture Slides themselves, in the ppt files which have the title slide “Von Neuman and RISC- V”. These slides are very self-explanatory and it is encouraged you start reading them even if the instructor hasn’t started discussing them in lecture. For the usage of macros (which are utilized heavily in this lab to generate ecalls), please also refer to the RARS documentation on macros and ecalls as well. For lab3, you don’t even need to know what the inside of a macro block looks like so long you know just what it is supposed to do overall. Working in RARS Helpful tip: For lab3 and lab4, it is very useful to create two separate folders in your machine, lab3 and lab4. Make each folder the workspace for your respective lab. So, for the given lab, place the provided three .asm files in Lab3 folder along with a copy of the .jar RARS application file. This is where you will create your Lab3.asm file as well. Figure 1 Ideal workspace setup for lab3/lab4 https://drive.google.com/file/d/1IRsd2WfmakN7w8l2NQSTpR8Zv7I68Kae/view?usp=sharing https://github.com/TheThirdOne/rars/wiki/Environment-Calls Henceforth, run all .asm files pertinent to Lab3 on this local copy of the .jar RARS application. For reference, see my Lab3 workspace below in Windows Open the RARS application. You should get the window below. Figure 2 Opening the RARS application Let us open firstRARSprogram.asm by clicking File -> Open. Make sure the comments (which appear in green) are properly indented and haven’t been misaligned when you downloaded the file from the Google Drive. They should appear as shown below: Figure 3 Opening an asm file on RARS Make sure to thoroughly read the entire contents of this file in the text editor. Verbose comments have been provided to guide you along in explaining each step in the source code. This will be the norm for the other .asm files in the Lab3 folder in Google Drive as well. After you have read and understood the source code, it is time to assemble the program. Before you assemble, go to Settings and make sure you have the exact following options checked (or unchecked). For this course, you are allowed to use pseudo instructions. Pseudo instructions are those instructions which are not native to the RISC-V instruction set but the RARS environment has defined these new ones by a combination of actual RISC-V instructions. Permit pseudo instructions (this actually makes coding easier for you) and 64-bit operation. This should be done for every RARS code in CSE12! Figure 4 RARS setting Now click on Assemble (the Wrench and screwdriver icon). If correctly assembled, your Messages window should show the following information: Now Click on the Run button to Run the program. You will get the following output: Figure 5 Successful assembly Figure 6 Successful Runtime Now try running the other .asm files. One word of caution when your text editor contains multiple opened files is to make sure assembling the correct assembly file. For example, the window below, multiple files are open and I want to only assemble and run add.asm. Then my tab for add.asm should be highlighted as shown below. Only then can I click Assemble, then Run. Figure 7 Multiple tabs open A helpful feature in RARS RARS has a helpful feature where instead of Running the entire program at once, you can Run One Step At A Time. The corresponding button is beside the Run button. This allows you to sequentially execute each line of code and see how it affects the values of the Registers as they appear to the right of your screen. Regarding Macros The file multiply.asm makes extensive use of macros to help create a more readable main program section (Instructions on how to use macros are provided in the file comments). So does the source code in the files fileWriteDemo.asm, fileReadDemo.asm and patternDisplayDemo.asm (we will discuss more on the aspect of file reads and writes that these .asm files do shortly). Based on how we define a macro in the source code, it is tempting to confuse it with a function. However, macros are NOT functions! Whenever you place multiple instances of the same macro in your code, you are copying the macro’s contents in those code areas for the same number of times. Naming new files in RARS When you want to open a new file on RARS, go to File->New. The default file name riscv1.asm shows up on the tab. When you save this file, you MUST make sure that you are explicitly defining the correct extension(.asm) as shown below. Figure 8 Saving a new file in RARS About file reads and writes in RARS File creation and manipulation is a very common part of the learning curve whenever you learn of a new high level programming language, be it C or Python. For lab3, we will be writing the display pattern to a file so that it is more convenient for the auto grader. The auto grader would do a file text equality check between the file generated by your lab3 source code and the one in its deck and accordingly provide you points (or not!). To give you a demo, we have two reference assembly source code files: fileWriteDemo.asm and fileReadDemo.asm. The former file creates a file with the name fileDemo.txt. The following text is written into fileDemo.txt: “These pretzels are making me thirsty!”. The latter file fileReadDemo.asm contains code to open fileDemo.txt and extract out this text to display on the output console of RARS. The following two images shows the results of having run fileWriteDemo.asm and then fileReadDemo.asm. https://www.cs.utah.edu/%7Egermain/PPS/Topics/C_Language/file_IO.html https://realpython.com/read-write-files-python/ Figure 9 A new file generated in my workspace after running fileWriteDemo.asm. Note the file size to be shown as 1KB despite us having written only 38 bytes of data into it. That is because a file also contains metadata and a header generated by your OS as well. Figure 10 RARS output console after running fileReadDemo.asm Both fileWriteDemo.asm and fileReadDemo.asm use many macros within the source code to make the main .text section of the code more programmer friendly in terms of writing. For the purposes of lab3, you DO NOT need to understand WHAT these macros are doing within their definition block. It suffices to know simply what the result of executing a macro in your source code simply does. However, understanding the macros does help to build your foundation in RARS programming well. One thing to note is that since lab3 does not focus on proper function coding in
Answered 2 days AfterNov 05, 2022

Answer To: This lab will introduce you to the RISC-V assembly language programming using RARS. You will write...

Nidhi answered on Nov 07 2022
45 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here