Kat H.

# Compilation is normally encapsulated so that all of the necessary steps happen behind the scenes. Type the following C code into a file named count.c.

Compilation

Compilation is normally encapsulated so that all of the necessary steps happen behind the scenes. Type the following C code into a file named count.c.

#include <stdio.h>

#include <stdlib.h>

#define TARGET 10

int main(){

int i;

for (i = 0; i < TARGET; ++i)

printf("%d\n", i);

return EXIT_SUCCESS;

}

You can compile this code all at once with the following command.

gcc -o count count.c

You can verify with ls that there are now two files: count.c containing your source code, and count, the executable program. (If you’re used to Windows where programs have a .exe extension, you’ll have to get used to the tradition in UNIX that programs do not have an extension at all.) You can run the program and see it work by entering the following.

./count

## Compiling

cc -S -o count.s count.i

Note that we start from the preprocessed .i file and that the traditional extension for the assembly language output is .s. Again, have a look inside the resulting file—you are not expected to understand assembly language yet, but we will be learning a lot about it in the coming weeks.

## Assembling

as -o count.o count.s
gcc -c -o count.o count.s

xxd count.o

gcc -o count count.o

## The assignment

Work through the example above. submit all of the files along the way:

1. count.c
2. count.i
3. count.s
4. count.o
5. count
xxd file dumped # dump file into dumped
# now edit dumped
xxd -r dumped file # patch the changes back into the original

## 1 Expert Answer

By:

Patrick B. answered • 04/14/21

Tutor
4.7 (31)

Math and computer tutor/teacher

## Still looking for help? Get the right answer, fast.

Get a free answer to a quick problem.
Most questions answered within 4 hours.

#### OR

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.