Heart of SaM: a Stack and Stack Pointer (SP) 7-2 SP (Stack Pointer) Stack

Size: px
Start display at page:

Download "Heart of SaM: a Stack and Stack Pointer (SP) 7-2 SP (Stack Pointer) Stack"

Transcription

1 What is SaM? SaM is a simple stack machine that we will use to (i) understand virtual machines and Java portability, and (ii) understand at the assembly language level how computers work. Heart of SaM: a Stack and Stack Pointer (SP) - SP (Stack Pointer) Stack SaM I Am Stack: an array of integers Stack grows when integer is "pushed" on top. Stack shrinks when integer is "popped" from top. Stack starts at address and grows to larger addresses. Stack pointer: first "free" address in stack (initialized to )

2 SaM commands ALL arithmetic/logical operations pop values from stack perform operation and push result. SaM Commands PUSHIMM *some integer* //pushes that integer on stack ADD //pops two values from top of stack //adds them and pushes result SUB //pops two values (say top and below) //and pushes result of doing (below - top) - SP 5 SP TIMES GREATER // boolean values are simulated using / (false/true) AND //logical AND... ADD - pop two values from stack ( and -) - add them (5) - push result SUB: similar; result would be (-) - () = -9 STOP //terminate execution of program 8 6 Operations on Stack - 6 SP - Pushing 6 on stack SP Pushing an Integer - SaM Commands 6 - SP SP - SP - Pop: removes from stack and returns it SP Popping an Integer PUSHIMM 6 - push the integer 6 on stack Stack operations are used to implement SaM commands. They are NOT SaM commands themselves. 5

3 SaM Commands - - SP SP DUP : duplicate the top element of the stack note: nothing is popped from stack SaM Commands - SP SP Here are two simple SaM programs: 5 PUSHIMM PUSHIMM PUSHIMM PUSHIMM TIMES Booleans are simulated in SaM with integers True ->, false -> GREATER - pop two values (Vtop and Vbelow) from stack - in example, Vtop = and Vbelow = - - if Vbelow > Vtop push else push - in example, we would push. TIMES //should leave on top of stack STOP 5 PUSHIMM PUSHIMM GREATER //should leave on top of stack STOP TIMES 9

4 How do commands get into Program array? Sample program execution: HALT PC HALT PC - Stack SP Program PUSHIMM PUSHIMM ADD Loader: method that is given a filename reads in commands from file and writes them into We will assume all programs are loaded into program memory starting at address. Program array Program SP Stack PUSHIMM 5 PUSHIMM GREATER STOP 6 Where does program reside in SaM? Program Stack HALT SP PC PUSHIMM PUSHIMM ADD Program: an area of memory that contains commands Program Counter (PC): address of command to be executed Program execution: PC = ; while (HALT == ) //STOP command sets HALT to Execute command Program[PC]; //arithmetic and logical commands increment PC Stack Interpreter: PC = ; Stack Pointer while (HALT == ){ Execute Program[PC]; Reboot HALT Program Program Counter opcode: PUSHIMM operand: 5 opcode: PUSHIMM operand: Loader: Loc = ; do{ Read a command from file; Create Instruction object for command; Program[Loc] = Instruction object; Loc++; while (! EOF) SaM PUSHIMM 5 PUSHIMM opcode: TIMES File TIMES... STOP 5

5 far, SaM commands were executed sequentially: each command So PC when it was done. incremented ability to skip some commands ability to repeatedly execute some sequence of commands understand this program, let us look at where these commands To stored in the Program area. are JUMP t: jump to instruction at Program[t] and start instructions from there on. Implementation: PC t executing JUMPC t: pop boolean from stack if it is true, execute starting at Program[t] otherwise, this command commands no eect and execution continues with command after this has one. Implementation: pop top of stack (V top ). If V top PUSHIMM 5 Jumps and Conditional Jumps PUSHIMM GREATER //is 5 > JUMPC 5 //if so, jump to 5 PUSHIMM Need more exibility to translate conditionals and loops: // this command will be stored at Program[5] PUSHIMM STOP Solution: JUMP/JUMPC commands 8 Frame Base Register HALT PC JUMP/JUMPC: like GOTOs in Pascal - FBR SP Program PUSHIMM PUSHIMM ADD Stack Frame Base Register: used to implement method invocations for now, assume it contains PC t otherwise, PC + +. is true, 9

6 Write a program to nd absolute value of element on top of stack. Program SP 68 SP //work-horses void reboot() int load(string s) //input:file name, returns number of commands lo void start() //start execution void dumpstate() //print out registers and stack contents DUP //duplicate top of stack...//other methods we will see later PUSHIMM GREATER //n >? JUMPC 6 //forward jump to STOP PUSHIMM - TIMES //(n)*(-) STOP interface SaM{ //getter and setter methods void setfbr(int v) Program getfbr() int Address : PUSHIMM 5 void setpc(int v) int getpc() void setsp(int v) : PUSHIMM getsp() int : GREATER //is 5 > void setstackelement(int a, int v) //Stack[a] = v int : JUMPC 5 //if so, jump to 5 getstackelement(int a) //return Stack[a] : PUSHIMM 5: PUSHIMM //convenient setter and getter methods 6: STOP void push(int v) int pop() void incpc()

7 class Instruction implements InstructionInterface{ private String opcode One approach to writing a SaM simulator: class Simulator { //main class private int operand //optional public Instruction(CSIn f) {... //read one command from file and make Instruction class SaMmy implements SaMInterface{... //return string representing command class Instruction implements InstructionInterface{... public void execute(sam machine) { //execute instruction 8 6 interface InstructionInterface { class Simulator { public static void main(string[] arg) { if (arg.length == ) { System.out.println("sam file must be command line argument") return void execute(sam machine) SaM Sumatra = new SaMmy() //My machine is called Sumatra int psize = Sumatra.load(arg[]) Sumatra.start() Sumatra.dumpState() 5

8 class SaMmy implements SaM{ public void execute(sam machine){ //for executing the instruction... public void start() { //Execute instructions starting at Program[] if (opcode.equals("add")){ int op = machine.pop() HALT = PC = int op = machine.pop() machine.push(op + op) do { Program[PC].execute(this) machine.incpc() while(halt == ) else if (opcode.equals("pushimm"){ //other opcode public Instruction(CSIn inf) { class SaMmy implements SaM{ opcode = inf.getword() if (opcode.equals("pushimm"))//only command with an explicit operand operand = inf.getint() protected int PC,FBR,SP,HALT protected InstructionInterface[] Program = new InstructionInterface[] protected int[] Stack = new int[] public int load(string ProgramFile) { //Load in instructions from ProgramFile and store in Program CSIn inf = new CSIn(ProgramFile) //create input manager int LC = //LC is where next instruction should be put public String tostring(){ while (inf.peekatkind()!= inf.eof) if (opcode == PUSHIMM) { Program[LC] = new Instruction(inf) return ("PUSHIMM " + operand) LC++ else return opcode inf.close() return LC... 9

9 can we still store dierent types of instructions into Program How in SaM? array new command => changing a bunch of variables and Adding in the Instruction class: methods you wrote this sort of code, you might as well program in a If language!! non-oo class ADDInst implements InstructionInterface { Modular solution: USE SUBTYPING return "ADD" Represent each opcode by its own class. public void execute(sam machine) { Adding new opcode = adding new class to program! machine.pop() int op = int op = machine.pop() machine.push(op + op) Answer: all classes implement InstructionInterface! machine.incpc() Happily, type of Program is InstructionInterface[]! 6 Critique of solution: Instruction SaMmy Type Picture InstructionInterface Object SaM opcodetable, constructor, tostring, execute, No easy way to extend the code to accommodate more commands. ADDInst SUBInst STOPInst... PUSHIMMInst JUMPInst... 5

10 Let load read in opcode and create an instance of the Solution: class. right How does this change SaM class? No change needed to start method!! class SaMmy implements SaM{ public int load(string ProgramFile) {//override Load in SaM class SaMmy implements SaM{... CSIn inf = new CSIn(ProgramFile) //create input manager public void start() { //Execute instructions starting at Program[] int LC = //LC is where next instruction should be put HALT = PC = ReadLoop: while (inf.peekatkind()!= inf.eof) do { { String s = inf.getword() Program[PC].execute(this) //type dispatch!! InstructionInterface i if (s.equals("add")) i = (InstructionInterface)new ADDInst() while(halt == ) else if (s.equals("sub")) i = (InstructionInterface)new SUBInst()... else... 8 class SaMmy implements SaM{ class SUBInst implements InstructionInterface {... return "SUB" public void Execute(SaM machine) { public int load(string ProgramFile) { //Load in instructions from ProgramFile and store in Program CSIn inf = new CSIn(ProgramFile) int LC = while (inf.peekatkind()!= inf.eof) { Program[LC] = new Instruction(inf) <--- does not make sense int op = machine.pop() int op = machine.pop() LC++ machine.push(op - op) machine.incpc() inf.close() return LC... There is no Instruction class anymore to instatiate! 9

11 of load code: still need a conditional that must be Criticism when opcode is added! modied some cool code: given a String representing a class name, Heres an instance of that class! create note: Why cant reading of operands be performed by Java in the ADDInst, SUBInst etc. classes? constructors if you use reection to generate a class name on the y, Problem: can only call the default constructor that takes no arguments. you public int load(string ProgramFile) { CSIn inf = new CSIn(ProgramFile) //create input manager int LC = //LC is where next instruction should be put ReadLoop: while (inf.peekatkind()!= inf.eof) { String s = inf.getword() So we cannot pass inf to it. InstructionInterface i try { i = (InstructionInterface)(Class.forName(s + "Inst")).newInstance() catch (Exception e) {System.out.println("Funny opcode " + s) break ReadLoop //now read in operands i.readoperand(inf) //must extend InstructionInterface to i.readoperand(inf) Program[LC] = i //require readoperand method Program[LC] = i LC++ LC++ return LC return LC Reection: interpret a string as a class name and create an instance of that class!

12 class JUMPCInst implements InstructionInterface { class PUSHIMMInst implements InstructionInterface { protected int operand protected int operand public void readoperand(csin inf) { public void readoperand(csin inf) { operand = inf.getint() operand = inf.getint() return "JUMPC " + operand return "PUSHIMM " + operand public void execute(sam machine) { public void execute(sam machine) { if (machine.pop() == ) machine.setpc(operand) machine.push(operand) machine.incpc() else machine.incpc() 8 6 Heres the denition of the new instruction interface: interface InstructionInterface { void readoperand(csin inf) class JUMPInst implements InstructionInterface { void execute(sam machine) protected int operand... public void readoperand(csin inf) { operand = inf.getint() class ADDInst implements InstructionInterface { public void readoperand(csin inf) { //no-op return "JUMP " + operand public void execute(sam machine) { return "ADD" public void execute(sam machine) { machine.setpc(operand) int op = machine.pop() int op = machine.pop() machine.push(op + op) machine.incpc() 5

13 Instruction: contains code common to all instructions (dont this with old Instruction class we dened at the start, I confuse ran out of meanginful names) just InstructionWithOperand extends Instruction: contains code instructions with no operands All will have exactly the (ADD,SUB,TIMES,GREATER,NOT,...) instructions with one operand (PUSHIMM,JUMP,...) will have All the same readoperand method. exactly abstract class Instruction implements InstructionInterface{ abstract public void execute(sam machine) public void readoperand(csin inf) {//do nothing Answer: use inheritance Dene two abstract classes: protected String mnemonic() { //another use of reflection String s = this.getclass().getname() return s.substring(, s.length() - ("Inst".length())) common to all instructions with an operand. return mnemonic() 5 5 OK, so this is cool, but there is a fair amount of code repeated. InstructionWithOperand InstructionInterface Object SaM Instruction SaMmy same readoperand method. ADDInst SUBInst STOPInst... Is there a way to \share" this code between dierent classes? PUSHIMMInst JUMPInst

14 far, JUMP and JUMPC commands (in le) took an integer So operand. numbers Any command can be given a label. Final twist to SaM saga: symbolic labels in SaM commands class ADDInst extends Instruction { //inherit tostring and readoperand! public void execute(sam machine) { int op = Example: JUMP 68 machine.pop() int op = machine.pop() It is more convenient to use symbolic labels for commands. machine.push(op + op) machine.setpc(machine.getpc() + ) Label: a name that starts with a letter and contains letters and A command may have multiple labels //This is the class for all instructions with one operand. //The operand can be a word or an integer. abstract class InstructionWithOperand extends Instruction{ protected int operand class JUMPInst extends InstructionWithOperand{//inherit tostring,readoperand public void execute(sam machine) { mnemonic() + " " + operand return machine.setpc(operand) public void readoperand(csin inf) { if(inf.peekatkind() == inf.integer) operand = inf.getint() //else should report error 5 55

15 Commands like JUMP take symbolic labels as operands Within machine, instructions like JUMP require integer as operands. addresses Who does the conversion from labels to integers? hash table. called Hash table maintains a set of (key,value) pairs. In our example, are symbolic labels and values are integers (addresses keys to the symbolic labels). corresponding from the hash table. pair Designing a hash table for fast look up: see later. While loading the program, create a directory of (symbolic address) pairs (like a telephone directory) name, JAMES =, BOND =, etc.). (eg. Directory is called a symbol table. After loading is done, walk over instructions in Program and each symbolic name by address, using symbol table (eg, replace Symbol table is an example of a more general data structure Question: Two main operations: insert a new (key,value) pair look up the value corresponding to a key Answer: loader. Sometimes, we may also want to delete a particular (key,value) 6 58 Additional duty of loader: PUSHIMM //some value n DUP //duplicate top of stack PUSHIMM GREATER //n >? JUMPC BOND //forward jump to instruction labeled BOND PUSHIMM - TIMES //(n)*(-) JAMES: replace BOND in instruction JUMPC BOND by. BOND: STOP This is called a two-pass loader. 5 59

16 change loader so it keeps track of (name, address) pairs change InstructionWithOperand so it can read in and store a operand symbolic add a translate method to each instruction: given symbol look up symbolic operand and translate to integer if table, necessary. while(s.endswith(":")) {String tmpstr = s.substring(,s.length()-) boolean success = ST.insert(tmpstr,LC) if (! success) println("multiply defined label " + tmpstr ) //check for dangling label at end of file interface InstructionInterface{ if (inf.peekatkind() == inf.eof) break FirstLoop void readoperand(csin inf) //reads one integer or word operand else s = inf.getword() void execute(sam machine) void translate(symboltable ST, SaM m) //translate symbolic addresses into integers //at this point, s should contain the opcode InstructionInterface i try { i = (InstructionInterface)(Class.forName(s + "Inst")).n catch (Exception e) {println("funny opcode " + s) return //two pass loader: first pass reads in instructions into Program array This requires the following changes: //but does not translate symbolic operands. second pass performs translatio //returns number of instructions read in public int load(string ProgramFile) { CSIn inf = new CSIn(ProgramFile) //create input manager return load(inf) public int load(csin inf) { SymbolTable ST = new SymbolTable() int LC = //LC is where next instruction should be put //First Pass LC = FirstLoop: while (inf.peekatkind()!= inf.eof) { String s = inf.getword() //eat up labels 6 6

17 abstract class Instruction implements InstructionInterface{ abstract public void execute(sam machine) public void readoperand(csin inf) { public void translate(symboltable ST, SaM m) { public void translate(symboltable ST, SaM m) { //if we had a symbolic operand if (! dest.equals("")) { //translate protected String mnemonic() { //the opcode String s = this.getclass().getname() operand = ST.lookup(dest) return s.substring(, s.length() - ("Inst".length())) if (operand == -) m.println("undefined name " + dest) //change dest so that we can print both dest and operand dest = dest + " //address: " return mnemonic() i.readoperand(inf) Program[LC] = i //This is the class for all instructions with one operand. LC++ //The operand can be a word or an integer. abstract class InstructionWithOperand extends Instruction{ inf.close() protected String dest = new String("") protected int operand //Second Pass for (int i = i < LC i++) { mnemonic() + " " + dest + operand return if (Program[i] == null) public void readoperand(csin inf) { if(inf.peekatkind() == inf.word) println("??? Null instruction at location " + i) dest = new String(inf.getWord()) else Program[i].translate(ST, this) else if(inf.peekatkind() == inf.integer) operand = inf.getint() return LC 65 6

18 give SaM a few more commands to make it possible to Lets real programs to SaM commands. compile "real" programs, we often need to read and write stack locations In than topmost stack location. other this corresponds to treating Stack area as if it is a Intuitively, memory. conventional PUSHIND Command 68 SP 68 SP Before PUSHIND After PUSHIND PUSHIND : TOS contains a Stack address. Pop that address, read contents of that address, and push. STOREIND Command 68 SP SaM continued 5??? So far, we have only pushed and popped values from stack. Before STOREIND After STOREIND STOREIND : TOS contains a value. Below that is a stack address. Pop these from the stack and Write value into that address. 69

19 PUSHFBR/POPFBR Commands SP SP 69 68??? FBR 6 6??? FBR 6 Before PUSHFBR After PUSHFBR PUSHFBR: Push contents of FBR on stack. Stack[SP] = FBR; SP++; POPFBR: Inverse operation SP--; FBR = Stack[SP]; 6 PUSHOFF Command STOREOFF Command SP SP SP SP FBR FBR FBR FBR Before PUSHOFF After PUSHOFF Before STOREOFF After STOREOFF PUSHOFF x : let v be value stored in address (FBR + x) push v on top of stack FBR is unchanged STOREOFF x : Say TOS contains value v. Pop it from the stack and write v into address (FBR + x) FBR is unchanged 5

20 Two instructions for control transfer in method call/return: JSR xxxx: Push address of next instruction on stack and jump to xxxx JUMPIND: Pop an address from stack, and jump to that address Example:... JSR foo //assume this instruction is stored in Program[] ADD... foo: ADDSP 5 //assume foo is JUMPIND //assume this instruction is stored at Program[]... Sequence of PC values:, 98, 99,...,,,, PUSHSP/POPSP Commands ADDSP Command 68 SP SP 69 68?????? 68 - SP 68 6 SP 6 Before PUSHSP After PUSHSP Before ADDSP -5 After ADDSP -5 PUSHSP: Push contents of SP on stack. Stack[SP] = SP; SP++; POPSP: Inverse operation SP--; SP = Stack[SP]; ADDSP: takes one integer as explicit operand Add that integer to SP ADDSP n can be written in terms of other instructions: PUSHSP PUSHIMM n ADD POPSP Convenient to have just one command. 9

21 and inheritance are powerful tools for writing reusable Interfaces programs. (inheritance,interfaces). type Dynamic method binding: permits existing code to splice in (of implementation) Permits subtype to be dened Inheritance incrementally language (BASIC, FORTRAN,...). favorite SaM code is portable - write SaM code (or compile SaM code say a Java program) and ship SaM code around the from Internet. is like SaM. (JVM) JVM is much more complicated than SaM - need to support Interfaces permit independent development of implementation and client code. code Interfaces permit objects of dierent types to be stored in one structure. Example: instructions of dierent types in data Central ideas: Subtyping: permits you to dene an extension of an existing the new type without modication. Useful idea: SaM Simulator brings all these ideas together. 8 Final Notes on SaM Interfaces in SaM simulator: Portability of SaM code: SaM standard: everyone agrees on SaM commands, labels etc. On all Macs/PCs/etc, provide SaM simulator written in your Interfaces document specications. methods must SaM support to permit instructions to What execute? What methods do instructions support? Java achieves portability the same way - Java Virtual Machine Program array threads, multiple data types, need to worry about security etc. 8 8

What is SaM? SaM is a simple stack machine designed to introduce you to compilers in a few lectures SaM I: written by Dr. Keshav Pingali around 2000

What is SaM? SaM is a simple stack machine designed to introduce you to compilers in a few lectures SaM I: written by Dr. Keshav Pingali around 2000 SaM I Am What is SaM? SaM is a simple stack machine designed to introduce you to compilers in a few lectures SaM I: written by Dr. Keshav Pingali around 2000 modeled vaguely after JVM SaM II: complete

More information

SaM. 1. Introduction. 2. Stack Machine

SaM. 1. Introduction. 2. Stack Machine SaM 1. Introduction Have you ever heard the Java mantra, write once, run everywhere? So, how does that work? When you compile a Java program, you generate a binary file that contains byte-code. Byte-code

More information

About Functions. Purpose: Encapsulate procedural information Control flow and call order. Scope (Global vs. Local) Parameters Recursion

About Functions. Purpose: Encapsulate procedural information Control flow and call order. Scope (Global vs. Local) Parameters Recursion SaM Functions Purpose: Encapsulate procedural information Control flow and call order Callee vs. Caller Scope (Global vs. Local) Parameters Recursion Each function call as a separate invocation About Functions

More information

This section provides some reminders and some terminology with which you might not be familiar.

This section provides some reminders and some terminology with which you might not be familiar. Chapter 3: Functions 3.1 Introduction The previous chapter assumed that all of your Bali code would be written inside a sole main function. But, as you have learned from previous programming courses, modularizing

More information

Compiling Techniques

Compiling Techniques Lecture 10: Introduction to 10 November 2015 Coursework: Block and Procedure Table of contents Introduction 1 Introduction Overview Java Virtual Machine Frames and Function Call 2 JVM Types and Mnemonics

More information

SaM v2.6 Design Documentation. Ivan Gyurdiev David Levitan

SaM v2.6 Design Documentation. Ivan Gyurdiev David Levitan SaM v2.6 Design Documentation Ivan Gyurdiev David Levitan 9/5/2005 Contents 1 Introduction 6 1.1 What is SaM?.............................. 6 1.2 What is SaM 2?............................. 6 1.3 What

More information

CMa simple C Abstract Machine

CMa simple C Abstract Machine CMa simple C Abstract Machine CMa architecture An abstract machine has set of instructions which can be executed in an abstract hardware. The abstract hardware may be seen as a collection of certain data

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: The CPU and Memory How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: 1 Registers A register is a permanent storage location within

More information

CS 11 C track: lecture 8

CS 11 C track: lecture 8 CS 11 C track: lecture 8 n Last week: hash tables, C preprocessor n This week: n Other integral types: short, long, unsigned n bitwise operators n switch n "fun" assignment: virtual machine Integral types

More information

CSc 453 Interpreters & Interpretation

CSc 453 Interpreters & Interpretation CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson Interpreters An interpreter is a program that executes another program. An interpreter implements a virtual machine,

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int

More information

Virtual Machine Tutorial

Virtual Machine Tutorial Virtual Machine Tutorial CSA2201 Compiler Techniques Gordon Mangion Virtual Machine A software implementation of a computing environment in which an operating system or program can be installed and run.

More information

Computer Architecture

Computer Architecture Computer Architecture Chapter 2 Instructions: Language of the Computer Fall 2005 Department of Computer Science Kent State University Assembly Language Encodes machine instructions using symbols and numbers

More information

JAM 16: The Instruction Set & Sample Programs

JAM 16: The Instruction Set & Sample Programs JAM 16: The Instruction Set & Sample Programs Copyright Peter M. Kogge CSE Dept. Univ. of Notre Dame Jan. 8, 1999, modified 4/4/01 Revised to 16 bits: Dec. 5, 2007 JAM 16: 1 Java Terms Java: A simple,

More information

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Java: framework overview and in-the-small features

Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

LAB C Translating Utility Classes

LAB C Translating Utility Classes LAB C Translating Utility Classes Perform the following groups of tasks: LabC1.s 1. Create a directory to hold the files for this lab. 2. Create and run the following two Java classes: public class IntegerMath

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 44: Interpreters Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1] Compiler

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

Course Administration

Course Administration Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701

More information

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters CSc 453 Compiler source Lexer tokens Parser AST Compilers and Systems Software 18 : Interpreters VM Code Gen IR Interm. Code Gen AST Semantic Analyser Department of Computer Science University of Arizona

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format Course Overview What This Topic is About PART I: overview material 1 Introduction 2 Language processors (tombstone diagrams, bootstrapping) 3 Architecture of a compiler PART II: inside a compiler 4 Syntax

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15 Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL

More information

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13 Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,

More information

Special Section: Building Your Own Compiler

Special Section: Building Your Own Compiler cshtp6_19_datastructures_compiler.fm Page 1 Tuesday, February 14, 2017 10:31 AM 1 Chapter 19 Special Section: Building Your Own Compiler In Exercises8.31 8.33, we introduced Simpletron Machine Language

More information

Module 27 Switch-case statements and Run-time storage management

Module 27 Switch-case statements and Run-time storage management Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

More information

Parsing Scheme (+ (* 2 3) 1) * 1

Parsing Scheme (+ (* 2 3) 1) * 1 Parsing Scheme + (+ (* 2 3) 1) * 1 2 3 Compiling Scheme frame + frame halt * 1 3 2 3 2 refer 1 apply * refer apply + Compiling Scheme make-return START make-test make-close make-assign make- pair? yes

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst Department of Computer Science Why C? Low-level Direct access to memory WYSIWYG (more or less) Effectively

More information

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality Problem Chapter 10 Memory Model for Program Execution Original slides by Chris Wilcox, Colorado State University How do we allocate memory during the execution of a program written in C?! Programs need

More information

Stacks and Function Calls

Stacks and Function Calls Stacks and Function Calls Embedded Systems 3-1 Remember the Memory Map for Our MCU Embedded Systems 3-2 Classifying Data Variables Automatic declared within a function Only exist while the function executes

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

CSc 553. Principles of Compilation. 2 : Interpreters. Department of Computer Science University of Arizona

CSc 553. Principles of Compilation. 2 : Interpreters. Department of Computer Science University of Arizona CSc 553 Principles of Compilation 2 : Interpreters Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg Compiler source Lexer tokens Parser AST VM

More information

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd 19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading

More information

Implementing Functions at the Machine Level

Implementing Functions at the Machine Level Subroutines/Functions Implementing Functions at the Machine Level A subroutine is a program fragment that... Resides in user space (i.e, not in OS) Performs a well-defined task Is invoked (called) by a

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types

More information

The Java language has a wide variety of modifiers, including the following:

The Java language has a wide variety of modifiers, including the following: PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access

More information

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to

More information

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control. C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of

More information

Quadsim Version 2.1 Student Manual

Quadsim Version 2.1 Student Manual Boston University OpenBU Computer Science http://open.bu.edu CAS: Computer Science: Technical Reports 1993-02-21 Quadsim Version 2.1 Student Manual Shaban, Marwan Boston University Computer Science Department

More information

Code Generation. Lecture 12

Code Generation. Lecture 12 Code Generation Lecture 12 1 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation

More information

In this chapter you ll learn:

In this chapter you ll learn: Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading on

More information

CSE P 501 Exam 8/5/04

CSE P 501 Exam 8/5/04 Name There are 7 questions worth a total of 65 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references: Course

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013 CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013 Name: This exam consists of 5 problems on the following 6 pages. You may use your double-sided hand-written 8 ½ x 11 note sheet

More information

Compilers CS S-05 Semantic Analysis

Compilers CS S-05 Semantic Analysis Compilers CS414-2003S-05 Semantic Analysis David Galles Department of Computer Science University of San Francisco 05-0: Syntax Errors/Semantic Errors A program has syntax errors if it cannot be generated

More information

Collections, Maps and Generics

Collections, Maps and Generics Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

Character Stream : It provides a convenient means for handling input and output of characters.

Character Stream : It provides a convenient means for handling input and output of characters. Be Perfect, Do Perfect, Live Perfect 1 1. What is the meaning of public static void main(string args[])? public keyword is an access modifier which represents visibility, it means it is visible to all.

More information

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism CMSC 330: Organization of Programming Languages Polymorphism Polymorphism Definition Feature that allows values of different data types to be handled using a uniform interface Applicable to Functions Ø

More information

When an instruction is initially read from memory it goes to the Instruction register.

When an instruction is initially read from memory it goes to the Instruction register. CS 320 Ch. 12 Instruction Sets Computer instructions are written in mnemonics. Mnemonics typically have a 1 to 1 correspondence between a mnemonic and the machine code. Mnemonics are the assembly language

More information

Brief Summary of Java

Brief Summary of Java Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming

More information

Virtual Machine. Part I: Stack Arithmetic. Building a Modern Computer From First Principles.

Virtual Machine. Part I: Stack Arithmetic. Building a Modern Computer From First Principles. Virtual Machine Part I: Stack Arithmetic Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Chapter 7:

More information

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE 1 SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ Java Programming Language Java Introduced in 1995 Object-oriented programming

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

Instructions: Assembly Language

Instructions: Assembly Language Chapter 2 Instructions: Assembly Language Reading: The corresponding chapter in the 2nd edition is Chapter 3, in the 3rd edition it is Chapter 2 and Appendix A and in the 4th edition it is Chapter 2 and

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

CS 211 Programming Practicum Spring 2017

CS 211 Programming Practicum Spring 2017 Due: Tuesday, 3/28/17 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a JAVA program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

CMSC 202. Exceptions

CMSC 202. Exceptions CMSC 202 Exceptions Error Handling In the ideal world, all errors would occur when your code is compiled. That won t happen. Errors which occur when your code is running must be handled by some mechanism

More information

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

More information

SOURCE LANGUAGE DESCRIPTION

SOURCE LANGUAGE DESCRIPTION 1. Simple Integer Language (SIL) SOURCE LANGUAGE DESCRIPTION The language specification given here is informal and gives a lot of flexibility for the designer to write the grammatical specifications to

More information

We will study the MIPS assembly language as an exemplar of the concept.

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be tricky) when you translate high-level code into assembler code. MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to

More information

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COMP 250 Winter 2011 Reading: Java background January 5, 2011 Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY III: PROCEDURES. Jo, Heeseung ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static,

More information

Assembly III: Procedures. Jo, Heeseung

Assembly III: Procedures. Jo, Heeseung Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Summer 2003 Lecture 14 07/02/03

Summer 2003 Lecture 14 07/02/03 Summer 2003 Lecture 14 07/02/03 LAB 6 Lab 6 involves interfacing to the IBM PC parallel port Use the material on wwwbeyondlogicorg for reference This lab requires the use of a Digilab board Everyone should

More information

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented

More information

Code Generation. Lecture 19

Code Generation. Lecture 19 Code Generation Lecture 19 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation

More information