Understanding Compiler

In this class, We discuss Understanding Compiler.

For Complete YouTube Video: Click Here

The reader should have prior knowledge of computer architecture processors and instructions. Click Here.

Here the reader will get a basic understanding of the compiler’s responsibility.

The example we discuss helps in understanding the next classes.

First, we refresh the concepts of computer architecture.

The computer architecture basics help in understanding the compiler design.

The below diagram shows the processor registers and random access memory.

We have a data register DR and a register named accumulator.

If we need to add two numbers. Example 2+5.

We place the value 2 in the data register. And value 5 in the accumulator.

We give the add instruction.

The add instruction will take value present in the data register and accumulator as input to ALU.

The ALU will add the two inputs, and the result is saved in the accumulator.

The above processor is discussed in our computer architecture subject.

The Random access memory RAM is also shown.

The instructions store, load, add, etc., are known in Computer architecture.

Store 250. This instruction will take the value in the accumulator and place it in memory location 250.

Store #20 250 instruction will place the binary value 20 in memory location 250.

Load 500 instruction will get the data present in 500 memory location to the accumulator.

The opcode for a store instruction is 0000.

Whenever we mention store in machine level, it is represented using 0000.

We write instructions in English for understanding. But they are binary.

In instruction, we have the opcode and address part.

The above basics on computer architecture are needed to understand compiler design.

Now we move to the compiler.

Given C Program.

int a=2, b= 5, c;

c= a+b;

The compiler’s goal is to convert the given high-level language to machine-level instructions shown above.

We use other programs to convert the high-level language to machine-level language.

The compiler, assembler, loader, etc., are some of the programs responsible for converting high to machine levels.

Most of the part is done by the compiler.

In this subject, we deal with compilers.

The remaining programs are not discussed in detail.

We give a basic understanding of converting high-level language to machine-level language.

The example we used in this class will help the readers in the following classes.

Int a =2 after reading the line, the compiler takes ‘a’ as a variable.

The variable should be assigned a memory location.

Assume the variable a is assigned memory location 510.

The details of the variable are saved in a table.

Assume in our RAM each line is 2 bytes.

The instruction is 16 bit. So we can place each instruction in one line of RAM.

Similarly, the variables b and c are assigned memory locations 511 and 512, respectively.

We write instructions.

Store #2, 510 this instruction will save the value 2 in memory location 10.

Store #5, 511 this instruction will keep the value 5 in memory location 511

load DR, 510. This instruction will save the value present in memory location 510 to the data register.

Load AC, 511 instruction will save the value present in memory location 511 to the accumulator.

the instruction ‘add’ will add the value present in DR and AC and place the result in AC

Store AC, 512 instruction will save the value present in the accumulator to memory location 512.

To execute the program, we need the instructions and data storage locations.

The responsibility of compiler, assembler, and loader to convert the high-level language to machine understanding code.