Review Session 1 Fri. Jan 19, 2:15 pm 3:05 pm Thornton 102

Similar documents
MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

QtSPIM and MARS : MIPS Simulators

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

SPIM Instruction Set

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

MIPS Functions and Instruction Formats

MIPS Processor Overview

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

Assignment 1: Pipelining Implementation at SPIM Simulator

Course Administration

Assembler. Lecture 8 CS301

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

Instruction Set Architecture

ECE 250 / CS 250 Computer Architecture. Procedures

ECE 15B COMPUTER ORGANIZATION

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

EECS 322 The SPIM simulator

Computer Systems and Architecture

MIPS%Assembly% E155%

CPSC 330 Computer Organization

MIPS Assembly (Functions)

CS 110 Computer Architecture MIPS Instruction Formats

COMP2421 COMPUTER ORGANZATION. Lab 3

MIPS Procedure Calls. Lecture 6 CS301

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

ECE 30 Introduction to Computer Engineering

Chapter 2A Instructions: Language of the Computer

Going From C to MIPS Assembly. Getting Started

SPIM & MIPS Programming

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

CS3350B Computer Architecture MIPS Introduction

MIPS function continued

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

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

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

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

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

CS64 Week 5 Lecture 1. Kyle Dewey

CS 61c: Great Ideas in Computer Architecture

Lecture 5: Procedure Calls

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

MIPS Functions and the Runtime Stack

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Instructions: Language of the Computer

EE 361 University of Hawaii Fall

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

MIPS Assembly Language Programming

CS61C : Machine Structures

Lecture 5: Procedure Calls

Lecture 7: Examples, MARS, Arithmetic

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

COMPUTER ORGANIZATION AND DESIGN

CENG3420 Computer Organization and Design Lab 1-2: System calls and recursions

MIPS Assembly Language Programming

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

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

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

Solutions for Chapter 2 Exercises

MIPS (SPIM) Assembler Syntax

Control Instructions

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

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

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number

Instruction Set Architectures (4)

CSE Lecture In Class Example Handout

MIPS Assembly Language Guide

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

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.

Machine Instructions - II. Hwansoo Han

CENG3420 Lecture 03 Review

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Assembler. #13 Running a Program II

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

Function Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10

MIPS Assembly Language. Today s Lecture

CENG3420 Lab 1-1: MIPS assembly language programing

Function Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Instructions: Language of the Computer

MIPS Architecture and Assembly Language Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

CS3350B Computer Architecture

Course Administration

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

MIPS Instruction Set Architecture (2)

CSE Lecture In Class Example Handout

ECE 30 Introduction to Computer Engineering

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

CS153: Compilers Lecture 8: Compiling Calls

CS3350B Computer Architecture MIPS Procedures and Compilation

Computer Architecture. The Language of the Machine

MIPS Reference Guide

CS 61C: Great Ideas in Computer Architecture (Machine Structures) More MIPS Machine Language

ECE369. Chapter 2 ECE369

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

Transcription:

Review Session 1 Fri. Jan 19, 2:15 pm 3:05 pm Thornton 102 1. Agenda Announcements Homework hints MIPS instruction set Some PA1 thoughts MIPS procedure call convention and example 1 2. Announcements Homework 1 (can work in groups of 2): Due date extended to 5 pm on Thursday, January 25. The TA email list is ee108b-win0607-tas@lists.stanford.edu PA 1 (individual): Assigned: yesterday Due 11:59pm on Thursday, February 8, you have 3 weeks. Lab 1 (groups of 2): Due: Tuesday, January 30, you have 12 days. Office hours: Drew: Tuesdays 1pm 3pm in P129 Yi: Tuesdays 3pm 5pm P129 Access to P128 (computer cluster) and P129. Email the TA list for login info. 2

3. Homework hints Problem 1: Part b: you can assume all 5000 elements are unequal. Part c: Total Execution Time = (total clk cyc.)/(clk cyc. rate) Part d: How does new instruction change the inner loop? Reduces instruction count, but cycle time has increased Problem 2: Go line by line of the C code and translate into assembly. Tail recursion. 3 Problem 3: Similar to problem 1. No more than 5 bugs. Problem 4: Pseudo instructions. Small has 16 bits and Big has 32 bits Break big numbers into upper and lower halves You may use the notation upper(big) and lower(big) to extract a portion of a big number. Please consult the bulletin board first for homework questions, email to the TA list if your question is not already answered. 4

4. MIPS instruction set R type instruction for arithmetic and logical operations. The fields are op, rs, rt, rd, shamt, funct I type instruction for operations involving immediates up to 16 bits wide. Load, store and branches are formatted as I type. J type instructions for jumping. green card or pages 77 and 78 for a comprehensive listing of MIPS instructions. Important correction to column 1 of green card: Shift Left Logicalsll R R[rd]=R[rt]<<shamt Shift Right Logicalsrl R R[rd]=R[rt]>>shamt 5 5. PA1 Thoughts Do the job of a compiler. Do not use tail recursion. Do use the Partition keyword. Know the procedure call conventions well. Use display command, xspim or pcspim to debug your code. 6

6. MIPS procedure call convention Call convention summary (please follow this guideline when you do MIPS assembly coding for homeworks, PAs and in exams): 7 Example: a recursive program that evaluates factorial 10. main () { printf ("The factorial of 10 is %d\n", fact (10)); } int fact (int n) { if (n < 1) return (1); else return (n * fact (n - 1)); } 8

.text # Indicate beginning of program.globl main # main can be referenced from other files main: subu $sp, $sp,32 # Stack frame is 32 bytes long sw $ra, 20($sp) # Save return address sw $fp, 16($sp) # Save old frame pointer addiu $fp, $sp,28 # Set up frame pointer li $a0, 10 # Put argument (10) in $a0 jal fact # Call factorial function la $a0, $LC # Load string address in $a0 move $a1, $v0 # Move fact result to $a1 jal printf # Call the print function lw $ra, 20($sp) # Restore return address lw $fp, 16($sp) # Restore frame pointer addiu $sp, $sp, 32 # Pop stack frame jr $ra # Return to caller $LC:.rdata # Read-only data \n\ # Store the string in memory, but do not null-terminate it.text fact: subu $sp, $sp, 32 # Stack frame is 32 bytes long sw $ra, 20($sp) # Save return address sw $fp, 16($sp) # Save frame pointer addiu $fp, $sp, 28 # Set up frame pointer sw $a0, 0($fp) # Save argument (n) lw $v0, 0($fp) # Load n bgtz $v0, iterate # Branch if n > 0 li $v0, 1 # Return 1 j pop # Jump to code to return 9 iterate: lw $v1, 0($fp) # Load n subu $v0, $v1, 1 # Compute n - 1 move $a0, $v0 # Move value to $a0 jal fact # Call factorial function lw $v1, 0($fp) # Load n mul $v0, $v0,$v1 # Compute fact(n-1) * n pop: # Result is in $v0 lw $ra, 20($sp) # Restore $ra lw $fp, 16($sp) # Restore $fp addiu $sp, $sp, 32 # Pop stack jr $ra # Return to caller Originally 10

After storing $ra After setting up $fp 11 After saving $fp in fact After saving $a0 in iteration 1 12

After saving $a0 in iteration 2 13 Aside 1: The.text and.globl you see in the assembly code are assembler directives, which are there to tell the assembler how to translate a program but which do not translate to machine instructions. Names followed by a colon, such as str or main, are labels that name the next memory location. Specifically data definitions start with the.data directive, code definition starts with.text directive usually an assembly program would have a main as well as a number of subroutine definitions. 14

Example:.data foo:.word 0 # data memory # 32 bit variable.text # program memory.align 2 # word alignment.globl main # main is global main: lw $a0, foo 15 Aside 2: with the system and do simple I/O. The specific I/O done depends on the value of some registers. Example: str: li $v0, 4 la $a0, str syscall # Declare zero-delimited ascii string # load 4 in $v0 for print_string # syscall # load our string in the syscall # argument register # make the call 16

In this case the system call code is 4 or print_string. Other system calls include: Code 1: print_int with argument $a0 = integer Code 2: print_float with argument $f12 = float Code 3: print_double with argument $f12 = double Code 4: print_string with argument $a0 = string Code 5: read_int with integer result in $v0 Code 6: read_float with float result in $f0 : : The complete listing is available in Appendix A of the textbook (on CD). 17