COMPILERS CLASS 227 237 Introduction Compiler A Compiler

  • Slides: 13
Download presentation
COMPILERS CLASS 22/7, 23/7

COMPILERS CLASS 22/7, 23/7

Introduction • Compiler: A Compiler is a program that can read a program in

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

Compiler : Source code COMPILER Report error Target code

Compiler : Source code COMPILER Report error Target code

Target code : Target code is mostly an executable machine-language program. It can be

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 Target Program Output

MDR IR ID MAR PC Control Unit Memory Accumulator R 0 R 1 R

MDR IR ID MAR PC Control Unit Memory Accumulator R 0 R 1 R 2 ALU

Computer Architecture Accumulator: • When a mathematical operation is going on, operator is temporarily

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

MAR – Memory Address Register MDR – Memory Data Register Memory – Memory Block

MAR – Memory Address Register MDR – Memory Data Register Memory – Memory Block Read, Write Signals: • MAR reads the data from the Memory block. • MDR writes into the Memory block.

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

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 Register ID – Instruction Decoder

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

ALU – Arithmetic Logic Unit • All the arithmetic operations are performed in ALU • 2 terminals to the Accumulator • 1 terminal to the Registers Control Unit: The control unit coordinates the components of a computer system. It fetches the code of all of the instructions in the program

Example X [P] + [Q] Instruction Memory Data Memory P, Q – Memory Address

Example X [P] + [Q] Instruction Memory Data Memory P, Q – Memory Address P Q R

Steps: 1. MAR finds the Address 2. Data goes to MDR (Fetch P, Q)

Steps: 1. MAR finds the Address 2. Data goes to MDR (Fetch P, Q) 3. P, Q stored in Accumulator to registers 4. Perform Add operation 5. Result is passed back to accumulator , from accumulator to MDR. Write action is performed and the value is stored in ‘X’

Address of P – 1000 Address of Q – 2000 Address of X –

Address of P – 1000 Address of Q – 2000 Address of X – 2050 Solution: LDA 1000 MOV R 0 LDA 2000 ADD R 0 STA 2050

LDA – Load Data Address MOV – If we don’t use this instruction the

LDA – Load Data Address MOV – If we don’t use this instruction the value in accumulator will be over written STA – Stores the value in the memory address