代写CSE12 Lab 3: Looping in RISC-V Assembly代做Python编程

CSE12 Lab 3: Looping in RISC-V Assembly

Submission by due date at 11:59 PM

Minimum Submission Requirements

Ensure that your Gradescope submission contains the following file:

○           Lab3.asm

Objective

This  lab  will  introduce  you  to  the  RISC-V  assembly  language  programming  using  RARS  (RISCV Assembler and Runtime Simulator). You will write a program with nested loops in the provided file Lab3.asm to write a specific pattern to a file by the name of lab3_output.txt (which will be generated by running your submitted Lab3.asm file. lab3_output.txt 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 a .asm extension.

In the Lab3 folder in the course Google Slide, you will see 7 assembly files. They are meant for you to read (and understand) 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 writing, 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  submit  to  your  Gradescope  autograding  portal.  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 the RARS Text editor only. Doing otherwise will cause comments and other important code sections to not be properly highlighted and can be a hindrance to learning assembly language intuitively. Steps for opening, assembling and running a  .asm file are provided later in this document.

These 7 files have enough comments in the source code to jump start 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 lecture pages following the topic Von Neuman and RISC- V”. These lecture slides are very self- explanatory. You are encouraged read ahead even if the instructor hasnt started discussing them in lecture. You are also encouraged to read the excellent RARS documentation which can be found by clicking “help” on the RARS program, or at these URLs: https://github.com/TheThirdOne/rars/wiki and https://github.com/TheThirdOne/rars

For the usage of macros (which are utilized heavily in this lab to generate system calls refererred to as 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 recommended that you 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 all the provided  .asm files in the Lab3 folder along with a copy of the .jar RARS application file, and run RARS from there. This is where you will create your Lab3.asm file as well.

Figure 1 Ideal workspace setup for lab3/lab4

Henceforth, run all .asm files pertinent to Lab3 on this local copy of the .jar RARS application. 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). 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:

Figure 5 Successful assembly

Now Click on the Run button to Run the program. You will get the following output:

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 of assembling the correct assembly file. For example, in the window below, multiple files are open.  If 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 within Gradescope will do a file text equality check between files generated by your lab3 source code and expected correctly generated files 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.

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 RISC-V assembly, it can get very difficult to keep track of random unintentional instances of your registers to change value. For instance, in C or Python, you can define a variable temp, assign it a specific value, and be rest assured that this  variable  does  not  change  from  the  assigned  value  during  code  compilation  or  runtime  unless explicitly told to. However, in a large source code assembly, working with a limited number of registers means that it is very difficult to keep track of each individual register value unless you are very careful.

We will deal with register preservation in lab4 but in lab3, you will only be asked to ensure that you do not use specific registers in your Lab3.asm source code. The list of these taboo registers will be highlighted in the section later on Lab3

Besides  the  aforementioned  2  files  related  to  file  write  and  read,  we  also  have  a   3rd     .asm  file, patternDisplayDemo.asm. The source code in this file, once run, asks as input an integer n and then prints the pattern “* “ n number of times horizontally.

Figure 11 Output console after running patternDisplayDemo.asm for user input n=3 and7. In both cases, make sure to check the contents of the created file patternDisplay.txt as well

Similar to patternDisplayDemo.asm, Lab3.asm will also make use of loops (nested loops to be precise) to generate a pattern based on the value of n inputted by the user. Thus, you should thoroughly read and understand the working of source code in patternDisplayDemo.asm.

Lab3 Programming Assignment

This program will print out a pattern with stars (asterisks, ascii hex code 0x2a) and blank space (ascii hex code 0x20) and the newline character ‘\n’(ascii hex code 0x0a).

1.          It will first prompt for the height of the pattern (i.e., the number of rows in the pattern). If the user enters an invalid input such as a negative number or zero, an error message will be printed and the user will be prompted again. These error messages are listed in the starter code in the Lab3.asm file provided.

2.          Then your program  should generate the following pattern, a " right-angled triangle", using the aforementioned characters. Refer to test cases in testCases sub folder in Lab3 folder for examples.

3.          This entire pattern generated from the user input of n is written to the file lab3_output.txt.

The actual task of opening the file lab3_output.txt and writing the contents to it is borne by macros used in starter code included in the Lab3.asm file. Consider the screenshot of the Lab3.asm file below:

Figure 12 Lab3.asm screenshot

As you can see, you should write down your code ONLY within the area indicated by the comments. The way this code works regarding file manipulation is as follows:

When a file is created in RARS, it is assigned a file descriptor ID, in the form. of an integer number. Future references to this file through macros are then made by referring to this file descriptor ID number. Once we create a file, we first need to set aside memory space within our RISC-V memory where data to be written to the file is kept. This space is referred to as a “memory buffer” . In Lab3.asm, we have defined the memory space starting from address 0x10040000 as our internal memory buffer. Specifically, we hold a doubleword (64 bits) at this address which keeps track of how many bytes we intend to finally write to the file. 0x10040008 onwards, we start collecting the bytes that will be written into the file

lab3_output.txt.

In your student code, you can update the file buffer with any character with the macro write_to_buffer. For example, I want to the write the character sequence “****\n” to my memory buffer within Lab3.asm’s student code section. Then I would need to write the following student code as shown next:

Figure 13 Modified Lab3.asm screenshot

Run this Lab3.asm file and open the generated lab3_output.txt in a text editor. Specifically, if you are using Notepad++ (which is strongly recommended), make sure to apply the setting: View->Show Symbol ->Show All Characters. This will make characters such as null and newline visible.

Figure 14 lab3_output.txt screenshot from running modified Lab3.asm

As you can see, the blank space appears as an orange dot, newline as LF (LineFeed) and null as NUL.

You can see these characters as they reside in the file buffer in memory too on RARS as shown below. If you go to Execute window after running this modified Lab3.asm, selecting 0x1004000 for view and enabling ASCII view, you will get the following screenshot:

Figure 15 “* ** *\n” data as it resides in file buffer

Note that within each individual cell in the Data Segment matrix above, we should read the bytes from right to left.

NOTE: For your student starter code, you MUST NOT use any of the registers: t0 to t6, sp.  a0 to a7 should only be temporarilly used to pass parameters or receive parameters from macros.  Using the   registers s0 through s11 should be enough for Lab3 assignment.

Example of running the actual correct Lab3.asm source code

The following is a screenshot showing the runtime of the actual solved Lab3.asm code:

Figure 16 Solved Lab3.asm runtime demo

When we open the generated lab3_output.txt file, we get the following text:

\Figure 17 lab3_output.txt screenshot

Your student code MUST display the prompts and error messages in response to user input EXACTLY as shown in Figure 16. Please make use of the provided strings in the .data section of the starter code in Lab3.asm to make sure you do not use any other type of sentence!

NOTE: Although you are not required to print each row in the pattern on your output console, doing so

(as shown in Figure 16 ) will greatly help in the real time code debugging. So, it is strongly advised to do

so.

Test Cases

The Lab3 folder in the Google Drive contains some test cases in testCases  subfolder for the case when user input was n=1, 3, 6, 8, 30. Make sure your code output generates the exact same alignment of characters as provided there for the corresponding n input in your student code.

Automation

Note that our grading script. is automated, so it is imperative that your program’s output matches the specification exactly. The output that deviates from the spec will cause point deduction.

Files to be submitted to your Lab3 gradescope portal

Lab3.asm

-This file contains your pseudocode and assembly code. Include a header comment as indicated in the documentation guidelines here.

A Note About Academic Integrity

This  is the  lab  assignment where most  students  start  to  get  flagged  for  cheating.  Please  review  the pamphlet  on Academic  Dishonesty and  look  at  the  examples  in  the  first  lecture  for  acceptable  and unacceptable collaboration.

You should be doing this assignment completely all by yourself!

Grading Rubric (100 points total)

The  following  rubric  applies  provided  you  have  fulfilled  all  criteria  in Minimum Submission Requirements. Failing any criteria listed in that section would result in an automatic grade of zero which cannot be legible for applying for a regrade request.

20 pt Lab3.asm assembles without errors (thus even if you submit Lab3.asm having written absolutely no student code, you would still get 20 pts!)

80 pt output in file lab3_output.txt matches the specification:

20 pt error check zero and negative heights using the convention shown in Figure 16

20 pt prompts user until a correct input is entered as shown in Figure 16

20 pt number of rows match user input (i.e., if n=6, the pattern would have 6 row

20 pt correct sequence of stars and newline characters on each row

Legal Notice

All course materials and relevant files located in the Lab3 folder in the course Google Drive must not be shared by the students outside of the course curriculum on any type of public domain site or for financial gain. Thus, if any of the Lab3 documents is found in any type of publicly available site (e.g., GitHub, stack Exchange), or for monetary gain (e.g., Chegg), then the original poster will be cited for misusing CSE12 course-based content and will be reported to UCSC for academic dishonesty.

In the case of sites such as Chegg.com, we have been able to locate course material shared by a previous quarter student. Chegg cooperated with us by providing the student's contact details, which was sufficient proof of the student's misconduct leading to an automatic failing grade in the course.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图