A0: Infrastructure
Instructions:
Remember, all assignments in CS 3410 are individual.
You must submit work that is 100% your own.
Remember to ask for help from the CS 3410 staff in office hours or on Ed!
If you discuss the assignment with anyone else, be careful not to share your actual work, and include an acknowledgment of the discussion in a collaboration.txt
file along with your submission.
The assignment is due via Gradescope at 11:59pm on the due date indicated on the schedule.
This assignment is due on Monday, 1/27 at 11:59pm. You may submit the assignment up to three days late (i.e., until 1/30 at 11:59pm) without using slip days.
Submission Requirements
You will submit your completed solution to this assignment to Gradescope. You must submit:
lab1.c
, which will be modified with your solution forprint_digit
andprint_string
Restrictions
- You may not include any libraries beyond what is already included in
stdio.h
- Your solution should use constant space (you should not use arrays, either dynamically or statically)
Provided Files
There is no release code for this assignment. You create your own file, as described below.
Implementation
View the lab slides here.
Before coming to lab, go through the course setup materials for Git and the RISC-V Infrastructure. The lab tasks will assume you have at least set up your Cornell GitHub credentials and have your favorite text editor, such as Visual Studio Code, ready to go.
Step 1: Compiling and running C programs
Course Docker Container
Follow these instructions to set up Docker and obtain CS 3410’s Docker container. To summarize, you will need to:
- Install Docker itself.
- Download the image with
docker pull ghcr.io/sampsyo/cs3410-infra
. - Consider setting up an
rv
alias to make the container easy to use.
If you don’t already have a favorite text editor, now would also be a good time to install VSCode.
C Programming
Next, follow these instructions for writing, compiling, and running your first C program.
When your program runs, show the result to a TA. Congratulations! You’re now a C programmer.
Git
Now, we’ll get some experience with Git! If you haven’t already, be sure to follow our guide to setting up your credentials on GitHub so you have an SSH key in place.
Go to the to the Cornell GitHub website and create a repository called “lab1”. This repository can be public, but for assignments all of your repositories must be private.
Now, clone your repository from within the cs3410
directory you made earlier:
$ git clone git@github.coecis.cornell.edu:abc123/lab1.git
replacing abc123
with your actual NetID. If this doesn’t work, ask a TA for
assistance. There is probably something wrong with your GitHub configuration.
Before changing directories into the
repo, you should move your hi.c
file that you created during the Docker setup step into the lab1
folder and clean up the executables
we made earlier:
$ mv hi.c lab1
$ rm a.out
$ cd lab1
$ ls
If you haven’t created one yet, you can run:
$ cd lab1
$ printf '#include <stdio.h>\nint main() { printf("hi!\\n"); }\n' > hi.c
You should see the file hi.c
in your repository. Enter:
$ git status
The following should appear (or something like it):
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
hi.c
Now, you should add the file hi.c
to stage it, make a commit, and then
push to the remote repository:
$ git add hi.c
$ git commit -m "Initial commit"
$ git push
This is commonly the GitHub workflow for a single person working on an assignment. You’ll make some changes, commit them, and push them, over and over until you finish the assignment.
To learn more about Git, consider following our complete git tutorial!
Step 2: print_digit
and print_string
For this next task, you are going to write two helper functions to help you in Assignment 1:
print_digit(int digit)
: Given an integerdigit
between 0 and 15, printdigit
as a hexadecimal digit using lowercase letters to the terminal (without usingprintf
)print_string(char* s)
: Given a string, print it to the terminal (without usingprintf
)
First, cd
into your lab1
repository. Then, make a file called lab1.c
, and
copy/paste the following code:
#include <stdio.h>
// LAB TASK: Implement print_digit
void print_digit(int digit) {
}
// LAB TASK: Implement print_string
void print_string(char* s) {
}
int main(int argc, char* argv[]) {
printf("print_digit test: \n"); // Not to use this in A1
for (int i = 0; i <= 16; ++i) {
print_digit(i);
fputc(' ', stdout);
}
printf("\nprint_string test: \n"); // Not to use this in A1
char* str = "Hello, 3410\n";
print_string(str);
return 0;
}
fputc
(defined in stdio.h
) writes a single character to a given output
stream (e.g., stdout
). See more here.
For print_digit
, you’ll want to use an ASCII table.
Save the file and exit the editor. Now is a good time to commit and push your changes to your repository. Once you’ve pushed, try to implement the functions print_digit
and print_string
. The TAs are available for help should you need it.
Once you’ve implemented the functions, you can run the program:
$ rv gcc -Wall -Wextra -Wpedantic -Wshadow -std=c17 -o test_lab1 lab1.c
$ rv qemu test_lab1
Like many commands on this page, this assumes you have the rv
aliases setup as described in our RISC-V Infrastructure setup guide.
Remember, if you change lab1.c
between runs, you need to recompile the program.
That’s all for Assignment 0!
Submission
Submit lab1.c
to Gradescope.
Upon submission, we will provide a smoke test to ensure your code compiles and passes the public test cases.