Compilers Jakub Yaghob

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

The University of Adelaide, School of Computer Science
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
Computer Architecture CSCE 350
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
Procedure call frame: Hold values passed to a procedure as arguments
Lecture 8: MIPS Instruction Set
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
CS 536 Spring Code generation I Lecture 20.
Lecture 6: Procedures (cont.). Procedures Review Called with a jal instruction, returns with a jr $ra Accepts up to 4 arguments in $a0, $a1, $a2 and $a3.
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
CHAPTER 2 ISA Instructions (logical + procedure call)
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Lecture 4: MIPS Instruction Set
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Function Calls in MIPS To call a function: jal func
Run-time support Jakub Yaghob
Computer Science 210 Computer Organization
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
Computer Architecture Instruction Set Architecture
Function Calls in MIPS To call a function: jal func
CSCI206 - Computer Organization & Programming
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Procedures (Functions)
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
Instructions - Type and Format
CSCI206 - Computer Organization & Programming
Logical and Decision Operations
MIPS Instructions.
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Logical and Decision Operations
10/4: Lecture Topics Overflow and underflow Logical operations
Program and memory layout
Systems Architecture I
Program and memory layout
Computer Architecture
Program and memory layout
10/6: Lecture Topics C Brainteaser More on Procedure Call
Program and memory layout
Procedure Support From previous study of high-level languages, we know the basic issues: - declaration: header, body, local variables - call and return.
MIPS function continued
Presentation transcript:

Compilers Jakub Yaghob Computer skills Compilers Jakub Yaghob

Compiler Simplified definition Translates a source code in an input language to a target code of a given CPU program test; var s,i:integer; a:array[1..5] of integer; begin for i:=1 to 5 do a[i]:=I; s:=0; s:=s+a[i]; writeln(s); end. compiler .obj linker .exe

Control structures translation – if-then-else if A<>B then S1 else S2 lw $t1,A($zero) lw $t2,B($zero) beq $t1,$t2,L1 S1 j L2 L1: S2 L2:

Control structures translation – while while A<B do S1 L1: lw $t1,A($zero) lw $t2,B($zero) slt $t3,$t1,$t2 beq $t3,$zero,L2 S1 j L1 L2:

Control structures translation – repeat-until repeat S1 until A<B L1: S1 lw $t1,A($zero) lw $t2,B($zero) slt $t3,$t1,$t2 beq $t3,$zero,L1

Control structures translation – for sw $r0,S($r0) li $r1,1 sw $r1,I($r0) j L2 L1: lw $r1,I($r0) subi $r2,$r1,1 sll $r2,$r2,2 lw $r2,arr($r2) lw $r3,S($r0) add $r3,$r3,$r2 sw $r3,S($r0) addi $r2,$r1,1 sw $r2,I($r0) L2: li $r3,5 bne $r1,$r3,L1 type int=integer; var arr:array[1..5] of int; s,i:int; begin …fill the array… s:=0; for i:=1 to 5 do s:=s+arr[i] end

Function calls Calling convention in procedural languages Parameter passing Returning a value from a function Order of parameters evaluation Stack cleanup Stack frame pointer saving Return address saving Local variables Register preservation

Function calls Call mechanism (C language) Caller evaluates and stores actual parameters from right to left Caller passes control flow using a “CALL” instruction Callee saves return address on the stack Callee saves caller’s frame pointer on the stack Callee sets up its frame pointer Callee saves some registers Callee reserves space for local variables on the stack Callee executes its code Callee removes local variables from stack Callee restores preserved registers Callee restores caller’s frame pointer Callee jumps to the return address Caller removes parameters

Function calls – example { int a = f(1, 2); } int f(int i, int j) { int r = i + j; return r; } subi $sp,$sp,8 sw $ra,4($sp) sw $fp,0($sp) move $fp,$sp subi $sp,$sp,4 lw $t8,8($fp) lw $t9,12($fp) add $t1,$t8,$t9 sw $t1,-4($fp) lw $v0,-4($fp) lw $ra,4($fp) lw $fp,0($fp) addi $sp,$sp,12 jr $ra li $t8,2 subi $sp,$sp,4 sw $t8,0($sp) li $t8,1 jal f addi $sp,$sp,8 sw $v0,-4($fp) RA FP R30 A R29 J I RA FP R

Parameter passing Pass by value Pass by reference The actual value of the parameter is copied as a local variable of the callee Input parameter Pass by reference An address of the parameter is passed as local variable of the callee Input/output parameters procedure P(i:integer; var v:integer); P(1, a); A I = 1 V = @A

Activation record (frame) Control link Activation record of the caller Access link Pointer to nonlocal data held in other activation records Saved machine status Return address to the code Registers Return value Actual parameters Control link Access link Saved machine status Local data Temporaries