Notes - Assembly language and gcc

Author: William T Krieger Updated: Oct 3, 2003

We will be using the Gnu Compiler Collection (gcc) to assemble our assembly language programs. Gcc is a piece of free software provided by GNU (GNU's not Unix) [ www.gnu.org ]. Gcc includes compilers for a number of different languages include C and C++. It also provides an assembler for many different architectures, including the Pentium which is of interest to us. It also includes linkers and loaders so that it can create executable files for the architectures (CPU and operation system) that it supports.

Installing gcc

You need to install gcc on your computer. We will be using version 2.95 of gcc compiled for Windows created by Cygwin [ www.cygwin.com ].

First, here's a copy of the installation notes that are provided with this download of gcc:

INSTALL.TXT

Download the self-extracting executable in the link below:

GCC-2.95.2-MSVCRT.EXE

and then download this bug fix tweak:

QUOTE-FIX-MSVCRT.EXE

I have installed gcc on two separate computers, using all the default settings, and had no problems... for whatever that's worth, eh.

A note on rationale... we are using the gcc because it is a flexible tool that allows us to write in C, C++ and Pentium assembly language. We are using version 2.95 of gcc because 1) it has been used in previous incarnations of CSC 220 at North Central College, and 2) it's a small, stable program. I have downloaded a more recent version of gcc, and it was much larger than the 7 MB of version 2.95. In short, gcc version 2.95 should satisfy all the needs we have for class.

Running gcc

Designed in a Unix environment, gcc does not have a Windows interface. You can run gcc in a DOS command shell. If you are unfamiliar with DOS or the command shell, here are some hints. 

cd <folder> change the current folder (like chdir)
chdir <folder> change the current folder (like cd)
dir display the files in the current folder (like ls)
help displays all the commands available and a one-line description of each
help <cmd> displays the help text related to the command specified
ls display the files in the current folder (like dir)

Other than setting your current folder to wherever your assembly language programs are and running gcc, I'd use Windows for everything else. You can run gcc in your command shell with the command:

gcc

Controlling gcc

Gcc is the Swiss army knife of compilers - it has many different possible functions. These functions are controlled by specifying options to the gcc command. The basic format is:

gcc <input_files> <options>

The format of the <input_files> can be any of the languages supported by gcc: C, C++, Pentium assembler, etc. This format is typically determined automatically by gcc using the suffix of the file(s) specified. Here are some suffixes and their corresponding file type:

Options to gcc begin with a dash "-".

Let's look at some common tasks you'll want to complete using gcc.

gcc hello.c

Compiles and links C source file hello.c and creates an executable file a.out

gcc hello.c -o hello.exe

Complies and links hello.c, creating the executable hello.exe

gcc hello.s

Assembles the assembly source file hello.s and creates an executable file a.out

gcc hello.s -o hello.exe

Assembles the assembly source file hello.s and creates an executable file hello.exe

gcc hello.c -S

Compiles the C source file hello.c but stops after creating assembly code for the program and creates an assembly language file hello.s

Please note that this command is useful in seeing what assembly language code the compiler creates for a given C program.