1 Lecture 6: Compilers, the SPIM Simulator Today’s topics:  SPIM simulator  The compilation process Additional TA hours: Liqun Cheng, email legion at.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
The University of Adelaide, School of Computer Science
Lecture 9: MIPS Instruction Set
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
10/6: Lecture Topics Procedure call Calling conventions The stack
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
SPIM and MIPS programming
Systems Architecture Lecture 5: MIPS Instruction Set
Computer Architecture CSCE 350
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
MIPS Assembly Language Programming
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
1 Computer Architecture MIPS Simulator and Assembly language.
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
CS 536 Spring Code generation I Lecture 20.
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety.
1 Lecture 7: Computer Arithmetic Today’s topics:  Chapter 2 wrap-up  Numerical representations  Addition and subtraction Reminder: Assignment 3 will.
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
Appendix A: MIPS Assembly Language. Instruction Format R-type I-type J-type.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
1 4.2 MARIE This is the MARIE architecture shown graphically.
Spr 2015, Feb 9... ELEC / Lecture 4 1 ELEC / Computer Architecture and Design Spring 2015 Compiling and Executing Programs.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
Lecture 4: MIPS Instruction Set
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
ISA's, Compilers, and Assembly
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
CS 312 Computer Architecture & Organization
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Code Optimization.
Computer Architecture & Operations I
MIPS Assembly Language Programming
Lecture 6: Assembly Programs
Introduction to Lab #1 José Nelson Amaral.
Lecture 7: MARS, Computer Arithmetic
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Instructions - Type and Format
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
Lecture 7: Examples, MARS, Arithmetic
Компьютерийн зохион байгуулалт, ассемблер CS201
COMS 361 Computer Organization
Lecture 6: Assembly Programs
COMS 361 Computer Organization
Where is all the knowledge we lost with information? T. S. Eliot
CPU Structure CPU must:
Lecture 4: Instruction Set Design/Pipelining
Program Assembly.
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Presentation transcript:

1 Lecture 6: Compilers, the SPIM Simulator Today’s topics:  SPIM simulator  The compilation process Additional TA hours: Liqun Cheng, legion at cs, Office: MEB 2162 Office hours: Mon/Wed TA hours for Josh: Wed 11:45-12:45 (EMCB 130) TA hours for Devyani: Wed 11:45-12:45 (MEB 3431)

2 IA-32 Instruction Set Intel’s IA-32 instruction set has evolved over 20 years – old features are preserved for software compatibility Numerous complex instructions – complicates hardware design (Complex Instruction Set Computer – CISC) Instructions have different sizes, operands can be in registers or memory, only 8 general-purpose registers, one of the operands is over-written RISC instructions are more amenable to high performance (clock speed and parallelism) – modern Intel processors convert IA-32 instructions into simpler micro-operations

3 SPIM SPIM is a simulator that reads in an assembly program and models its behavior on a MIPS processor Note that a “MIPS add instruction” will eventually be converted to an add instruction for the host computer’s architecture – this translation happens under the hood To simplify the programmer’s task, it accepts pseudo-instructions, large constants, constants in decimal/hex formats, labels, etc. The simulator allows us to inspect register/memory values to confirm that our program is behaving correctly

4 Example This simple program (similar to what we’ve written in class) will run on SPIM (a “main” label is introduced so SPIM knows where to start) main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 If we inspect the contents of $t2, we’ll find the number 12

5 User Interface main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 File add.s > spim (spim) read “add.s” (spim) run (spim) print $10 Reg 10 = 0x c (12) (spim) reinitialize (spim) read “add.s” (spim) step (spim) print $8 Reg 8 = 0x (5) (spim) print $9 Reg 9 = 0x (0) (spim) step (spim) print $9 Reg 9 = 0x (7) (spim) exit

6 Directives.text.globl main main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 … jal swap_proc jr $ra.globl swap_proc swap_proc: … File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions) This function is visible to other files

7 Directives.data.word 5.word 7.byte 25.asciiz “the answer is”.text.globl main main: lw $t0, 0($gp) lw $t1, 4($gp) add $t2, $t0, $t1 … jal swap_proc jr $ra File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions)

8 Labels.data in1.word 5 in2.word 7 c1.byte 25 str.asciiz “the answer is”.text.globl main main: lw $t0, in1 lw $t1, in2 add $t2, $t0, $t1 … jal swap_proc jr $ra File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions)

9 Endian-ness Two major formats for transferring values between registers and memory Memory: low address 45 7b 87 7f high address Little-endian register: the first byte read goes in the low end of the register Register: 7f 87 7b 45 Most-significant bit Least-significant bit Big-endian register: the first byte read goes in the big end of the register Register: 45 7b 87 7f Most-significant bit Least-significant bit

10 System Calls SPIM provides some OS services: most useful are operations for I/O: read, write, file open, file close The arguments for the syscall are placed in $a0-$a3 The type of syscall is identified by placing the appropriate number in $v0 – 1 for print_int, 4 for print_string, 5 for read_int, etc. $v0 is also used for the syscall’s return value

11 Example Print Routine.data str:.asciiz “the answer is ”.text li $v0, 4 # load immediate; 4 is the code for print_string la $a0, str # the print_string syscall expects the string # address as the argument; la is the instruction # to load the address of the operand (str) syscall # SPIM will now invoke syscall-4 li $v0, 1 # syscall-1 corresponds to print_int li $a0, 5 # print_int expects the integer as its argument syscall # SPIM will now invoke syscall-1

12 Example Write an assembly program to prompt the user for two numbers and print the sum of the two numbers

13 Example.text.data.globl main str1:.asciiz “Enter 2 numbers:” main: str2:.asciiz “The sum is ” li $v0, 4 la $a0, str1 syscall li $v0, 5 syscall add $t0, $v0, $zero li $v0, 5 syscall add $t1, $v0, $zero li $v0, 4 la $a0, str2 syscall li $v0, 1 add $a0, $t1, $t0 syscall

14 Compilation Steps The front-end: deals mostly with language specific actions  Scanning: reads characters and breaks them into tokens  Parsing: checks syntax  Semantic analysis: makes sure operations/types are meaningful  Intermediate representation: simple instructions, infinite registers, makes few assumptions about hw The back-end: optimizations and code generation  Local optimizations: within a basic block  Global optimizations: across basic blocks  Register allocation

15 Dataflow Control flow graph: each box represents a basic block and arcs represent potential jumps between instructions For each block, the compiler computes values that were defined (written to) and used (read from) Such dataflow analysis is key to several optimizations: for example, moving code around, eliminating dead code, removing redundant computations, etc.

16 Register Allocation The IR contains infinite virtual registers – these must be mapped to the architecture’s finite set of registers (say, 32 registers) For each virtual register, its live range is computed (the range between which the register is defined and used) We must now assign one of 32 colors to each virtual register so that intersecting live ranges are colored differently – can be mapped to the famous graph coloring problem If this is not possible, some values will have to be temporarily spilled to memory and restored (this is equivalent to breaking a single live range into smaller live ranges)

17 High-Level Optimizations High-level optimizations are usually hardware independent Procedure inlining Loop unrolling Loop interchange, blocking (more on this later when we study cache/memory organization)

18 Low-Level Optimizations Common sub-expression elimination Constant propagation Copy propagation Dead store/code elimination Code motion Induction variable elimination Strength reduction Pipeline scheduling

19 Title Bullet