首页 > > 详细

辅导program编程、辅导C/C++程序语言

Lab 4: Assembly vs C Programming
Due Friday 11 March 2022, 11:59 PM
Minimum Submission Requirements
● Ensure that your Lab4 folder contains ONLY the following files
(note the capitalization convention):
○ lab4_part1.s
○ lab4_part1_test.hex
○ lab4_part2.s
○ lab4_part2_test.hex
○ lab4_part3.c
○ lab4_part3.hex
○ README.txt
● Commit and push your repository
● Complete the Google Form with the correct commit ID of your final submission
before the due date.
Lab Objective
In this lab, you will write the code to perform some primitive graphics operations on
a simulated memory-mapped bitmap display in emulsiV. You will implement the necessary
functions with a combination of RV32I assembly and C language and use bare-metal
cross-compilation to generate the binary (.hex) files to run in emulsiV.
Breakdown
This assignment consists of three parts:
Part 1: Implement a function written in assembly code compliant with the RV32I
standard to fill the entire display with a solid color. This function takes the
desired color as input and returns no value.
Part 2: Implement a function written in assembly code compliant with the RV32I
standard that sets the corresponding value in memory to a color given the pixel's
coordinates. This function takes the desired pixel color and the pixel coordinates as
inputs and returns no value.
Part 3: Implement the C code to draw a rectangle given the coordinates of the left
top and right bottom corner. This code should call the functions implemented in parts
1 and 2 to draw on the bitmap display.
You are provided with skeleton files for parts 1 and 2 to help you start with the
lab. You may not change the name of the functions or arguments at all. The label
“main” should not be used anywhere in the files lab4_part1.s and lab4_part2.s.
Lab 4 Page 1 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
We are also providing test files for parts 1 and 2. These files consist of simple
main functions that will allow you to compile your functions and generate the (.hex)
files for your submission.
Resources
1. Follow the instructions to install the RISC-V GNU toolchain on your computer.
This tool is essential for this lab. Follow the google drive
riscv-video-updated.mp4 video for instructions on how to install the RISC-V
with Windows/WSL or OSX/homebrew.
2. emulsiV: This is the simulator we will be using for this lab. This link
provides the GitHub link to the source code. You can follow the instructions
to install and run the server or simply use the online interface.
3. This document gives an overview of the RISC-V assembly language.
4. Compiler Explorer is an interactive online tool that lets you type C code and
see the results of its RISC-V compilation.
5. OnlineGDB Online compiler and debugger for C/C++
6. Read some background on Raster graphics
Background
emulsiV bitmap
The graphic display area of emulsiV maps each pixel to a RAM byte using 8-bit color
quantization. It assigns 3 bits to red, 3 bits to green, and 2 bits to blue, as the
human eye is less sensitive to blue light. Color is therefore encoded as follows:
The values specify the intensity of red, green, and blue. Here are some color value
examples: white=0xff, black=0x00, red=0xe0, green=0x1c and yellow=0xfc.
The image has (32 x 32 =) 1024 pixels, each being 1 byte. Therefore it will be stored
in a memory segment spanning 1024 bytes, starting at memory address 0x00000C00 and
taking up the remainder of the memory in our 32-bit address space.
Lab 4 Page 2 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
The emulsiV bitmap RAM follows a raster-scan ordering. The picture above shows an
example of how the coordinates of the pixels relate to the array in memory (the
picture is using a smaller 4x4 display for clarity). Now, for example, if you wanted
to access the address of the pixel at row 2, column 3 (2,3) you would take the base
address of the bitmap and offset that by +11 which is (2 * row_size) + 3 to locate
the correct pixel. In general:
Pixel_address = base_address + ((row*row_size) + column)
Specification: Part 1
Description
The following is the description of the function that you will implement in the
lab1_part1.s file. This function will be called by the grading script, so make sure
not to alter its signature.
fill_bitmap: Given a color, this function will fill the bitmap display with that
color.
Inputs:
a0 = 8 bit color value
Outputs:
No register outputs
Compilation
To generate the .hex file that runs on emulsiV you will have to compile your code.
Assuming that you have followed the instructions and installed the pre-built RISC-V
bare-metal toolchain on your computer, the following sequence of commands will
compile your code for part 1:
1. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o startup.o startup.s
2. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part1.o
lab4_part1.s
3. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part1_test.o
lab4_part1_test.s
4. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -nostdlib -T emulsiv.ld -o
lab4_part1_test.elf startup.o lab4_part1.o lab4_part1_test.o
Lab 4 Page 3 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
5. riscv64-unknown-elf-objcopy -O ihex lab4_part1_test.elf lab4_part1_test.hex
The files startup.s and emulsiv.ld must be in the same directory as your lab files
but should not be pushed to your repository.
Submission
The only files that you are pushing to your gitlab repository are lab4_part1.s and
lab4_part1_test.hex. The .hex file that you generate has to run on emulsiV and fill
the bitmap with a specific color that you will calculate using your Student
Identification Number (Your Student Identification Number is a 7-digit number that
can be found on your Student ID Card embedded in the library bar code number on the
right side of each card).
To calculate the color that you should use to paint the background for your
submission, you will add the seven digits of your Student Identification Number
(StudentID number) and multiply the result by 4. The calculated value will correspond
to the color of the pixels in decimal, for example:
Student id number: 1633177
● Step 1.- Add the seven digits: 1+6+3+3+1+7+7 = 28
● Step 2.- Multiply the result by 4: 28*4 = 112 = 0x70
Therefore you will fill the bitmap with the color 0x70. Note that you do not need to
implement the code to calculate the color value. You can calculate it by hand and
just change the value in the lab4_part1_test.s file.
Output
The image below shows the emulsiV bitmap before and after the execution of the
program (assuming student id number = 1633177):
Before running After running
Note that the color you obtain depends on your student id number.
Lab 4 Page 4 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
Specification: Part 2
Description
The following is the description of the function that you will implement in the
lab2_part1.s file. This function will be called by the grading script, so make sure
not to alter its signature.
draw_pixel: Given a coordinates y (row) in a1, and x (col) in a2 sets the
corresponding value in memory to the color given by a0. This works by storing the RGB
value in the appropriate location of the row-major bitmap array starting at address
0x00000C00.
Inputs:
a0 = 8 bit color value
a1 = y coordinate of pixel
a2 = x coordinate of pixel
Outputs:
No register outputs
You should do some error checking to ensure the pixel is within range. If the x or y
values “overflow” and are more than 8-bits. We will not be grading this error
checking, but it could save you time debugging!
Compilation
To generate the .hex file that runs on emulsiV you will have to compile your code.
Assuming that you have followed the instructions and installed the pre-built RISC-V
bare-metal toolchain on your computer, the following sequence of commands will
compile your code for part 2:
1. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o startup.o startup.s
2. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part2.o
lab4_part2.s
3. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part2_test.o
lab4_part2_test.s
4. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -nostdlib -T emulsiv.ld -o
lab4_part2_test.elf startup.o lab4_part2.o lab4_part2_test.o
5. riscv64-unknown-elf-objcopy -O ihex lab4_part2_test.elf lab4_part2_test.hex
The files startup.s and emulsiv.ld must be on the same directory as your lab files
but should not be pushed to your repository.
Submission
The only files that you are pushing to your gitlab repository are lab4_part2.s and
lab4_part2_test.hex. The .hex file that you generate has to run on emulsiV and paint
the center pixel of the bitmap (coordinates x=15, y=15) with a specific color that
you will calculate using your Student Identification Number (Your Student
Identification Number is a 7-digit number that can be found on your Student ID Card
embedded in the library bar code number on the right side).
To calculate the color that you should use to paint the center pixel of the bitmap
(coordinates x=15, y=15) for your submission you will add the seven digits of your
Lab 4 Page 5 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
Student Identification Number, multiply the result by 4 and finally apply a bitwise
not to the result (considering that the color value for the pixel uses only one
byte). The calculated value will correspond to the color of the pixels in decimal,
for example:
Student id number: 1633177
● Step 1.- Add the seven digits: 1+6+3+3+1+7+7 = 28
● Step 2.- Multiply the result by 4: 28*4 = 112 = 0x70
● Step 3.- Apply a bitwise not operation to the previous result (remember that
the pixel value uses only 1byte i.e. 8-bits)
0x70 = 0b01110000, inverting the bits we get 0b10001111 = 8f
Therefore you will paint the center pixel of the bitmap (coordinates x=15, y=15) with
the color 0x8f. Note that you do not need to implement the code to calculate the
color value. You can calculate it by hand and just change the value in the
lab4_part2_test.s file.
Output
The image below shows the emulsiV bitmap before and after the execution of the
program (assuming student id number = 1633177):
Before running After running
Note that the color you obtain depends on your student id number.
Lab 4 Page 6 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
Specification: Part 3
Description
The following is the description of the function that you will implement in the
lab1_part3.c file. We are not providing skeleton files for this part.
rectangle(unsigned char background_color, unsigned char line_color, int left, int
top, int right, int bottom):
This function will draw a rectangle to the bitmap with the desired background and
line color. Coordinates of left top and right bottom corner are required to draw the
rectangle and the color. left specifies the X-coordinate of top left corner, top
specifies the Y-coordinate of top left corner, right specifies the X-coordinate of
right bottom corner, bottom specifies the Y-coordinate of right bottom corner.
This C code program will call the functions fill_bitmap and draw_pixel that you
implemented on the previous parts in assembly. Consider that the pixels draw “on top
of” each other so the order of the calls matters.
Compilation
To generate the .hex file that runs on emulsiV you will have to compile your code.
Assuming that you have followed the instructions and installed the pre-built RISC-V
bare-metal toolchain on your computer, the following sequence of commands will
compile your code for part 3:
1. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o startup.o startup.s
2. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part1.o
lab4_part1.s
3. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o lab4_part2.o
lab4_part2.s
4. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -ffreestanding -c -o
lab4_part3.o lab4_part3.c
5. riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -nostdlib -T emulsiv.ld -o
lab4_part3.elf startup.o lab4_part1.o lab4_part2.o lab4_part3.o
6. riscv64-unknown-elf-objcopy -O ihex lab4_part3.elf lab4_part3.hex
The files startup.s and emulsiv.ld must be on the same directory as your lab files
but should not be pushed to your repository.
Submission
The only files that you are pushing to your gitlab repository are lab4_part3.c and
lab4_part3.hex. The .hex file that you generate has to run on emulsiV and draw a
rectangle with parameters that you will calculate using your Student Identification
Number (Your Student Identification Number is a 7-digit number that can be found on
your Student ID Card embedded in the library bar code number on the right side).
The parameters for your program output will be as follows:
● The background color will be the same of part 1 (see the submission section
for part 1)
Lab 4 Page 7 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
● The line color will be the same of part 2 (see the submission section for part
2)
● The coordinates of left top and right bottom corners will be calculated based
on your Student Identification Number as follows:
Left top corner: (first digit, second digit)
Right bottom corner: (31 - seventh digit, 31 - sixth digit)
for example:
Student id number: 1633177
Left top corner: (1, 6)
Right bottom corner: (31 - 7, 31 - 7) = (24, 24)
Output
The image below shows the emulsiV bitmap before and after the execution of the
program (assuming student id number = 1633177):
Before running After running
Note that the color and position you obtain depends on your student id number.
Lab 4 Page 8 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz
Specification: README.txt
This file must be a plain text (.txt) file. It should contain your first and last
name (as it appears on Canvas) and your Student Identification Number. In the
following format:
Name
Lastname
Student id
Notes
● It is important that you do not hard-code the values for any of the bitmap
addresses in your program -- except for the origin of the memory-mapped IO
segment at 0x00000C00. We will be testing your functions with different values
than those provided in test files, so do not hard code the output!
● Do not push extra files to the repository.
Grading Rubric (100 points total)
30 pt Part-1 completed
15 pt lab4_part1.s compiles successfully
15 pt lab4_part1_test.hex runs on emulsiV
30 pt Part-2 completed
15 pt lab4_part2.s compiles successfully
15 pt lab4_part2_test.hex runs on emulsiV
35 pt Part-3 completed
10 pt lab4_part3.c compiles successfully
10 pt lab4_part3.hex runs on emulsiV
15 pt Code produces the correct output
5 pt README.txt in the lab4 directory and ONLY the correct content present (no extra
files like objects or points may be lost).
Lab 4 Page 9 of 9 Winter 2022
© 2022, Computer Engineering Department, University of California - Santa Cruz

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!