Using gcc for Intel Assembler

Author: William T Krieger Updated: Sep, 2005

This term we are using the MinGW version of gcc to assemble our programs. I know. Ack... acroynms:

  • gcc (GNU Compiler Collection) is a handy (re. free) compiler, assembler, linker provided by the free software guys are GNU. Gcc handles many languages including C, C++ and our flavor of Intel assembly language. Web site: http://gcc.gnu.org/ 
  • MinGW (Minimalist GNU for Windows) is a port of gcc (and other stuff) from Unix to the Windows operating system. Web site: http://www.mingw.org/

Unfortunately, some computers in the lab (Carnegie 210, mostly) have MinGW, and some don't. You can look for MinGW in the Programs menu on the Start button. You can also try running gcc in a DOS window (see below).

Also, I have CD's with the software on them that you can install on your own computer.

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. 

  • DOS command shell - The specifics of starting a DOS command shell is going to depend on your machine and/or what version of Windows you are using. The following steps will work for many of you:
    1. Click on the Start button
    2. Select Run...
    3. Enter cmd
  • Dos commands - if you haven't used DOS in a while (or ever), the following commands can be entered:
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++, Intel 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:

  • *.c - C source file
  • *.s - assembly language source file
  • *.o - object file

Options to gcc begin with a dash "-".

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

  • Compile a C program

gcc hello.c

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

gcc hello.c -o hello.exe

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

  • Run the assembler

gcc hello.s

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

gcc hello.s -o hello.exe

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

  • Show compiler's assembly code

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.