首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导ECS 50留学生编程、讲解Programming、C/C++程序辅导 讲解Python程序|调试Matlab程序
项目预算:
开发周期:
发布时间:
要求地区:
ECS 50: Programming Assignment #6
Spring 2021
Contents
1 Changelog 1
2 General Submission Details 1
3 Grading Breakdown 1
4 Submitting on Gradescope 2
5 RV32EM 2
6 RISC-V Simulator 2
6.1 Accessing My CSIF Installation of the Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
6.2 Installing the Simulator Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
7 Simulator Example Program 3
8 Relevant I/O Concepts in the Example Code 3
9 Your Assignment 4
9.1 Other Notes Regarding Use of the Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1 Changelog
You should always refer to the latest version of this document.
• v.1: Initial version.
• v.2: Removed mention of Windows Subsystem for Linux. To Windows users, I’d recommend MobaXTerm.
2 General Submission Details
Partnering on this assignment is prohibited. If you have not already, you should read the section on
academic misconduct in the syllabus.
This assignment is due the night of Tuesday, 06/08. Gradescope will say 12:30 AM on Wednesday, 06/09, due to the
“grace period” (as described in the syllabus). Be careful about relying on the grace period for extra time; this could be risky.
3 Grading Breakdown
As stated in the updated syllabus, this assignment is worth 8% of your final grade.
∗This content is protected and may not be shared, uploaded, or distributed.
1
4 Submitting on Gradescope
Files to submit:
• main.c
You may be penalized for submitting unnecessary files.
There is no autograder for this assignment. You must simply submit your code to Gradescope, and – after the
deadline – I will grade the submissions. (Make sure your file’s name is correct!) I will do this on the CSIF, so the CSIF is
still the reference environment.
Your output must match mine exactly.
5 RV32EM
Since you will write C code in this assignment, the exact details on RV32EM are not too important, but I include them
here for your own edification.
While introducing RISC-V during lecture, I very briefly talked about different extensions to RISC-V. Such extensions
include, for instance, the M extension for multiplication/division instructions and the FD extension for single/double floatingpoint
instructions.
In this assignment, you will write C code that can be run on a RV32EM processor. The “32” means that the processor
is a 32-bit processor instead of a 64-bit processor, so addresses are 32 bits. The “M” refers to the M extension mentioned
earlier. The “E” refers to the E extension, which helps to support low-end cores / embedded systems. Low-end cores are
cheap; consequently, an RV32EM processor only has 16 registers, x0 through x15. (Where applicable, registers still maintain
their special meaning. For instance, x0 is still hard-wired to always be zero, and x2 is the stack pointer.)
6 RISC-V Simulator
In this assignment, you will use Professor Chris Nitta’s RISC-V simulator that can be found here. You should skim the
readme to get a glance at what you’ll be dealing with.
There are two ways that you can use the simulator, and I talk about both ways below. The first way should be much
easier than the second way.
• Accessing my CSIF installation of the simulator.
• Installing the simulator yourself.
6.1 Accessing My CSIF Installation of the Simulator
Note on ssh Command: Since the simulator is a graphical application, you will need to enable something called X11
forwarding. I have personally confirmed that on a Linux machine and on a Windows machine (with a Linux command line
like MobaXTerm), this can be done by using the -X flag1
in the ssh command that you use for logging on to the CSIF. I
imagine it would be similar on a Mac. I don’t know how to enable X11 forwarding on Putty on Windows; to Windows users,
I would recommend MobaXTerm.
Running the Simulator: I have already installed the simulator in my CSIF files. You can run the simulator with the
following command2
.
1 / home / aaron123 / riscv - console / runsim . sh
This will open the simulator. You can run the simulator as a background task (with &) if you want to continue using the
same terminal that you used to open the simulator.
At this point, you can follow along with Professor Nitta’s example here. Note the following:
• Ignore launching the simulator with /code/runsim.sh.
• Presumably, the example files will not be in the same place on your end that they are in his walkthrough. You can find
the example files here or on Canvas in the riscv-example folder. (I included a zipped version too, in case it’s convenient.)
1Someone once mentioned to me the -Y flag as an alternative; I’ve never tried this flag.
2Note that if you copy-and-paste the below line from this PDF, there may be unexpected spaces or strange characters in the result, as this
tends to occur when one copies-and-pastes from a PDF.
2
As stated in Professor Nitta’s documentation for the simulator, you can use the -d flag to enable debug mode; just pass
it as a command-line argument to the script.
Regarding compilation (of your code): As mentioned below, you will use a provided makefile in order to compile
your code. You will need to add the path to the RV32EM C compiler (that I’ve installed) to your PATH environment variable.
You can do that with a line like the below3
.
1 export PATH = $PATH :/ home / aaron123 / opt / riscv32 / bin
I believe that you would have to type the above line on the command line each type you log in to the CSIF. If you want
to avoid having to do this, then I would recommend adding the above line to a .bash_aliases file (in your home directory on
the CSIF) and putting the following line in the .bashrc file (that should already be in your home directory on the CSIF):
source ~/.bash_aliases. Each time that you open a new session on the CSIF, the .bashrc file will be checked, which in turn
means that the .bash_aliases file will be checked.
6.2 Installing the Simulator Yourself
I would not recommend this way. I would recommend using the simulator on the CSIF in order to save yourself time.
Follow the directions that Professor Nitta provides here. Expect this process to take a few hours.
7 Simulator Example Program
As mentioned above, the example code can be found here, and it is also provided on Canvas. These files are described
below. You need all of these files for what you are going to be doing in this assignment, because – as mentioned
below – you will be modifying main.c. Note, however, that you do not need to understand much of what is in
the files, except for main.c and (maybe4
) a bit of what’s in src/startup.c.
• Makefile: for compilation.
• riscv32-console.ld: linker file that is also for compilation.
• src/crt0.s: The code in this file helps set up an interrupt handler (and other things). This code contains the _start
label, which is the true starting point of the program. (Notice that main() is called at the bottom.)
• src/interrupt.s: This file contains the interrupt handler, which preserves registers, calls another function called c_interrupt_handler
() to do most of the work, and returns with mret. (This mret instruction is similar to iret in x86 in that it is an instruction
specifically used for returning from an interrupt handler.)
• src/main.c: main() is defined here. This is where much of the action occurs; see below for more details.
• src/startup.c: This file has code for helping with certain things related to I/O and interrupts, including the definition
of the c_interrupt_handler() function that is called by the interrupt handler.
You should make sure that you can run the simulator and that you use the example on the simulator as Professor Nitta
shows in the documentation. The rest of what I say here won’t make much sense if you have not even tried the example yet
or at least seen what the example is supposed to do.
8 Relevant I/O Concepts in the Example Code
As you know, there are two categories of approaches for interacting with I/O ports:
1. The I/O address space approach, which is what x86 does.
2. The memory-mapped I/O approach, which is what RISC-V does.
In the memory-mapped I/O approach, certain memory addresses correspond to I/O ports. You can find what those
addresses are (for Professor Nitta’s RV32EM simulator) if you look at the documentation here. As an example, according
to here, the text data of the video controller (controlling what text shows up on the screen) starts at address 500F E80016.
This is why you see – in the example code’s main.c – that VIDEO_MEMORY has a starting address of 500F E80016. This address is
mapped to the top-left corner of the screen, meaning that if we do VIDEO_MEMORY[0] = ’a’, then a lowercase ‘a’ will appear at
the top-left of the screen. The following address, 500F E80116, is mapped to the spot immediately to the right of the top-left
corner, and so on for 500F E80216. You should be able to understand how the example code gets “Hello, World!” to show
up on the screen.
As stated here, the screen is 64 x 36 characters.
3See my earlier footnote about what can go wrong if you copy-and-paste from a PDF.
4
i.e. insofar as it is relevant to the final exam concepts
3
The example code uses an infinite loop, since there’s no reason for the program to end. Within that infinite loop, some
stuff is done with the global and last_global variables in order to prevent the example from being overly responsive to inputs.
Once we check the value of controller_status, things become interesting again. Here, we are checking if any button has
been pressed. This is done by checking the multi-button controller status register5
, which – as stated here can be accessed
by reading the value that is at address 4000001816. The code in startup.c set things up so that reading the controller_status
variable will get what’s at address 4000001816. When you read from the multi-button controller status register, you get a
4-byte value in which certain bits have special meaning. You can read more here. As examples of how to interpret the bits,
you can check if the left direction button is pressed by checking if bit #0 is set, and you can check if the up direction button
is pressed by checking if bit #1 is set. You should be able to understand how the buttons are checked in main.c.
For More Information: There are many other concepts related to RISC-V’s handling of I/O and interrupts that we will
not go into here. If you want more information, you may find Chapter 10 of The RISC-V Reader: An Open Architecture
Atlas by David Patterson and Andrew Waterman to be useful.
9 Your Assignment
For this assignment, you must make the following modifications to main.c:
• No longer print “Hello, World!”.
• The top row and bottom row of the screen should be equal signs.
• The left and right columns of the screen should be vertical bars.
• The user (the “X”) should no longer be allowed to move to the top row, bottom row, left column, or right column.
• The user’s icon (the “X”) should start at the top-left most point that it is allowed to be at.
• Any other spot on the screen should contain a “.” at the start.
• When the user moves, the user should consume/remove any “.” that are touched.
• Instead of moving with the WASD keys/buttons, the user should now move with the UIJK keys/buttons. Specifically:
– U button: leftward movement.
– J button: downward movement.
– K button: rightward movement.
– I button: upward movement.
Below is an example of what compilation looks like. You do not need to do the export line each time, just once per CSIF
session. (If you don’t do it, then you should get a compiler error message complaining that riscv32-unknown-elf-gcc does not
exist.)
1 $ ls
2 Makefile riscv32 - console . ld src
3 $ ls src
4 crt0 .s interrupt . s main .c startup .c
5 $ export PATH = $PATH :/ home / aaron123 / opt / riscv32 / bin
6 $ make
7 mkdir -p ./ obj
8 mkdir -p ./ bin
9 riscv32 - unknown - elf - gcc -O0 -g - ggdb - ffreestanding - nostartfiles - nostdlib - nodefaultlibs - DDEBUG -I ./
include -c src / main .c -o obj / main . o
10 riscv32 - unknown - elf - gcc -O0 -g - ggdb - ffreestanding - nostartfiles - nostdlib - nodefaultlibs - DDEBUG -I ./
include -c src / crt0 .s -o obj / crt0 . o
11 riscv32 - unknown - elf - gcc -O0 -g - ggdb - ffreestanding - nostartfiles - nostdlib - nodefaultlibs - DDEBUG -I ./
include -c src / interrupt .s -o obj / interrupt .o
12 riscv32 - unknown - elf - gcc -O0 -g - ggdb - ffreestanding - nostartfiles - nostdlib - nodefaultlibs - DDEBUG -I ./
include -c src / startup .c -o obj / startup .o
13 riscv32 - unknown - elf - gcc ./ obj / main .o ./ obj / crt0 .o ./ obj / interrupt . o ./ obj / startup .o -o ./ bin / riscv - console
- example -O0 -g - ggdb - ffreestanding - nostartfiles - nostdlib - nodefaultlibs - DDEBUG -Wl , --gc -
sections -Wl ,-T , riscv32 - console . ld
14 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
15 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
16 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
17 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
18 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
5Do not confuse this kind of “register” with the kinds of general-purpose registers like a0 and s1 that you can (for the most part) freely access
and use in RISC-V assembly code. “Register” is a bit of an overloaded term.
4
19 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 - unknown - elf /10.2.0/../../../../ riscv32 - unknown - elf / bin / ld :
cannot find default versions of the ISA extension ‘i ’
20 riscv32 - unknown - elf - strip ./ bin / riscv - console - example -o ./ bin / riscv - console - example . strip
21 $ ls
22 bin Makefile obj riscv32 - console . ld src
23 $ ls bin
24 riscv - console - example riscv - console - example . strip
Below, I show some screenshots of my running my own solution in the simulator.
• This image shows what the screen should look like at the start.
• If I press the K button (or – as I prefer – “k” on the keyboard), then the “X” moves right, consuming any “.” marks
that are on the way. At this point, pressing “i” (the I button) does nothing, since I cannot move any further up.
• Pressing “j” (the J button) causes the “X” to move down.
5
• In the below image, I am as far down as I can go; pressing “j” will do nothing.
• In the below image, I am as far to the right as I can go; pressing “k” will do nothing.
6
You should not have to modify the while loop or either of the outermost if statements in main(). As stated previously,
you are only submitting main.c, so you should not bother modifying any other file in the setup.
9.1 Other Notes Regarding Use of the Simulator
When I SSH onto the CSIF from a Ubuntu computer and use the file explorer that pops up when I try to choose firmware,
I cannot seem to double-click folders to open them and instead have to click Open at the top right. This is not an issue when
I SSH onto the CSIF from a Windows computer or when I run the simulator directly on my Ubuntu computer. I only point
this issue out because I think that it could trick students into thinking that their connection to the CSIF suddenly failed or
that they’re having internet issues.
In general, I prefer to use the keyboard for pressing the buttons, e.g. pressing “u” instead of clicking the “u” button. I
find that sometimes, when I click the buttons, they get stuck in a pushed position, as if they’re always clicked.
I’m not quite sure how helpful the debug mode of the simulator will be in this assignment, since you are not writing
assembly code. However, I am acquainted with the debug mode, so if you have questions about it, feel free to ask me.
7
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
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
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!