Course Administration

Similar documents
COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Lecture 5: Procedure Calls

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

MIPS%Assembly% E155%

ECE232: Hardware Organization and Design

Chapter 2A Instructions: Language of the Computer

EE 361 University of Hawaii Fall

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Instruction Set Architecture

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

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Chapter 2: Instructions:

Computer Organization MIPS ISA

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

ECE331: Hardware Organization and Design

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Course Administration

CSE Lecture In Class Example Handout

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Instructions: Language of the Computer

MIPS Functions and Instruction Formats

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

CENG3420 Lecture 03 Review

Lecture 5: Procedure Calls

ECE260: Fundamentals of Computer Engineering

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Thomas Polzer Institut für Technische Informatik

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

ECE 30 Introduction to Computer Engineering

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

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.

Lecture 6: Assembly Programs

Computer Architecture

COMPUTER ORGANIZATION AND DESIGN

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CSE Lecture In Class Example Handout

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

MIPS Functions and the Runtime Stack

We can emit stack-machine-style code for expressions via recursion

CS222: MIPS Instruction Set

MIPS (SPIM) Assembler Syntax

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Functions in MIPS. Functions in MIPS 1

Lectures 3-4: MIPS instructions

Instructions: Assembly Language

CS/COE1541: Introduction to Computer Architecture

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Assembler. Lecture 8 CS301

Chapter 2. Instructions: Language of the Computer

EEC 581 Computer Architecture Lecture 1 Review MIPS

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

CA Compiler Construction

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Instructions: Language of the Computer

Chapter 2. Instruction Set Architecture (ISA)

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Storage in Programs. largest. address. address

CS3350B Computer Architecture

Lecture 5. Announcements: Today: Finish up functions in MIPS

Architecture II. Computer Systems Laboratory Sungkyunkwan University

CS64 Week 5 Lecture 1. Kyle Dewey

Computer Hardware Engineering

CS3350B Computer Architecture MIPS Introduction

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

CS222: Dr. A. Sahu. Indian Institute of Technology Guwahati

MIPS Instruction Set Architecture (2)

Computer Architecture

2/16/2018. Procedures, the basic idea. MIPS Procedure convention. Example: compute multiplication. Re-write it as a MIPS procedure

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Instruction Set Architectures (4)

Machine Instructions - II. Hwansoo Han

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Computer Organization and Design

Instruction Set Architectures Part I: From C to MIPS. Readings:

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

MIPS Instruction Set

CS 110 Computer Architecture MIPS Instruction Formats

Lecture 4: MIPS Instruction Set

Today. Putting it all together

CSCE 5610: Computer Architecture

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

CS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Transcription:

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 E-mail: karanth@ohio.edu Website: http://oucsace.cs.ohiou.edu/~avinashk/classes/ee461a/ee461a.htm Course Administration Homework 2 posted, please see class webpage for deadlines All assignment work to be done individually, NO COLLABORATION is allowed No classes on 9/19 and 9/21 next lecture posted. Read on your own. Review/Quiz on Mon 9/24 1

Converting Function Calls in Assembly Need to pass parameters to the called function Need to save return address of caller Need to save register values Need to get return values Restore register values Instructions for Accessing Procedures MIPS Procedure Call instruction jal Procedure Address # Jump and Link Saves PC+4 in register $ra to have a link to the next instruction for the procedure return Machine Format (J Format) op 26-bit address Then do a procedure return with a return $ra #return Instruction format (R Format) op rs funct 2

How to use Stack? PUSH: First decrement the stack pointer, and then store value POP: For reverse, first load the value, and then increment Assume $s0=000002 needs to be saved onto stack $sp PUSH: subi $sp, $sp, 4 sw $s0, 0($sp) $sp 0x02 0x103 0x102 0x101 0x100 0x23 0xFF 0xDB 0x2A 0x103 0x102 0x101 0x100 POP: lw $s0, 0($sp) addi $sp, $sp, 4 $sp 0x02 0x103 0x102 0x101 0x100 Leaf Procedure Example C code: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; Arguments g,, j in $a0,, $a3 f in $s0 (hence, need to save $s0 on stack) Result in $v0 3

Leaf Procedure Example MIPS code: leaf_example: addi $sp, $sp, -4 sw $s0, 0($sp) add $t0, $a0, $a1 add $t1, $a2, $a3 sub $s0, $t0, $t1 add $v0, $s0, $zero lw $s0, 0($sp) addi $sp, $sp, 4 jr $ra Save $s0 on stack Procedure body Result Restore $s0 Return Call Stack MIPS conventions (and most other processors) allocate a region of memory called the call stack Parameters (that were not passed through registers) Local variables Temporary storage (run out of registers and need to save a value) Return address Sections of the memory on the call stack (stack frames) are allocated when you make a function call, and de-allocated when you return from a function 4

MIPS Stack Frame $ FP Incoming Parameters $ FP Stack Return Address $ SP Spilled Registers Heap Local Variables Static $ SP Outgoing Parameters Text Allocating Space to Local Variables Local variables (by default) are created when you enter a function and disappear when you leave How does the allocation take place? By incrementing and decrementing the stack pointer subi $sp, $sp, 12 \\ allocate space for 3 integer locals addi $sp, $sp, 12 \\ de-allocate space for locals 5

The stack grows as functions are called void time { int x, y[2]; bar(x); void bar(int x) { int a[3]; printf(); Inside time s stack frame time s stack frame time calls bar time s stack frame bar s stack frame bar calls printf time s stack frame bar s stack frame printf s stack frame The stack shrinks as function returns void time { int x, y[2]; bar(x); void bar(int x) { int a[3]; printf(); bar returns time s stack frame printf returns time s stack frame bar s stack frame 6

Stack Frame Content void time { int x, y[2]; bar(x); void bar(int x) { int a[3]; printf(); inside time time s stack frame return address to main x y[0] y[1] spilled registers in time x Return addr to time a[0] a[1] a[2] Spilled registers in bar return addr to bar printf local vars inside bar bar s stack frame Call Stacks with Recursion Each instance of the recursive function is given its own stack frame Local variables in function are private to a particular invocation Each has its own return address, spill space Global and static variables are shared there is 1 copy for all calls 7

Recursion Example main { bar(2); void bar(int a) { int x, y[2]; if( a > 0 ) bar(a 1 ); main calls bar return address to 2 return addr to main x, y[0], y[1] spilled registers in bar bar calls bar return address to 2 return addr to main x, y[0], y[1] spilled registers in bar 1 return addr to bar x, y[0], y[1] Spilled registers in bar Saving Registers during a call What happens to the values we have in registers when we have a function call? Options You can save registers before you make the function call and restore the registers when you return (caller-save register) You can save your registers after you make the function call and restore the registers before you return (callee-save register). Caller saved are $t0 - $t7 (temporary) and callee saved are $s0 - $s7 (saved) 8

Review of MIPS Operand Addressing Modes Register addressing operand is in a register op rs rt rd funct Register word operand Base (displacement) addressing operand is at the memory location whose address is the sum of a register and a 16-bit constant contained within the instruction op rs rt offset Memory base register Register relative (indirect) with Pseudo-direct with 0($a0) addr($zero) Immediate addressing operand is a 16-bit constant contained within the instruction op rs rt operand word or byte operand Review of MIPS Instruction Addressing Modes PC-relative addressing instruction address is the sum of the PC and a 16-bit constant contained within the instruction op rs rt offset Program Counter (PC) Memory branch destination instruction Pseudo-direct addressing instruction address is the 26-bit constant contained within the instruction concatenated with the upper 4 bits of the PC op jump address Memory jump destination instruction Program Counter (PC) 9

MIPS (RISC) Design Principles Simplicity favors regularity fixed size instruction 32 bits small number of instruction formats opcode always the first 6 bits Good design demands good compromises three instruction format Smaller is faster limited instruction set limited number of registers in register file limited number of addressing modes Make the common case fast arithmetic operands from the register file (load-store machine) allow instructions to contain immediate operands 10