1.2. What is C?
A tool called a compiler is then used to
convert the high-level code into machine language. A program can be
written in C and compiled for any computer, it's up to the compiler to
get the hardware-specific instructions right.
To see just how readable C is compared to Assembly
language, take a look at the following tiny program written in each:
Example 1-1. C vs. Assembly language
.string "Tax Due: %d\n"
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $1000, %eax
movl $400, %edx
movl $0x3e6147ae, -12(%ebp)
subl %edx, %eax
leal 4(%esp), %esp
movw -18(%ebp), %ax
movb $12, %ah
movw %ax, -20(%ebp)
subl $8, %esp
addl $16, %esp
movl $1, %eax
And the program in C:
int wages = 1000;
int tax_allowance = 400;
float tax_rate = 0.22;
tax_due = (wages - tax_allowance) * tax_rate;
printf("Tax Due: %d euro\n", tax_due);
Which did you find easier to understand, even without knowing C. The
output of both programs is the same: "Tax Due: 131 euro"
The Assembly code shown is written in the "80386"
instruction set, it will not work on machines that use a different
instruction set. The C code can be compiled for practically any