You are on page 1of 3

Assignment

Theory of Compiler

Submitted To: Syeda Rabail Zahra

Submitted By: Muhammad Usama Asghar

Roll No: 05 (Five)

Class: BSCS 5th

Session: 2015-19

Year: 2018
Q: 01 - What is the role of compiler in computer science?
The role of a compiler in computer science is that it a special program
that processes statements written in a particular programming
language and turns them into machine language or "code" that a
computer's processor uses. Typically, a programmer writes language
statements in a language such as Pascal or C one line at a time using an
editor.

Q: 02 - If compiler operates in different phases, then what about


interpreter?
Interpreters and compilers are very similar in structure. The main
difference is that an interpreter directly executes the instructions in the
source programming language while a compiler translates those
instructions into efficient machine code.

An interpreter will typically generate an efficient intermediate


representation and immediately evaluate it. Depending on the
interpreter, the intermediate representation can be an AST, an
annotated AST or a machine-independent low-level representation
such as the three-address code.

Q: 03 - Explain the role of code optimization.


The role of code optimization is that it is the process of transferring the
source code into least number of possible bytes, by eliminating all the
unnecessary instructions from the source program. Unnecessary
instructions mean un-executable statements. Code optimization is the
most researched area of compiler construction.
Q: 04 - At what stage of compilation, memory is assigned to variables?
If we answer this strictly, Compiler does not allocate/assign memory for
variables; in fact it generates code that allocates memory for variables
at runtime.

But if we answer this question very loosely then it must be the first
stage of compilation - Lexical Analysis phase where the Symbol Table is
constructed which stores all the symbols.

In general, the ‘static memory allocation’ is the allocation of memory at


compile time, before the associated program is executed, unlike
‘dynamic memory allocation’ or automatic memory allocation where
memory is allocated as required at run time.

Q: 05 - Write an assembly program to add two numbers.


1. .model small
2. .stack 256
3. .code
4. Mov al,’2’
5. Mov bl,’3’
6. Add al,bl ;al=al+bl
7. Mov dl,al
8. Sub dl,48
9. Mov ah,02
10. Int 21h
11. Mov ah,4ch
12. Int 21h
13. end

You might also like