compilers class 22/7,23/7. introduction compiler: a compiler is a program that can read a program in...

13
COMPILERS CLASS 22/7,23/7

Upload: eileen-mitchell

Post on 29-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

COMPILERSCLASS 22/7,23/7

Page 2: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Introduction

• Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent program in another language (Target)

• An important role of the compiler is to report any errors in the source program that it detects during the translation process

Page 3: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Compiler :

Source code

Target codeCOMPILER

Reporterror

Page 4: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Target code : Target code is mostly an executable machine-language program. It can be called by the user to process inputs and produce outputs.

Input OutputTargetProgram

Page 5: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

MDR

MAR

IR

PC

ID

Control Unit

Accumulator

R0R1R2

ALU

Memory

Page 6: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Computer Architecture

Accumulator:

• When a mathematical operation is going on, operator is temporarily stored in Accumulator

• Content of memory location and the result is saved or stored through Accumulator

Page 7: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

MAR – Memory Address RegisterMDR – Memory Data RegisterMemory – Memory Block

Read, Write Signals: • MAR reads the data from the Memory block.• MDR writes into the Memory block.

Page 8: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Program Counter : Program Counter contains address of next instruction. Initially it carries address of first instruction.

Instruction Memory : All instructions are stored here.IR – Instruction RegisterID – Instruction Decoder

Page 9: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

ALU – Arithmetic Logic Unit• All the arithmetic operations are performed in

ALU• 2 terminals to the Accumulator• 1 terminal to the RegistersControl Unit:The control unit coordinates the components of a computer system. It fetches the code of all of the instructions in the program

Page 10: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Example

X [P] + [Q]Instruction MemoryData Memory

P,Q – Memory Address

P Q R

Page 11: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Steps:1. MAR finds the Address2. Data goes to MDR (Fetch P,Q)3. P,Q stored in Accumulator to registers 4. Perform Add operation5. Result is passed back to accumulator , from

accumulator to MDR. Write action is performed and the value is stored in ‘X’

Page 12: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

Address of P – 1000Address of Q – 2000Address of X – 2050Solution:LDA 1000MOV R0LDA 2000ADD R0STA 2050

Page 13: COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent

LDA – Load Data AddressMOV – If we don’t use this instruction the value in accumulator will be over writtenSTA – Stores the value in the memory address