{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab 3 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

Lab 3 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 3 - FL13 Lab 3 assignment is due on Thursday, September 12, by 7pm in your svn repository. To work with this lab, you need lecture 6. Tour of the program building process For the first part of this exercise, we'll take you through the steps involved in building an executable program from C source. You do not need to manually follow these steps every time you build a program, this is only done once in here so that you can see what is going on "under the hood" . At the end of the tour, we'll show you that you can have the compiler, "gcc", do all of these steps for you with one invocation like so: Your first C program Go to your ece198jl directory and create a new subdirectory called "lab3". All your today's work should be stored in this subdirectory. By now you probably guessed that this is also going to be a part of your lab 3 assignment. Add this newly created subdirectory to your svn repository and verify its existence using the web browser. If you have any difficulties with this step, please refer to Lab 1. Take this code and put it in a file called hello-world.c (we didn't want to spoil the moment by giving it to you ) Step 1: Preprocess The preprocessor expands preprocessor directives , which is any line that starts with a "#". These are processed before your code is compiled. The following preprocesses hello-world.c, putting the preprocessed code in a new file called hello-world.i. Run the above command and look at the preprocessed file hello-world.i; you'll see a bunch of stuff and then your code (at the very end ). This is the result of expanding the "#include" preprocessor directives. Can you figure out what the "#define" directive did? Step 2: Compile The compiler then takes preprocessed C code and translates it into assembly language, in this case x86 assembler. The following compiles hello-world.i into the assembly language file hello-world.s: Run this and look at the assembly language file. One day you will learn about the assembly language. For now, just note that our gcc -g -std=c99 -Wall -Werror -o hello-world -l c hello-world.c #include <stdio.h> #define MESSAGE "Hello, x86 world!" int main() { puts(MESSAGE); return 0 ; } gcc -E -o hello-world.i hello-world.c gcc -S -o hello-world.s hello-world.i
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
program written in machine-independent high-level language C got translated into a low-level machine-specific assembly language. Step 3: Assemble The x86 assembler takes the assembly language file hello-world.s and outputs an object file hello-world.o containing x86 machine code: Go ahead and run this. The x86 assembler outputs a single file, which contains both symbols and machine code. To see the symbol table of the file (remember that it's a binary file, so you can't just open it with a text editor) use objdump: There are two rows of 64-bit hex values (the 0000000000000000s). The first row is the (relative) address, the second is the size of each section. You'll see a "main" symbol with size x15, that's your main subroutine. You'll also see a symbol called "puts" marked "UND" for undefined, can you guess what that is?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern