Lecture No. 01
Dated: 13-03-2025
Typical Compilation
Source Code
int expr(int n) {
int d;
d = 4 * n * n * (n + 1) * (n + 1)l
return d;
}
Intel X86 Assembly Code
The source code above is converted into corresponding assembly code
which is machine dependent. Meaning that the gcc
compiler translates the source code according to the platform (machine) it is compiling on.
.globl _expr
_expr:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
movl %eax, %edx
leal 0(,%edx,4), %eax
movl %eax, %edx
imull 8(%ebp), %edx
movl 8(%ebp), %eax
incl %eax
imull %eax, %edx
movl 8(%ebp), %eax
incl %eax
imull %eax, %edx
movl %edx, -4(%ebp)
movl -4(%ebp), %edx
movl %edx, %eax
jmp L2
.align 4
L2:
leave
ret
Issues in Compilation
The translation process is complex and is done in multiple passes.
There is no unique translation from source language to destination language.