Programming Languages (CS 550)

Similar documents
EE 6502 UNIT-II PROGRAMMING OF 8085 MICROPROCESSOR. Prepared by S.Sayeekumar, AP/RMDEEE

Chapter 3: Computer Organization Fundamentals. Oregon State University School of Electrical Engineering and Computer Science.

Computer Architecture 计算机体系结构. Lecture 3. Instruction-Level Parallelism I 第三讲 指令级并行 I. Chao Li, PhD. 李超博士

EECS 583 Class 9 Classic Optimization

ASAM ATX. Automotive Test Exchange Format. XML Schema Reference Guide. Base Standard. Part 2 of 2. Version Date:

FabComp: Hardware specication

CIS 371 Computer Organization and Design

GOPALAN COLLEGE OF ENGINEERING AND MANAGEMENT Department of Computer Science and Engineering COURSE PLAN

M2 Instruction Set Architecture

CIS 371 Computer Organization and Design

Lecture 14: Instruction Level Parallelism

Unit 9: Static & Dynamic Scheduling

Code Scheduling & Limitations

Out-of-order Pipeline. Register Read. OOO execution (2-wide) OOO execution (2-wide) OOO execution (2-wide) OOO execution (2-wide)

Computer Architecture: Out-of-Order Execution. Prof. Onur Mutlu (editted by Seth) Carnegie Mellon University

PQube 3 Modbus Interface

To read more. CS 6354: Tomasulo. Intel Skylake. Scheduling. How can we reorder instructions? Without changing the answer.

CS 6354: Tomasulo. 21 September 2016

COSC 6385 Computer Architecture. - Tomasulos Algorithm

CHAPTER 4 APPLIED OPERATION CHAPTER44 APPLIED OPERATION

Revision 6, January , Electronics Diversified, Inc.

Chapter 1: Battery management: State of charge

In-Place Associative Computing:

TECHNICAL MANUAL FOR ELECTRONIC SPEEDOMETER STR-RIEJU MATRIX 2

CPW Current Programmed Winder for the 890. Application Handbook. Copyright 2005 by Parker SSD Drives, Inc.

index changing a variable s value, Chime My Block, clearing the screen. See Display block CoastBack program, 54 44

DAT105: Computer Architecture Study Period 2, 2009 Exercise 2 Chapter 2: Instruction-Level Parallelism and Its Exploitation

128Mb Synchronous DRAM. Features High Performance: Description. REV 1.0 May, 2001 NT5SV32M4CT NT5SV16M8CT NT5SV8M16CT

The colorwav package

CMPEN 411 VLSI Digital Circuits Spring Lecture 24: Peripheral Memory Circuits

Permanent Magnet Motors for ESP Applications Updating the Track Record of Performance. Lorne Simmons VP Sales & Marketing

Installation And Programming Manual of OPTIMA Eco Tec and OPTIMA Pro Tec OBD/CAN

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, S. McKee, E. Sirer, H. Weatherspoon]

CSCI 510: Computer Architecture Written Assignment 2 Solutions

CIS 662: Sample midterm w solutions

Easy Weigh ADVANCED COUNTING SCALE MODEL: AC-100 OWNER S MANUAL VER 1.00

Examples using gdb. Text shown in bold red is what the user types.

PIPELINING: BRANCH AND MULTICYCLE INSTRUCTIONS

SP PRO ABB Managed AC Coupling

Overview of operation modes

A REPORT ON THE STATISTICAL CHARACTERISTICS of the Highlands Ability Battery CD

DS1250W 3.3V 4096k Nonvolatile SRAM

Ford Financial Statement Changes. January Dear Accounting Customer:

CMU Introduction to Computer Architecture, Spring 2013 HW 3 Solutions: Microprogramming Wrap-up and Pipelining

ARKANSAS DEPARTMENT OF EDUCATION MATHEMATICS ADOPTION. Common Core State Standards Correlation. and

Computer Architecture ELE 475 / COS 475 Slide Deck 6: Superscalar 3. David Wentzlaff Department of Electrical Engineering Princeton University

Pipelined MIPS Datapath with Control Signals

Advanced Superscalar Architectures. Speculative and Out-of-Order Execution

CS 152 Computer Architecture and Engineering

The High-Speed Benchmark. El-Exis SP. Maximum performance - Highest output

6.823 Computer System Architecture Prerequisite Self-Assessment Test Assigned Feb. 6, 2019 Due Feb 11, 2019

DS1643/DS1643P Nonvolatile Timekeeping RAM

Unit P.2, P2.3. Currents in electric circuits E ½. F Fuel gauge indicator. Fuel tank. Ammeter. Float. Battery. Sliding contact. Pivot 12V.

Fourth Grade. Multiplication Review. Slide 1 / 146 Slide 2 / 146. Slide 3 / 146. Slide 4 / 146. Slide 5 / 146. Slide 6 / 146

OVERVIEW OF CONTROLS

Fourth Grade. Slide 1 / 146. Slide 2 / 146. Slide 3 / 146. Multiplication and Division Relationship. Table of Contents. Multiplication Review

DS1250Y/AB 4096k Nonvolatile SRAM

Registers Shift Registers Accumulators Register Files Register Transfer Language. Chapter 8 Registers. SKEE2263 Digital Systems

Capacity Expansion. Operations Research. Anthony Papavasiliou 1 / 24

Instruction of connection and programming of the OSCAR-N MINI controller

SYNCHRONOUS DRAM. 128Mb: x32 SDRAM. MT48LC4M32B2-1 Meg x 32 x 4 banks

How to get started. with. Kongsberg XP Auto systems. Serial number: Please Read This First

GC MERGE OF LIGHT ENDS WITH ASTM D7169 BOILING POINT DISTRIBUTION

HYB25D256400/800AT 256-MBit Double Data Rata SDRAM

KISSsoft 03/2016 Tutorial 7

SDRAM DEVICE OPERATION

KISSsoft 03/2018 Tutorial 7

Busy Ant Maths and the Scottish Curriculum for Excellence Foundation Level - Primary 1

Draft Outline for NTE GTR September 8, 2004

APPENDIX A Instruction Set. Op Code. T states Flags Main Effects. Instructions

Parallelism I: Inside the Core

Land Rover and Jaguar

Tacoma 3RZ 4x4 ECM terminals, manual vs. automatic All data compiled from the factory service manual wiring guide

BMW TIS - Intelligent battery sensor: E60, E61, E63, E64 Installation location Item Description

Grade 1: Houghton Mifflin Math correlated to Riverdeep Destination Math

Houghton Mifflin MATHEMATICS. Level 1 correlated to Chicago Academic Standards and Framework Grade 1

Chapter 11. Using MAX II User Flash Memory for Data Storage in Manufacturing Flow

Capacity-Achieving Accumulate-Repeat-Accumulate Codes for the BEC with Bounded Complexity

DS1230Y/AB 256k Nonvolatile SRAM

FleetPro User Manual Online Card Management. Chevron Canada Limited Commercial & Industrial Marketing

SYNCHRONOUS DRAM. 256Mb: x4, x8, x16 SDRAM 3.3V

8.1 Testing Engine and Transmission Systems

index Page numbers shown in italic indicate figures. Numbers & Symbols

Cruise Control 1993 Jeep Cherokee

Instruction of connection and programming of the OSCAR-N controller

ST315B. User Handbook STAFFOR. ST315B Temperature Programmer. See separate handbook for Installation Instructions Issue: 2.00

NetLogo and Multi-Agent Simulation (in Introductory Computer Science)

FUEL CORRECTIONS: 13 July 2015

A Viewpoint on the Decoding of the Quadratic Residue Code of Length 89

Presented at the 2012 Aerospace Space Power Workshop Manhattan Beach, CA April 16-20, 2012

Quick Setup Guide for IntelliAg Model 3PYP 12 Row Single Row Air Pro

1.0 Symbols. Static bearing load [N] C d. Dynam ic bearing load [N] T 2 fem. T s-max

For motors controlled

Parameter Design and Tuning Tool for Electric Power Steering System

Subaru BRZ Toyota GT86 Scion FR-S

Storage and Memory Hierarchy CS165

Index. sequencing, 21, 26 starting off, 22 using, 28 code sequence, 28 custom pallete, 28

SDRAM AS4SD8M Mb: 8 Meg x 16 SDRAM Synchronous DRAM Memory. PIN ASSIGNMENT (Top View)

Operating Instructions SKC Inc. 863 Valley View Road Eighty Four, PA USA

Errors with S1/S2/S3/S4 Safety cards

Transcription:

Programming Languages (CS 550) Mini Language Compiler Jeremy R. Johnson 1

Introduction Objective: To illustrate how to map Mini Language instructions to RAL instructions. To do this in a systematic way that illustrates how to write a compiler to translate Mini Language programs to RAL programs. Show simple optimizations that can be used to reduce the number of instructions. Algorithm Construct code for expressions, assignments, if, and while. Concatenate statements in stmt-list Allocate temporaries as needed Keep track of variables, constants, and temporaries in Symbol Table Use symbolic instructions and fill in absolute addresses (linking) when complete code has been constructed 2

A Random Access Machine AC Control Unit Program AC = accumulator register... 1 2 3 4 5 6 Memory... 3

Instruction Set LDA X; Load the AC with the contents of memory address X LDI X; Load the AC indirectly with the contents of address X STA X; Store the contents of the AC at memory address X STI X; Store the contents of the AC indirectly at address X ADD X; Add the contents of address X to the contents of the AC SUB X; Subtract the contents of address X from the AC MUL X; Multiply the contents of address X to the contents of the AC JMP X; Jump to the instruction labeled X JMZ X; Jump to the instruction labeled X if the AC contains 0 JMN X; Jump to the instruction labeled X if the contents of the AC ; is negative HLT ; Halt execution 4

Memory Organization Constants Prog. Variables Num_Consts Num_Vars get_temp() Num_Temps Temp. Variables 5

Symbolic Instructions Addresses and labels can be symbolic names Symbolic names are mapped to actual addresses during linking Example: LD x ST z ADD y JMP L Linked code with (x=100, y =110, z = 105, L = 20) LD 100 ST 105 ADD 110 JMP 20 6

Symbol Table Map from identifiers Symbol table entries Symbol table entries contain: address [may be unknown] Indicate whether entry is an constant, variable, temporary or label 7

Expressions expr expr 1 op expr 2 Code 1 ; result stored in t 1 Code 2 ; result stored in t 2 LD t 1 ; load result of exp 1 OP t 2 ; apply op to result of exp 2 and result of exp 1 ST t 3 ; store result of exp 1 op exp 2 8

Expressions expr NUMBER ; check to see if NUMBER in symbol table, ; otherwise add to symbol table LD NUMBER ; load constant from constant table ST t n ; next available temporary 9

Expressions expr IDENT ; check to see if IDENT in symbol table ; otherwise add to symbol table LD IDENT ; load constant from constant table ST t n ; next available temporary 10

Assignment assign_stmt IDENT = expr ; check to see if IDENT in symbol table ; otherwise add to symbol table Code LD t ST IDENT 11

Conditional Statements if_stmt if expr then S 1 else S 2 fi Code e ; result stored in t LD t ; JMN L1 Code 1 JMP L2 L1: Code2 L2: 12

While Statements while_stmt while expr do S od L1: Code e ; result stored in t LD t ; JMN L2 L2: Code S JMP L1 13

Statement List stmt-list stmt; stmt-list stmt code 1 code 2 code n 14

Example n := 0-5; if n then i := n else i := 0 - n fi; fact := 1; while i do fact := fact * i; i := i - 1 od 15

Example n := 0-5; LD ZERO ST T1 LD FIVE ST T2 LD T1 SUB T2 ST T3 LD T3 ST n 16

Example if n then i := n else i := 0 - n fi; LD n ST T4 LD T4 JMN L1 LD n ST T5 LD T5 ST i JMP L2 L1: LD ZERO ST T6 LD n ST T7 LD T6 SUB T7 ST T8 LD T8 ST i L2: 17

Example fact := 1; LD ONE ST T9 LD T9 ST fact 18

Example while i do fact := fact * i; i := i - 1 od L3: LD i ST T10 JMN L4 LD fact ST T11 LD i ST T12 LD T11 MUL T12 ST T13 LD T13 ST fact LD i ST T14 LD ONE ST T15 LD T14 SUB T15 ST T16 LD T16 ST i JMP L3 L4: 19

Complete Example (concatenate and append HLT) LD ZERO ST T1 LD FIVE ST T2 LD T1 SUB T2 ST T3 LD T3 ST n LD n ST T4 LD T4 JMN L1 LD n ST T5 LD T5 ST i JMP L2 L1: LD ZERO ST T6 LD n ST T7 LD T6 SUB T7 ST T8 LD T8 ST i L2: LD ONE ST T9 LD T9 ST fact L3: LD i ST T10 JMN L4 LD fact ST T11 LD i ST T12 LD T11 MUL T12 ST T13 LD T13 ST fact LD i ST T14 LD ONE ST T15 LD T14 SUB T15 ST T16 LD T16 ST i JMP L3 L4: HLT 20

Symbol Table Name Value Type addr ZERO 0 const? FIVE 5 const? n u var? T1 u temp? T2 u temp? T3 u temp? T4 u temp? T5 u temp? i u var? T6 u temp? T7 u temp? T8 u temp? ONE 1 const? T9 u temp? fact u var? T10 u temp? T11 u temp? T12 u temp? T13 u temp? T14 u temp? T15 u temp? T16 u temp? 21

Symbol Table and Label Summary Num_Vars = 3 Num_Consts = 3 Num_Temps = 16 Constants ZERO -> addr 1 FIVE -> addr 2 One -> addr 3 Variables n -> addr 4 i -> addr 5 fact -> addr 6 Temporaries T1 -> addr 7 T2 -> addr 8 T16 -> addr 22 L1 = 19 L2 = 28 L3 = 32 L4 = 54 22

Linked Example LD 1 ST 7 LD 2 ST 8 LD 7 SUB 8 ST 9 LD 9 ST 4 LD 4 ST 10 LD 10 JMN 19 LD 4 ST 11 LD 11 ST 5 JMP 28 L1: LD 1 ST 12 LD 4 ST 13 LD 12 SUB 13 ST 14 LD 14 ST 5 L2: LD 3 ST 15 LD 15 ST 6 L3: LD 5 ST 16 JMN 53 LD 6 ST 17 LD 5 ST 18 LD 17 MUL 18 ST 19 LD 19 ST 6 LD 5 ST 20 LD 3 ST 21 LD 20 SUB 21 ST 22 LD 22 ST 5 JMP 32 L4: HLT 23

Optimizations Peephole optimization Remove ST immediately followed by LD Commute (expr 1,expr 2 ) in expr expr 1 op expr 2 to allow additional peephole optimizations Constant folding Common subexpression elimination 24

Complete Example (after peephole optimization) LD ZERO ST T1 LD FIVE ST T2 LD T1 SUB T2 ST T3 LD T3 ST n LD n ST T4 LD T4 JMN L1 LD n ST T5 LD T5 ST i JMP L2 L1: LD ZERO ST T6 LD n ST T7 LD T6 SUB T7 ST T8 LD T8 ST i L2: LD ONE ST T9 LD T9 ST fact L3: LD i ST T10 JMN L4 LD fact ST T11 LD i ST T12 LD T11 MUL T12 ST T13 LD T13 ST fact LD i ST T14 LD ONE ST T15 LD T14 SUB T15 ST T16 LD T16 ST i JMP L3 L4: HLT 25

Complete Example (after peephole optimization) LD ZERO ST T1 LD FIVE ST T2 LD T1 SUB T2 JMN L1 LD n L1: LD ZERO ST T6 LD n ST T7 LD T6 SUB T7 ST i L2: LD ONE L3: LD i ST T10 JMN L4 LD fact ST T11 LD i ST T12 LD T11 LD i ST T14 LD ONE ST T15 LD T14 SUB T15 ST i JMP L3 L4: HLT ST i ST fact MUL T12 JMP L2 ST fact 38 vs. 54 instructions 26

Supporting Procedures Fully static environment No recursion Activation record Parameters Local variables (keep count) Return address (indirect jump needed) Can be statically allocated Dynamic environment Allow recursion Call stack (dynamic allocation) Indirect load and store needed 27

Memory Organization Constants Global Prog. Variables Global Temp. Variables Activation Records Constants Global Prog. Variables Global Temp. Variables Call Stack 28

Program Memory Organization Procedures P1 P2 P3 Main Program Procedure Entry in Function Table Number of parameters Number of local/temp variables Starting address Number of instructions Need to know starting address of main program 29

Activation Record Frame Pointer Parameters For call stack Local Variables Temp. Variables Stack Pointer Return Address 30

Example: fact(n) define proc(n) i := n; fact := 1; while i do fact := fact * i; i := i - 1 od; return := fact end 31

fact(n) LD n ST T1 LD T1 ST i LD ONE ST T2 LD T2 ST fact L1: LD i ST T3 JMN L2 LD fact ST T4 LD i ST T5 LD T4 MUL T5 ST T6 LD T6 ST fact LD i ST T7 LD ONE ST T8 LD T7 SUB T8 ST T9 LD T9 ST i JMP L1 L2: LD fact ST T10 LD T10 ST return 32

Activation Record FP SP n i fact T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 return ret. addr. Accessing AR LD n LDI FP ST n STI FP LD i LD FP ADD ONE ST FPB LDI FPB LDO FP[1] ST i STO FP[1] LD Tj LDO FP[j+Num_Param+Num_Vars] 33

Initiate call 1. Create activation record 1. Update FP and SP Calling Sequence 2. Store parameters in activation record 3. Store return address (RA) 4. Jump to starting address of procedure code 1. Introduce call instruction (can place RA relative to SP) Return from call 1. Store return value in activation record (when return is assigned) 2. Jump to RA 1. Introduce ret instruction (jmp indirect) 3. Retrieve return value from activation record 4. Update FP and SP 34