Lab 1

Computer Architecture I (CS110) Lab Document
Reference: CS110 Course Page

Computer Architecture I @ ShanghaiTech University

  • Goals

    • Set up your Linux.
    • Set up Gradescope.
    • Learn some simple C programming.
    • Learn basic Linux commands.

    How Checkoffs Work

    You'll notice that at the end of (almost) every exercise, there is a section labelled "Check-off." The items in this section are what you must successfully demonstrate to your TA in order to receive credit for completing the lab. Once you finish ALL of the exercises , you should put your names AND ShanghaiTech email address on the checkoff list on the board, and a TA will come and check you off. Labs are graded out of x points, which will evaluate to 100%. A lab is considered on-time if it is turned in within a week of the lab session in which it is initially assigned to you. For example, the lab assigned to you in this week's lab is this document, lab 1. Thus, the latest you may get lab 1 checked off is the beginning of your lab next week.

    Exercises

    Exercise 1: Have a 64bit Linux installed

    As a SISTOR, you should have a REAL Linux (WSL is NOT allowed) installed. In CS110 and CS110P, we recommend installing Ubuntu 24.04 LTS (64bit) on your computer. If you are using an X86 computer (Intel or AMD), you should install it as dual boot. If you are using an ARM-based computer (e.g. Apple Silicon), contact us immediately. Note that some part of the lab may not work on macOS!

    Using a virtual machine is OK, but not recommended. We prefer dual boot.

    Exercise 2: Gradescope

    Show the TA your gradescope account and that you finished HW1.

    Exercise 3: Linux commands

    The following commands/programs are very useful in Linux.

    • cd
    • ls
    • pwd
    • mkdir
    • touch
    • cat
    • cp
    • mv
    • rm

    Explain the usage of each command to the TA.

    Exercise 4: Bash shortcuts (↑/↓ and Tab)

    Bash provides a few very useful keyboard shortcuts that will make you much faster in the terminal.

    • Command history (↑ / ↓)
      • Press to cycle through previously used commands.
      • Press to move forward in the history.
      • Use this to quickly rerun a command or edit it instead of typing it again.
    • Autocomplete (Tab)
      • Type the first few characters of a command, file name, or directory name, then press Tab to autocomplete it.
      • If there are multiple matches, press Tab twice to show options, then type a few more characters and press Tab again.

    Check-off: Demonstrate to the TA that you can use ↑/↓ to recall a previous command, and use Tab to autocomplete a file or directory name.

    Optional: Try installing fish (Friendly Interactive SHell)

    If you want to try a different interactive shell, you can install fish (Friendly Interactive SHell). It is known for user-friendly defaults, strong autosuggestions, and syntax highlighting out of the box, which can make interactive terminal work feel smoother than bash.

    1. Update package lists:
      • sudo apt update
    2. Install fish:
      • sudo apt install fish
    3. Run it:
      • fish

    If you find fish useful, you can set it as your default shell:

    • chsh -s "$(command -v fish)"

    Optional: Try installing zsh

    Another popular shell is zsh. Compared with bash, it supports richer interactive features (better tab completion, globbing, and prompt customization), and many users pair it with frameworks like oh-my-zsh to enable plugins and themes.

    1. Install zsh:
      • sudo apt install zsh
    2. Run it:
      • zsh

    If you find zsh useful, you can set it as your default shell:

    • chsh -s "$(command -v zsh)"

    Exercise 5: Sizes

    Write a C program that displays the sizes (in bytes) of different data types. You are only allowed to have one printf in the program - it has to be used inside a preprocessor macro. This macro can only have one argument. Each type should be output in a new line similar to this (with correct values of course):

    Size of short: 3

    Size of int: 5

    The sizes of the following types should be printed:

    • char
    • short
    • short int
    • int
    • long int
    • unsigned int
    • void *
    • size_t
    • float
    • double
    • int8_t
    • int16_t
    • int32_t
    • int64_t
    • time_t
    • clock_t
    • struct tm
    • NULL
    • struct { int a; short b; }

    Compile using: gcc -Wpedantic -Wall -Wextra -Wvla -Werror -std=c11 Use -m32 to compile it for 32bit and -m64 to compile it for 64bit. Note that you may need to install a package named gcc-multilib to compile with -m32.

    Checkoff:

    • Show and explain your source code to the TA.
    • Show the compilation of the 32bit and 64bit version to the TA.
    • Run both programs and explain the sizes and differences.
    • Explain why size of struct { int a; short b; } is not the sum of sizes of int and short

The following TA(s) are responsible for this lab: Chaofan Li <lichf2025@shanghaitech.edu.cn>