程序代写代做 compiler C algorithm data structure assembly Objectives

Objectives
• You will learn how to write and debug assembly language programs
• You will learn how to translate a high level C program into its corresponding assembly language. This will give you an idea of how a compiler works
• You will learn how data structures such as integers and arrays are represented in memory
• You will learn how to implement conditional statements, loops, and functions in an assembly language.

This laboratory exercise has two parts. Part A is a warm-up exercise, to get you acquainted with the simulator and RISC-V assembly language programming. Part B is the real exercise where you will implement a sorting routine in RISC-V assembly language.

For both parts of the lab, you are given starter code in the form of a skeleton file. You have to add your code to this file.

Simulator
You will be using an online RISC-V simulator called Venus (www.kvakil.me/venus/). Venus consists of an editor and a simulator. Venus will allow you to view the contents of the registers, and memory of the simulated RISC-V processor. That is how you will debug your program – by single stepping through your code and observing the memory contents and registers.
You must copy your code in to the editor then click the simulator tab to run your program. Venus has environmental calls that allows you to do basic I/O. (https://github.com/kvakil/venus/wiki/Environmental-Calls)

Part A (Warm Up Exercise) – 50 points

Skeleton code for this portion of the lab can be found in lab1a.skel. In part A you write a RISC-V assembly language program that prints the contents of an array that are greater than a given constant K. The output should display each integer that meets the above condition on a new line.

Note: Though this exercise seems quite simple, it is the building block of a powerful paradigm in high performance computing called map-reduce. You are basically implementing the map operation which involves iterating over a list and extracting values that satisfy a particular condition or are the result of applying a particular function (in this example the function is “greater than k”).
What do you have to do?
• Given an array of 10 numbers loop through them all
• For each number check if it is greater than a constant of your choice. The constant can be changed by changing the value K in the skeleton file.
• Print out the results one element per line.
• Download the skeleton file called lab1a.skel and add your code to it. Rename your file to lab1a.S where kerbos ID is the ID you use to login to your UC Davis email or MyUCDavis account.
• Comment your code explaining what the equivalent C operation would be (i.e. bge t0, t1, outsideloop #if(t0 < t1){ … }) • Comment your name and ID# at the top of the file Skeleton Code .data arrayOfNums: .word 0 .word 1 .word 255 .word 65536 .word 4294967295 .word 22 .word 314159 .word 161803 .word 42 .word 131929 K: .word 1337 .text .globl main main: ####Code here#### done: ####Exit using environmental calls#### Sample Output (Optional: Why does 4294967295 not get printed?) 65536 314159 161803 131929 Part B (Sorting Students) - 100 points In the second skeleton file attached you will find an array of structures (or student records) stored in the memory corresponding to the C declaration: struct student{ char *name; int final } Class[20]; Each record has two fields - The first field is the name of a student 8 characters long (including the null character at the end), and the second field is the final exam score (positive integer less than 100). Your task is to write a RISC-V assembly language program to sort the student records. Your program should be able to sort student records by the first letter of their name or their final exam score. You should be able to sort in ascending or descending order. The output of your program should be the sorted array printed one record per line - with Name and Final separated by a space. What do you have to do? • You have to use the BUBBLE SORT algorithm. No other sorting algorithm is allowed. • Download the skeleton file called lab1b.skel and add your code to it. Rename your file to lab1b.S where kerbos ID is the ID you use to login to your UC Davis email or MyUCDavis account.
• You are permitted to use only the environment calls for the Venus RISC-V simulator and RISC-V instructions.
• You should test your program for different values number of students, of student names and scores.
• You must print out the welcome message and data like in the sample outputs
• Comment your code explaining what the equivalent C operation would be (i.e. addi t0, x0, 6 #int j=6;)
• Comment your name and ID# at the top of the file
Skeleton Code
.data
Class:
.asciiz “Bill “
.word 87
.asciiz “Art “
.word 45
.asciiz “Peter “
.word 67
.asciiz “Miller “
.word 55
.asciiz “Wells “
.word 51
.asciiz “Rahim “
.word 90
.asciiz “Thomas “
.word 67
.asciiz “Garcia “
.word 49
.asciiz “William”
.word 77
.asciiz “Janice “
.word 55
.asciiz “Emma “
.word 82
.asciiz “Susie “
.word 69
.asciiz “Katie “
.word 59
.asciiz “Gizelle”
.word 59
.asciiz “Marie “
.word 66
.asciiz “Powell “
.word 87
.asciiz “Marie “
.word 80
.asciiz “Hannah “
.word 71
.asciiz “Kristen”
.word 60
.asciiz “Jones “
.word 50
NumOfStudents: .word 20
.text
.globl main
main:
####Your code here####

done:
####Exit using environmental calls####

Output Sample 1 (Ascending Scores)

Welcome to the Grade Sorting Program
Name Grade
Art 45
Garcia 49
Jones 50
Wells 51
Miller 55
Janice 55
Katie 59
Gizelle 59
Kristen 60
Marie 66
Thomas 67
Peter 67
Susie 69
Hannah 71
William 77
Marie 80
Emma 82
Powell 87
Bill 87
Rahim 90

Output Sample 2 (Descending Names)

Welcome to the Grade Sorting Program
Name Grade
Art 45
Bill 87
Emma 82
Gizelle 59
Garcia 49
Hannah 71
Jones 50
Janice 55
Kristen 60
Katie 59
Marie 80
Miller 55
Marie 66
Powell 87
Peter 67
Rahim 90
Susie 69
Thomas 67
William 77
Wells 51

Output Sample 3 (Descending Scores)

Welcome to the Grade Sorting Program
Name Grade
Rahim 90
Powell 87
Bill 87
Emma 82
Marie 80
William 77
Hannah 71
Susie 69
Peter 67
Thomas 67
Marie 66
Kristen 60
Katie 59
Gizelle 59
Miller 55
Janice 55
Wells 51
Jones 50
Garcia 49
Art 45

General hints
• Venus allows you to set breakpoints to pause the execution of your program by clicking the line of interest
• Venus allows you to inspect memory and the registers displayed in different formats (ASCII, hex, decimal etc) Use this to trace your sorting.
• Try writing out the code in C then try to reason out an equivalent assembly program
• When referencing data in memory think about the number of bytes that needs to be traversed from an initial address to get to some piece of data. Is the data a byte, short, word, or longer? How many bytes is each?