Skip to content

Lab 01 - Hello World and Args in the RISC-V Development Environment

Deliverables due Wed Aug 27th by 4:45pm in your Lab01 GitHub repo

  • Ability to demonstrate ssh access to the BeagleV machines from your laptop without a password
  • Ability to edit files on a BeagleV machine using a terminal-based editor like micro, vim, or emacs (not nano)
  • Ability to compile and run C programs on the BeagleV machines
  • Abilily to run the Autograder program (grade) on the BeagleV machines
  • Ability to use git and access GitHub repos from the BeagleV machines

There will be two parts that will be graded for Lab01 - Lab01 Tests - This will be autograded - Lab01 Dev Setup - You will demonstrate that you can do the activities above to me or a TA

Tests: https://github.com/USF-CS315-F25/tests

Autograder: https://github.com/phpeterson-usf/autograder

Overview

This lab will get you up to speed in the development environment. You will learn how to do the following:

  • Use git and access GitHub on the BeagleV machines
  • Use a terminal-based editor to write C code
    • You will write two C programs
  • Create a Makefile
  • Install and run the autograder

Program Requirements

You need to write two programs for Lab01: hello and argslens

Hello World (hello)

You will write a version of Hello World, called hello, that takes a single argument, <str>, and prints "Hello, <str>". For example:

$ ./hello World
Hello, World!
$ ./hello CS315
Hello, CS315!

Argument Lengths (argslens)

In class, we developed a simple program that shows the command line arguments passed to a C program using argc and argv. You can find this program in the inclass GitHub repo:

https://github.com/USF-CS315-F25/inclass

Your goal is to create a new program argslens.c based on args.c that will also print the length in characters after each argument. The args.c output looks like this:

$ ./args foo cs315 computer achitecture
argv[0] = ./args
argv[1] = foo
argv[2] = cs315
argv[3] = computer
argv[4] = achitecture

The argslens.c output should look like this:

$ ./argslens foo cs315 computer architecture
argv[0] = ./argslens (10)
argv[1] = foo (3)
argv[2] = cs315 (5)
argv[3] = computer (8)
argv[4] = architecture (12)

In order to add the length in characters to each argument output line you will need to use the standard C library strlen() function. In order to use this function you will need to include the string.h header file to the argslens.c program.

Working with make and Makefiles

What make and Makefiles do (quick intro)

  • Goal: Rebuild only what changed. make tracks targets (files to build), their prerequisites (dependencies), and recipes (shell commands).
  • How it works: If any prerequisite is newer than a target (or the target is missing), make runs the recipe to remake that target.
  • Makefile: A declarative file that defines targets, dependencies, variables, and pattern rules so make knows how to build your project.
  • Benefits: Fast incremental builds, reproducible commands, easy customization via variables, and convenient utility targets like clean.

A Makefile is usually called Makefile and will exist in the same directory as your source code.

The Lab01 Makefile

.PHONY: all clean
CC      := gcc
CFLAGS  := -g -O2 -Wall -Wextra
LDFLAGS := -g

PROGS := hello argslens
HELLO_OBJS := hello.o
ARGSLENS_OBJS := argslens.o
OBJS := ${HELLO_OBJS} ${ARGSLENS_OBJS}

%.o: %.c
        ${CC} -c ${CFLAGS} -o $@ $<

all: ${PROGS}

hello: ${HELLO_OBJS}
        ${CC} ${LDFLAGS} -o $@ $^

argslens: ${ARGSLENS_OBJS}
        ${CC} ${LDFLAGS} -o $@ $^

clean:
        rm -rf ${PROGS} ${OBJS}

The Lab01 Makefile Explained

.PHONY: all clean
- Declares all and clean as phony (not real files). This prevents filename collisions and forces these targets to run when invoked.

CC      := gcc
CFLAGS  := -g -O2 -Wall -Wextra
LDFLAGS := -g
- Sets build variables with simple (immediate) assignment := (values are expanded now, not re-expanded later). - CC: the C compiler. - CFLAGS: flags for compiling (-g debug info, -O2 optimize, warnings). - LDFLAGS: flags for linking (-g includes debug symbols in the linked binary).

PROGS := hello argslens
HELLO_OBJS := hello.o
ARGSLENS_OBJS := argslens.o
OBJS := ${HELLO_OBJS} ${ARGSLENS_OBJS}
- Lists the two executables to build and the object files each needs. - OBJS collects all object files (used below in clean). - Note: In GNU make, ${VAR} and $(VAR) are equivalent; you’re using braces consistently.

%.o: %.c
        ${CC} -c ${CFLAGS} -o $@ $<
- A pattern rule: how to compile any .c file into the matching .o. - Automatic variables: - $@ → the target (e.g., hello.o) - $< → the first prerequisite (here, the matched .c, e.g., hello.c) - The recipe (must start with a tab) compiles without linking.

all: ${PROGS}
- Default aggregate target: building all builds both hello and argslens. - Running just make (no target) builds the first target in the file; because .PHONY appears first, most makes still choose all as the default goal. If you ever find ambiguity, put all as the very first non-dot target.

hello: ${HELLO_OBJS}
        ${CC} ${LDFLAGS} -o $@ $^
- Links hello from its object(s). - $^ → all prerequisites (here, hello.o).

argslens: ${ARGSLENS_OBJS}
        ${CC} ${LDFLAGS} -o $@ $^
- Same idea for argslens (links argslens.o into the executable).

clean:
        rm -rf ${PROGS} ${OBJS}
- Utility target to delete built files.


How make will build this

  1. make (or make all)
    → needs hello and argslens.
  2. hello needs hello.o. If hello.o is missing/outdated, the pattern rule compiles hello.c → hello.o. Then the hello rule links it.
  3. Same for argslens via argslens.c → argslens.o → link.
  4. make clean removes the binaries and objects for a fresh rebuild.

Tips & common variations

  • Tabs matter: Each recipe line must start with a tab (not spaces).
  • Add a new program:
  • Create foo.c.
  • Add foo to PROGS and a FOO_OBJS := foo.o.
  • Add a link rule like foo: ${FOO_OBJS} ${CC} ${LDFLAGS} -o $@ $^.
    The pattern rule already handles compiling foo.c to foo.o.
  • Rebuild from scratch: make clean && make
  • Dry run: make -n shows what would run without executing.

That’s it! This Makefile is clean and extensible: one generic compile rule, explicit link rules per program, and tidy variables you can override when needed.

Autograder

To run the Autograder tests for Lab01, make sure you have cloned the tests repo for the class and you have configured the Autograder to point to the location of you tests repo in your home directory. Once you have the autograder installed and configured, you should be able to run the Lab01 tests like this:

benson@beagle2:lab01-solution$ grade test
. 01(25/25) 02(25/25) 03(25/25) 04(25/25) 100/100

Autograder Installation on the BeagleV machines

To use the Autograder on the BeagleV machine you just need to clone the Autograder repo into your home directory. Here are some simple steps:

% ssh beagle
% mkdir cs315
% cd cs315
% git clone https://github.com/phpeterson-usf/autograder

Then you need to edit your ~/.bash_profile to add the autograder location to you PATH:

export PATH=~/cs315/autograder:$PATH

You can log out and log back in to update the PATH.

Code Submission

You will submit your code in your Lab01 GitHub repo. You will be provided a link to create your repo. Please only submit your Makefile, hello.c, argslens.c, and optionally a README.md file. You should not include any binary files such as executables or object files. In general, you should not include any files that will be generated as a result of building your program with make.

Rubric

  • 100% Lab01 autograder tests.
  • 100% Lab01 dev setup.