Lecture 6: Mini Language Compiler
Background Material
Reading
- Chapter 5 (sec. 1-5) of the text (Basic Semantics - Symbol Table)
- Chapter 7 (sec. 1-3) of the text (Control I - Expressions and Statements)
- Chapter 8 (sec. 1-4) of the text (Control II - Procedures)
Theme
This lecture shows how to write a compiler that translates Mini Language
programs to programs that execute on a simpler model of computation, namely
a bounded memory random access machine with a single accumulator. The compiler
uses the same infrastructure for parsing that the Mini Language Interpreter
used.
Topics
- Random Access Machine (RAM) model.
- Random Access Machine Assembly Language (RAL)
- Compiling Mini Language expressions and statements to RAL
- Symbol Table, Memory Model and Linking symbolic RAL programs.
- Simple optimizations
- Adding support for procedures
- Activation records and local variables
- Parameter passing
- return statement
- Call stack
Lecture Notes
Programs
- ram.h - interface for RAM simulator class
- inst.h - instruction opcodes for RAM
- ram.cpp - implementation of RAM simulator
class
- main.cpp - main program to run RAM simulator
- prog.txt - sample RAM program
- mem.txt - sample RAM memory configuration
Exercises
- Compile and run the RAM simulator on a sample RAL program.
- Write a RAL program which takes two input integers at addresses 1 and 2 and
multiplies them storing the result at address 4. You may assume that they
are non-negative.
- Extend the RAM simulator to support the MUL and JMZ instructions.
- assignment 6.
- assignment 7.
Created: May 8, 2008 by jjohnson AT cs DOT drexel DOT edu