3.2.Program Encoding
\(3.2.\)Program Encoding
1.Program execution process
Say we want to compile two C program p1.c
and
p2.c
, we input the command:
1 | linux> gcc -0g -o p p1.c p2.c |
The C preprocessor expands the source code to include any files specified with
#include
commands and with#define
declarations.Compiler generates assembly code having name
p1.s
andp2.s
.Assembler converts the assembly code into binary object-code files
p1.o
andp2.o
.
The object code contains binary representations of all instructions, but doesn't include the address of the global value.
- Linker merges these two object-code files along with code
implementing library functions (e.g.,
printf
) and generates the final executable code filep
(specified by-o p
).
2.Machine code
\(a.\)Program memory
The program memory contains:
the executable machine code for the program
some information required by the operating system
a run-time stack for managing procedure calls and returns
blocks of memory allocated by the user (e.g., by using the
malloc
library function).
\(b.\)Some command
We use -S
to see the assembly code generated by the
compiler:
1 | gcc -0g -S mstore.c |
We use -c
to both compile and assemble the code:
1 | gcc -0g -c mstore.c |
This will generate an object-code file mstore.o
.
To inspect the contents of machine-code, we can use the
disassembler. The program objdump
can serve the
role:
1 | objdump -d mstore.o |
The result is as below: