University of Minnesota
Machine Architecture and Organization (sec 010)

CSci 2021 Lab 0x0

Welcome to the first lab section of Computer Science 2021, Machine Architecture and Organization. The purpose of the lab sections in this class is to give you hands-on experience with some of the tools and concepts that we've introduced in lecture that you will use on your own in assignments. We want the lab sections to be supportive learning environments: we have scheduled several TAs to go around the room and help you if you have questions or get stuck, and please also talk to and help the other students sitting next to you!

For each lab we have prepared a variety of activities for you to try, roughly in order of increasing complexity. There is no specific expectation about how much you can get through during the in-lab section, and you may find it worthwhile to continue activities on your own afterwards. Attendance in the lab does contribute to your course grade, so be sure to talk to a TA at least once during the course of each lab; if you don't need them to answer any questions, show one of them what you've done once you've gotten through some of the activities. (Our expectation is for you to be checked off as attending at least 12 of the 15 lab sections over the course of the semester for full attendance credit.)

Since this lab is happening on the first day of class, we aren't covering any new concepts, but we'd like you to get a little practice with some of the basics of using the lab computers, which you can then build on in the rest of the course. If you've already had experience using Linux in other classes or on your own, this may mostly be review, but our systems do have some quirks it's worth familiarizing yourself with.

  1. The first steps for each lab section will be to log in to one of the computers, open a web browser, and find the page off of the course web site which describes that lab's activities. If you are reading this on a web page in lab, it looks like you've managed to do that successfully. But if you're helping someone else, the URL for this page should be:

    Or, step by step, start from the department homepage at, then follow links for People/Faculty, Stephen McCamant's Home Page, scroll down to Teaching to find the link for this class, and follow links to Labs and Lab 0x0.

  2. In keeping with the low-level perspective of 2021, most lab activities will involve programs that you run using the computer's command-line interface. So within the graphical user interface, you'll need to open a "terminal" window where you can type commands and see their output. On the standard lab machine interface, the Terminal program has an icon that looks like a black screen, or you can start it with the keyboard shortcut Ctrl-Alt-T.

  3. The programming language you'll be using most often in 2021 is C. If you have used Java or C++ before, you will find that a lot of C's syntax looks familiar, but C isn't object-oriented and doesn't have many fancy features. In fact, C code can be translated fairly directly into the low-level machine code that computer actually executes; understanding this translation is one of the goals for you to become familiar with in 2021.

    You'll write C programs by putting their source code in a plain text file which conventionally has a filename ending in .c, and then compiling this source code into an executable program using a tool called a compiler. Like C++, but unlike Java, the output of the C compiler is machine code that the computer can execute directly.

    By tradition, the first C program that you write doesn't do anything fancy, it just prints a welcome message. Here is what your first program should look like:

    #include <stdio.h>
    int main(int argc, char **argv) {
        printf("Hello, world!\n");
        return 0;

    For now, you don't need to understand what all the parts of the program do; we'll talk more about the C language in the first few lectures. But let's practice creating a plain text file containing the program, and compiling and running it. There are a number of different text editor programs on the lab machines that you can use, but as a first one, we recommend a simple graphical text editor named gedit, which is similar to Notepad on Windows. To start editing a file named hello.c containing your program source code, type the command gedit hello.c & in your terminal window. gedit is the name of the command, hello.c tells gedit what file to edit (it will create it if the file doesn't already exist), and the & ("ampersand") symbol at the end of the command runs the editor "in the background" so that you can also type commands in the terminal while the editor is running. For this first time, we'd recommend typing the whole program in character by character, for practice finding all the special characters, noticing the difference between the parentheses () and the curly braces {}, and so on. Once you've finished you can use gedit's save command to write the file.

  4. The C compiler we'll be using is called GCC, and the command-line program to run it is called gcc. Some class activities might give inconsistent results if you're not using the same version of GCC, so let's take a minute to make sure you have the right version available. Run the command gcc --version: the output should be gcc (GCC) 4.9.2 followed by a copyright message. If you see a different version, try using the command module load soft/gcc/4.9.2 and check gcc --version again.

    The command to compile your first program is

    gcc -Wall -g hello.c -o hello

    -Wall and -g are two options that are not strictly required but that we recommend you usually use: -Wall turns on a large number of compiler warnings, which print messages about things that are not illegal but may still indicate a mistake. -g directs the compiler to include extra information in the final executable which can be used by a debugger, a useful tool that we'll talk in more detail about later. If you typed the program correctly, there shouldn't be any warnings or errors; if you see any, go back to the editor to change the source code and try again. The option -o hello tells the compiler to name the final program it produces hello: the convention on Unix systems is that executable programs don't have file extensions. (On Windows, this would be hello.exe instead.)

  5. Once your sample program has been compiled, you can run it with the command ./hello. This follows a similar pattern as the other commands you've seen, but the ./ in front of the command indicates that the program is found in the current directory, where you just compiled it, instead of one of the system program directories. If everything is working correctly, your program should print a welcome message and then finish.

  6. Next, we'd like you to try out a couple of tools you can use if you want to work on 2021 assignments, but you aren't in one of the computer labs. You can work on your 2021 assignments from any computer with a network connection by connecting remotely to computers on campus. We recommend this as the most reliable approach, since you'll still be using exactly the same software that you would in the labs. First, there is a remote graphical interface to the lab machines that is named VOLE. To use it, open up a new tab or window in your web browser, and connect to Click on "Connect Now", log in, then click on "Launch Session", click on the "XFCE" icon, and press "Launch". When doing this for the first time in a web browser, you may need to disable popup blocking. Inside your web browser you'll see a desktop that looks a bit different from the default one on the lab machines, but has most of the same basic features, such as a terminal and web browser accessible from icons at the bottom of the screen. For practice, repeat steps 2-5 above in this interface by opening a terminal window, running gedit from it to make a change to hello.c, and then recompiling and rerunning the program.

  7. You can also connect to the CSELabs machines using a command-line-only interface. In addition to being more traditional, this has the benefit that the command line interface requires fewer computer resources on the CSELabs machines. Of course we don't recommend that you put off your assignments until the last minute, but if you do, you may find that the labs and VOLE servers are all busy, but the command-line interface is still running fast. The way to make a command line connection is with a program named ssh. On Unix systems, this is a command-line program. For instance, you can connect to any of the machines in this very lab. The command looks like:


    Replace username with your username (this part and the @ is optional when going from one CSELabs machine to another). Replace the N with the number of one of the machines next to you, which is probably either one more or one less than the number of your machine, as shown on a label and also in your command-line prompt. This command will ask for your password and then if that's correct, you'll see a command-line prompt from the machine you asked to connect to. You can use this in the same way as the other Terminal windows you've seen. For suggestions about text editors that you can use over a command-line interface, see the next part.

  8. Now that you have the basics down, here are some other things you can work on for more familiarity with our lab environment:

    • You should be familiar with the basics of a Unix/Linux command line, for instance commands like ls to list the files in a directory and cp to copy files from one place to another. The following Linux command-line tutorial would be a good resource to go though if you don't already feel confident about these.

    • One text editor that you can use either from a command-line interface or from the GUI is called Emacs. To learn about it, you can run the command emacs from a terminal and then click on the "Emacs Tutorial" link that appears on the startup screen.

    • The other most commonly used family of Unix/Linux text editors after Emacs is called "vi". To get an introduction on how to use the "vim" variant of vi, run the command vimtutor from a terminal.

    • If you'd like to try exploring a slightly more complex C program, we've created one named lab0-mystery.c that you can try. Make a copy of the source code in your own directory with the command

      cp /web/classes/Spring-2020/csci2021/labs/0x0/lab0-mystery.c .

      (Note the . at the end of that command, which is an important argument to the command and not the end of a sentence.) Try compiling the program, running it with various arguments, and changing it to understand what it does. You can also learn more about the library functions that this code calls with the man command: for instance man strdup will show you a description of what strdup does. Hint (highlight to read): Try ./lab0-mystery 13 uggcf://