代写CSE12 Lab 4: Simple CSV File Analysis代写Python语言

CSE12 Lab 4: Simple CSV File Analysis

Due at 11:59 PM on the marked due date

Objective

The objective of this lab is to learn about function calling, RISC-V protocols for the use of registers.

This lab takes as input a CSV (comma separated values) file (.csv extension) that is used for generating tabular data in spreadsheets. Specifically,for this assignment, you will NEED to assume this CSVfile was generated under

Windows (the reason will be explained shortly).  Consider the data.csv file below as it appears when you open it in Excel as an example.

Figure 1 data.csv file in Excel

This file shows the stock returns from an investment portfolio over a year. The “A” column contains the stock name and the “B” column indicates the returns in USD (You can assume that there are no negative stock returns in any of our CSV data files).

You will run the file lab4_testbench_rv32_rev#.asm file in RARS which takes data.csv as its  input CSV file. Doing so will yield the following analysis, based on the calculations made by the assembly files that you will be submitting):

1. Find the total file size in bytes (excluding any metadata generated by your OS)  (length_of_file.asm)

2. List the dollar amount of all the input records.  (input_from_record.asm)

3. Provide the name of the stock that gives the maximum income.  (maxIncome.asm)

4. Provide the name of the stock that gives the minimum income.   (minIncome.asm)

5. Calculate the total income generated from all stocks

When you run via RARS lab4_testbench_rv32_rev#.asm with the .asm files shown above completed by you, you will get the output console as shown below:

Figure 2 After running the lab4_testbench_rv32_rev#.asm file with the Lab4 assignment fully completed

About the Windows CSV file format

To distinguish between each entry/row/record in the spreadsheet format of the CSV file, the following convention is adopted depending on the OS :

Windows - Lines end with a  and a  character

Linux  - Lines end with only a  character

Macintosh (Mac OSX) - Lines end with only a  character

Macintosh (old) - Lines end with only a  character

where is the carriage return (‘\r’) character and  is the line feed/newline (‘\n’) character.

If you open the provided data.csv file in Notepad++ on Windows with “Show all Characters” enabled, then you should see the following text showing the placement of the carriage return and line feed characters. .

Figure 3  data.csv on Notepad++ on Windows

So, for example, if I were to express record 2 from data.csv as  a  string  of characters in RARS, I would write: “Kramerica,0\r\n”. If you are using an OS that is NOT Windows, it is likely that data.csv would not open correctly due to the encoding differences. If you have a text editor like Notepad++ that allows you to see all characters, make sure that the “\r\n” appears for each record in the file as shown in Figure 3.      This is the case for the data.csv that we include in the directory.

Another assumption that we will state at this point is that we expect that in each record, the name of the stock is followed by the “,” and then immediately by the stock price expressed as an unsigned integer in base 10. So, with record 2 as an example, we will never have a situation where it is written as “Kramerica, . . 0\r\n”  where the 2 red dots indicate two blank spaces. This assumption makes the CSV file analysis by RARS easier to code.

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 Lab4 folder in the course you will see  9 assembly files. They are meant to be read (and understood) in sequence and they will provide you with lotsof hints as to how to build your program:

1. add_function.asm – This program accepts two integers as user inputs and prints their addition result. The actual addition is done through calling a function, sum. Sum accepts two arguments in the a0, a1 registers and returns a0+a1 in a0 register

2. multiply_function.asm – This program accepts two integers as user inputs and prints their multiplication result. The actual multiplication is done through calling a function, multiply. Multiply accepts two arguments in the a0, a1 registers and returns a0*a1 in a0 register. This function in turn calls the function sum, described previously, to do a particular addition. Thus, multiply function is an example of a nested function call, a function which itself calls another function, sum in our case.

3. The  lecture slides provide a lot of information about register calling and saving conventions. Studying  the comments in add_function.asm, multiply_function.as alongside with the notes should be sufficient to create to allow you to complete this assignment.

4. lab4_testbench_rv32_rev#.asm - This is the main testbench program you will run upon completion of all coding in Lab4 to ensure your Lab4 assignment works as expected. This file is initially provided such that if you run it as it is (with the other .asm files in the same directory), you will still get partially correctly generated output.  This testbench will also run the the function allocate_file_record_pointers from the allocate_file_record_pointers.asm which will aid you in writing your program. DO NOT MODIFY THE TESTBENCH FILE.

5. allocate_file_record_pointers.asm - This .asm file contains a function that creates an array in memory of pointer pairs.   These pointer pairs indicate 1) the location of the start of a string corresponding to the stock name and 2) the start of a location containing the stock price for each and every record/entry coming from the data.csv file. This function has been fully written out for you. DO NOT MODIFY THIS FILE.

6. macros_rv32_rev#.asm - This file contains useful macros, mostly to do I/O, it uses and modifies a# registers, so be careful. Become familiar with these functions. They are your friends.

6. income_from_record.asm - This. asm file contains a function that you will write to convert the string data from the income of a record/entry in the spreadsheet and convert it into an integer. Example, convert the string “1234” into the actual integer 1234 in base 10.

7. income_from_record_ideas_asm - This file provides some ideas for implementing income_from_record.asm.

7. length_of_file.asm - This. asm file contains a function that you will write to find the total amount of data bytes in the csv file. Refer to Figure 2 for an example.

8. maxIncome.asm - This. asm file contains a function that you will write to determine the name of the stock that has the maximum income in the csv file. Refer to Figure 2 for an example.

9. minIncome.asm - This. asm file contains a function that you will write to determine the name of the stock that has the minimum income in the csv file. (Figure 2 fails to  show the corresponding output. It’ll be added later)

10. totalIncome.asm - This. asm file contains a function that you will write to sum up all the stock incomes in the csv file. Refer to Figure 2 for an example.

Please download all these files and make sure to open them in the RARS Text editor only. Otherwise the comments and other important code sections may not be properly highlighted and it can be a hindrance to learning assembly language intuitively.

These  files  have  enough  comments  in  the  source  code  to jump  start  your  understanding  of RISC-V  assembly programming for Lab 4 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. The 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.

Please read the provided files carefully.    You can learn a lot about assembler from reading these files.   Note that using macros resembles calling functions.    The macros have been written to make use of the a# registers, so don’t assume that any values in your a# registers remain valid after calling a macro.

Memory arrangement as defined in Lab4

The memory of RISC V is used as per the given requirements.

File Data Buffer

The data.csv file is treated as the default input file.  It’s contents are store in the file buffer location 0xffff0000 (referred to as MMIO).

Figure 4  data segment window forMMIO after running completed Lab4 assignment.

The input is achieved when the provided fileRead macro found in lab4_testbench_rv32_rev#.asm is executed. Your code does not need to do this.

For  reference,  from  Figure  4,  note  where  the  first  record  in  the  given data.csv file,  “Kruger Industrial Smoothing,365\r\n” is found. The location of the letter K’(encoded in ASCII as  byte 0x4b or 64 in base 10) is at 0xffff0000. The location of the character digit ‘3’, i.e. the start of the income,(encoded in ASCII as  byte 0x33 or 51 in base 10) is at 0xffff001c. If you count the bytes in the string “Kruger Industrial Smoothing,365\r\n” with ‘K’ being the 0th character, then ‘3’is the 28th character (0x1c), so this makes sense.

File Record Pointers

We need a systematic way to reference the memory locations where the stock name and income from the file buffer at 0xffff0000. Remember that the stock names and stock incomes can be both of varying lengths of characters. Thus, we set aside the memory location 0x10040000 (heap) for a table containing the locations (addresses) of the first character appearing for each stock name and income respectively (i.e. one for the name, one for the number) of each record in the CSV file.

Figure 5 data segment window for heap after running completed Lab4 assignment.

This    is     achieved     when     the    testbench     (lab4_testbench_rv32_rev#.asm) runs     the    provided     function allocate_file_record_pointers with the arguments in a0 and a1 registers being the file size in bytes (119 in our given example from data.csv) and the starting address of file buffer (0x0ffff0000 in our given example from data.csv), respectively.   The allocate_file_record_pointers function  is provided in the allocate_file_record_pointers.asm file separately through the .include statement in lab4_testbench_rv32_rev#.asm.

For reference, from Figure 5, note in our example data.csv the first record’s location of start of income name (0xffff0000) and income value(0xffff001c) are stored as words in consecutive heap memory locations 0x10040000 and 0x10040004 respectively. Likewise, the second record’s (i.e. “Kramerica,0\r\n”) location of start of income name  (0xffff0021) and income value(0xffff002b) are  stored  as  words  in  consecutive  heap  memory  locations 0x10040008 and 0x1004000c respectively. And so on and so forth. It is left as a HIGHLY recommended exercise that the student verifies this pattern for the remaining records in the CSV file and how they are allocated in the memory locations as shown in Figure 5. As we see in Figure 5, the  10 non zero heap memory locations from 0x10040000 to 0x10040024 indicate there were originally 10/2 = 5 records in our data.csv file. This value (no. of records) is returned in a0.




热门主题

课程名

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
站长地图