Graduate Institute of Electronics Engineering, NTU. SPIM and MIPS Asm. Presenter: 沈文中 (TA) Date: 2004/10/13

Size: px
Start display at page:

Download "Graduate Institute of Electronics Engineering, NTU. SPIM and MIPS Asm. Presenter: 沈文中 (TA) Date: 2004/10/13"

Transcription

1 SPIM and MIPS Asm Presenter: 沈文中 (TA) Date: 2004/10/13 ACCESS IC LAB

2 SPIM Introduction Installation Outline Graphic Interface Description Loading and Running a Program Simulator Setting MIPS ASM Assembler Syntax System Calls A Detailed Example page2

3 Introduction A simulator of MIPS R2000/R3000 Computers Developed by James R. Larus, Computer Sciences Department, University of Wisconsin-Madison Multiple versions for Unix, DOS and Windows page3

4 Get Related Files Windows Version Installation -Extract the zipped file to a new folder -Execute setup.exeand follow the installation procedure page4

5 Graphic Interface Description Menu bar File operations Simulator settings Windows views online Help information Register window Text Segment window Data Segment window Message window Console window page5

6 Registers Text Segment DataSegment Messages

7

8 Loading and Runing a Program Load: Run: Trace: Restart: File->Open (*.s) Simulator->Go Control-C Simulator->Continue/Break Simulator->Single Step/Multiple Step Simulator->Breakpoints Simulator->Clear Registers/Reinitialize Simulator->Reload page8

9 Simulator Setting page9

10 Assembler Syntax Comments: begin with a sharp-sign () Identifiers: a sequence of alphanumeric characters, underbars(_), and dots(.) that do not begin with a number Reserved words: opcodes for instructions Labels: at the beginning of a line followed by a colon (:) String are enclosed in double-quotes (") Special characters in strings follow the C convention (\n, \t, \") page10

11 Assembler Directives.text <addr>: the next items are put in the user text segment.data <addr>: data segment.align n: align the next datum on a 2 n byte boundary.byte b1,, bn: store the n values in successive bytes.half h1,, hn: 16-bit quantities (2 bytes).word w1,, wn: 32-bit quantities (4 bytes).float f1,.., fn: single precision numbers.double d1,, dn: double precision numbers page11

12 Assembler Directives.ascii str: store the string in memory.asciiz str: with null.space n: allocate n bytes of space.globl sym: declare that symbol sym is global page12

13 SPIM for Windows Examples page13

14 add.s addition of an array.text.align 2.globlmain main: lw $a0, Size read the size of array li $a1, 0 index i li $a2, 0 a2 contains the sum li $t2, 4 t2 contains constant 4 loop: mul $t1, $a1, $t2 t1 gets i*4 lw $a3, Nstart($t1) a3 = N[i] add $a2, $a2, $a3 sum = sum + N[i] add $a1, $a1, 1 i = i + 1 beq $a1, $a0, STOR go to STOR if finished j loop STOR: sw $a2, Result store sum at Result.data.align 2 Nstart:.word 8, 25, -5, 55, 33, 12, -78 Size:.word 7 Result:.word 0

15 Text Segment ========================= [0x ] 0x3c lui $1, 4097 [Size] ; 11: lw $a0, Size read the size of array [0x ] 0x8c24001c lw $4, 28($1) [Size] [0x ] 0x ori $5, $0, 0 ; 12: li $a1, 0 index i [0x c] 0x ori $6, $0, 0 ; 13: li $a2, 0 a2 contains the sum [0x ] 0x340a0004 ori $10, $0, 4 ; 14: li $t2, 4 t2 contains constant 4 [0x ] 0x00aa0018 mult $5, $10 ; 16: mul $t1, $a1, $t2 [0x ] 0x mflo $9 [0x c] 0x3c lui $1, 4097 [Nstart] ; 17: lw $a3, Nstart($t1) [0x ] 0x addu $1, $1, $9 [0x ] 0x8c lw $7, 0($1) [Nstart] [0x ] 0x00c73020 add $6, $6, $7 ; 18: add $a2, $a2, $a3 [0x c] 0x20a50001 addi $5, $5, 1 ; 19: add $a1, $a1, 1 i = i + 1 [0x ] 0x10a40002 beq $5, $4, 8 [STOR-0x ] ; 20: beq $a1, $a0, STOR [0x ] 0x j 0x [loop] ; 21: j loop [0x ] 0x3c lui $1, 4097 [Result] ; 23: sw $a2, Result store sum at Result [0x c] 0xac sw $6, 32($1) [Result]

16 Data Segment ========================= DATA [0x ]...[0x1000fffc] [0x1000fffc] [0x ] [0x ] [0x ]...[0x ] STACK [0x7fffeffc] KERNEL DATA [0x ]...[0x ] 0x x x x xfffffffb 0x x x c 0xffffffb2 0x x x x

17

18 System Calls Service Code Arguments Result print_int 1 $a0=integer print_float 2 $f12=float print_double 3 $f12=double print_string 4 $a0=string read_int 5 integer (in $v0) read_float 6 float (in $f0) read_double 7 double (in $f0) read_string 8 $a0=buffer, $a1=length sbrk 9 $a0=amount address (in $v0) exit 10 System calls:loads the system call code into register $v0 exit: stops a program page18

19 How to print and read in a string.data str1: str2:.asciiz"please type a string with lenght19\n".asciiz"this string is that you input\n".text.align 2.globlmain 本文區段 main 為全域變數 main: li $v0, 4 print_string 的系統呼叫程式碼 la $a0, str1 要列印字串的位置在 str1 syscall 印出字串

20 li $v0, 8 read_string 的系統呼叫程式碼 li $a1, 20 可讀入的字串長度 19 syscall string 的起始位置為暫存器 $a0 addi$t0, $a0, 0 把暫存器 $a0 拷貝至暫存器 $t0 li $v0, 4 print_string 的系統呼叫程式碼 la $a0, str2 要列印字串的位置在 str2 syscall 印出字串 li $v0, 4 addi$a0, $t0, 0 把暫存器 $t0 拷貝至暫存器 $a0 syscall

21 Segment Data segment ASM Architecture Stack, int, string, float, Code segment Label: called by jump, loop Macro (function ): begin with.macro; end with.endmacro page21

22 ========================================================== Static data allocation and initialization ==========================================================.data PLACE OVERALL COMMENTS FOR DATA DESCLARATIONS HERE REPLACE MYDATA1 and MYDATA2 with your data declarations MYDATA1 : PLACE COMMENTS SPECIFIC TO MYDATA1 HERE MYDATA2 : PLACE COMMENTS SPECIFIC TO MYDATA2 HERE ========================================================== Macro definition area ========================================================== ========================================================== Macro : print_int Inplicit argument : an integer in $a0 Side-effect : modifies $v0.macro print_int li $v0,1 syscall.endmacro Example program page22

23 ========================================================== Macro : print_string Implicit argument : Address of a null terminated string in $a0 Side-effect : modifies $v0.macro print_string li $v0, 4 syscall.endmacro ADDITIONAL MACROS GO HERE ========================================================== Constants ==========================================================.define fp_off -4.define ra_off 0 ADDITIONAL CONSTANTS GO HERE ========================================================== Program text ==========================================================.text.global main page23

24 main : Main program entry move $t0, $fp keep track of old fp move $fp, $sp old sp in base of stack frame sw $ra, ra_off($fp) save return add. 1st thing in the frame sw $t0, fp_off($fp) save old fp on frame subu $sp, $sp, 8 move sp to new position in frame Main body PLACE INSTRUCTIONS FOR MAIN BODY HERE main exit lw $t0, fp_off($fp) restore fp lw $ra, ra_off($fp) and ra move $sp, $fp restore stack pointer move $fp, $t0 and frame pointer j $ra return ========================================================== page24

25 PLACE DESCRIPTIVE PROLOGUE FOR PROCEDURE IN COMMENTS BELOW Procedure : Description : Parameters : Locals : Returns : LABEL1 : procedure entry PLACE INSTRUCTIONS FOR PROCEDURE ENTRY HERE procedure body PLACE INSTRUCTIONS FOR PROCEDURE BODY HERE procedure exit PLACE INSTRUCTIONS FOR PROCEDURE EXIT HERE ADDITIONAL PROCEDURES GO HERE.end main page25

26 ========================================================== Static data allocation and initialization ==========================================================.data String for output output :.ascliz factorial of five is newline :.ascliz \n ========================================================== Macro definition area ========================================================== ========================================================== Macro : print_int Inplicit argument : an integer in $a0 Side-effect : modifies $v0.macro print_int li $v0,1 syscall.endmacro page26

27 ========================================================== Macro : print_string Implicit argument : Address of a null terminated string in $a0 Side-effect : modifies $v0.macro print_string li $v0, 4 syscall.endmacro ========================================================== Macro : push on stack Argument : what to put on stack Side-effect : modifies $sp.macro push(operand) sw operand, 0($sp) addu $sp, $sp, -4.endmacro ========================================================== Macro : pop from stack Argument : where to pop Side-effect : modifies $sp page27

28 .macro push(operand) addu $sp, $sp, 4 lw operand, 0($sp).endmacro ========================================================== Constants ==========================================================.define fp_off -4.define ra_off 0 ========================================================== Program text ==========================================================.text.global main main : Main program entry move $t0, $fp keep track of old fp move $fp, $sp old sp in base of stack frame sw $ra, ra_off($fp) save return add. 1st thing in the frame sw $t0, fp_off($fp) save old fp on frame subu $sp, $sp, 8 move sp to new position in frame page28

29 Main body li $a0, 5 will compute factorial of 5 jal fact move $s0, $v0 save result la $a0, output prepare to print print_string header la $a0, newline print_string move $a0, $s0 prepare to print print_int print factorial main exit lw $t0, fp_off($fp) restore fp lw $ra, ra_off($fp) and ra move $sp, $fp restore stack pointer move $fp, $t0 and frame pointer j $ra return ========================================================== page29

30 PROCEDURE : Fact DESCRIPTION : an integer in a0 LOCALS : RETURN : fact (a0) in v0 DESCRIPTION : Computes recursively factorial fact : Procedure entry move $t0, $fp keep track of old fp move $fp, $sp old sp in base of stack frame sw $ra, ra_off($fp) save return add. 1st thing in the frame sw $t0, fp_off($fp) save old fp on frame subu $sp, $sp, 8 move sp to new position in frame Procedure body test argument for 0; if so return with value 1 beq $a0, $0,nore test a0; if zero goto out otherwise save a0 on the stack push ($a0) a0 saved addi $a0, $a0, -1 decrement argument page30

31 recursive entry jal fact call back from recursive level v0 = v0 * a0 pop ($t0) pop previous argument mul $v0, $v0, $t0 get result at this level b out exit that level end of recursion nore: li $v0,1 result in v0 and exit regs, perform alu Procedure exit out: lw $t0, fp_off($fp) restore fp lw $ra, ra_off($fp) and ra move $sp, $fp restore stack pointer move $fp, $t0 and frame pointer j $ra return page31

32 1. A template for MIPS assembly programs.data Static data declared below, with labels for each data structure (MYDATA1,MYDATA2) MYDATA1: data storage directive such as.word,.space, etc. MYDATA2: another data storage directive.text Make main visible to other files.globl main Assembly instructions go here, with labels for procedures and branch targets (main, Sum, LABEL1): page32

33 1. A template for MIPS assembly programs main : NOP NOP LABEL1: NOP NOP first instruction of main a branch target j $ra last instruction of main Instructions for additional procedures go here. A descriptive prologue is a good idea. For example: PROCEDURE: Sum PARAMETERS: int * numbers (a0) Address of an array of integers int count (a1) Length of the array page33

34 1. A template for MIPS assembly programs LOCALS: i (t0) Loop index RETURNS: sum (v0) DESCRIPTION: Compute the sum of numbers[0].. Numbers[count], and return the result. Sum: NOP first instruction of procedure Sum j $ra last instruction of procedure Sum page34

35 2. Assembler directives Assembler directives do not generate instructions, but instead provide additional information to the assembler on how to arrange code and data in memory, how to interpret macros, and so on. Directives such as.text and.data are present in even the simplest programs. Other more interesting directives are described below: 2.1 Data allocation and initialization Most of the directives are to instruct the program on how to allocate space for and initialize static variables. These always appear in the data segment after the.data directive but before the.text directive. You ll probably use the following frequently: Allocate space for and initialize a null-terminated ascii string:.asciiz This is an ascii string.\n Allocate and initialize an array of 5 bytes:.byte 0x00 0x01 0x02 0x03 0x04 Allocate and initialize an array of 2 32-bit words:.word 0x x Allocate an unitialized area of 100 byts (25 32-bit words).space 100 Additional directives are described in pages A-51~A-53 of the text. page35

36 2. Assembler directives 2.2 Macros Suppose you found yourself frequently using the pop and push operations described in class. Rather than having to type in two instructions every time you wanted to push a register onto the stack or pop a value from the stack into a register, it would be nice if the assembler provided primitives to do it for you. The assembler doesn t, but it allows you to create your own, with macros. For example, at the beginning of the assembler program, you could add the lines.macro push ($operand) sw $operand, 0($sp) addu $sp, $sp, -4.end_macro page36

37 2. Assembler directives.macro pop ($operand) addu $sp, $sp, 4 lw $operand, 0($sp).end_macro Now in your program you can use the newly defined macro to push, for example, register $a0 onto the stack: push($a0) The assembler uses your macro definition to expand this to sw $a0, 0($sp) addu $sp, $sp, -4 In general macros are useful when you find yourself in repetitive sequences of instructions. They are not a substitute for procedures, though. (Why not?) page37

38 3. Printing to the console To test your program, you ll need some way of displaying your output in a humanreadable format. SPIM provides several system calls for printing to the console. syscall : is effectively a special procedure call with an unusual calling convention. Before using the syscall instruction, register $2 must contain the syscall number; for now we re only interested in syscall 1 (print_int) and syscall 4 (print_string). (More syscalls can be found on page A-49 of the text.) For these two syscalls, register $4 should contains the integer value or the address of the string to be printed. So in this example it takes three syscalls to print out the result string. For your convenience, we have defined macros for these two printing syscalls within the template..data str:.asciiz The sum from is newline:.asciiz \n page38

39 3. Printing to the console li $2, 4 Use syscall 4 (print_string) la $4, str to display string str syscall li $2, 1 Use syscall 1 (print_int) lw $4, 4($sp) to print the sum syscall li $2, 4 Use syscall 4 (print_string) la $4, newline to print a newline syscall page39

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

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn MIPS and QTSPIM Recap Cptr280 Dr Curtis Nelson MIPS Architecture The MIPS architecture is considered to be a typical RISC architecture Simplified instruction set Programmable storage 32 x 32-bit General

More information

QtSPIM and MARS : MIPS Simulators

QtSPIM and MARS : MIPS Simulators QtSPIM and MARS : MIPS Simulators Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going

More information

MIPS Processor Overview

MIPS Processor Overview MIPS Processor Cptr280 Dr Curtis Nelson MIPS Processor Overview Hardware Design philosophy Architecture Software Assembly language program structure QTSpim simulator Example programs 1 MIPS Processor Power

More information

COMP2421 COMPUTER ORGANZATION. Lab 3

COMP2421 COMPUTER ORGANZATION. Lab 3 Lab 3 Objectives: This lab shows you some basic techniques and syntax to write a MIPS program. Syntax includes system calls, load address instruction, load integer instruction, and arithmetic instructions

More information

Assignment 1: Pipelining Implementation at SPIM Simulator

Assignment 1: Pipelining Implementation at SPIM Simulator Assignment 1: Pipelining Implementation at SPIM Simulator Due date: 11/26 23:59 Submission: icampus (Report, Source Code) SPIM is a MIPS processor simulator, designed to run assembly language code for

More information

MIPS Architecture and Assembly Language Overview

MIPS Architecture and Assembly Language Overview MIPS Architecture and Assembly Language Overview Adapted from: http://edge.mcs.dre.g.el.edu/gicl/people/sevy/architecture/mipsref(spim).html [Register Description] [I/O Description] Data Types and Literals

More information

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture Stephen Pauwels MIPS: Introduction Academic Year 2018-2019 Outline MIPS Registers and Memory Language Constructs Exercises Assembly Language Very closely related to machine

More information

MIPS Procedure Calls. Lecture 6 CS301

MIPS Procedure Calls. Lecture 6 CS301 MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place

More information

SPIM Instruction Set

SPIM Instruction Set SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

More information

EECS 322 The SPIM simulator

EECS 322 The SPIM simulator EECS 322 The SPIM simulator Instructor: Francis G. Wolff wolff@eecs.cwru.edu Case Western Reserve University This presentation uses powerpoint animation: please CWRU EECS viewshow 322 February 12, 2001

More information

CENG3420 Lab 1-1: MIPS assembly language programing

CENG3420 Lab 1-1: MIPS assembly language programing CENG3420 Lab 1-1: MIPS assembly language programing Haoyu YANG Department of Computer Science and Engineering The Chinese University of Hong Kong hyyang@cse.cuhk.edu.hk 2017 Spring 1 / 18 Overview SPIM

More information

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

Review Session 1 Fri. Jan 19, 2:15 pm 3:05 pm Thornton 102 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

More information

MIPS function continued

MIPS function continued MIPS function continued Review Functions Series of related instructions one after another in memory Called through the jal instruction Pointed to by a label like any other Returns by calling Stack Top

More information

SPIM & MIPS Programming

SPIM & MIPS Programming Computer Organization and Structure 2012 SPIM & MIPS Programming Department of Information Management National Taiwan University Outline Introduction to Assembly Language SPIM Getting Started MIPS Assembly

More information

MIPS Assembly Language Programming

MIPS Assembly Language Programming MIPS Assembly Language Programming ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted

More information

We will study the MIPS assembly language as an exemplar of the concept.

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

Course Administration

Course Administration Fall 2017 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 3/4 Avinash Kodi Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701

More information

SPIM S20: A MIPS R2000 Simulator

SPIM S20: A MIPS R2000 Simulator SPIM S20: A MIPS R2000 Simulator 1 th 25 the performance at none of the cost James R Larus larus@cswiscedu Computer Sciences Department University of Wisconsin Madison 1210 West Dayton Street Madison,

More information

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

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points) ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points) Objectives: Get familiar with MIPS instructions Assemble, execute and debug MIPS

More information

MIPS Assembly Language. Today s Lecture

MIPS Assembly Language. Today s Lecture MIPS Assembly Language Computer Science 104 Lecture 6 Homework #2 Midterm I Feb 22 (in class closed book) Outline Assembly Programming Reading Chapter 2, Appendix B Today s Lecture 2 Review: A Program

More information

MIPS Assembly Language Programming

MIPS Assembly Language Programming MIPS Assembly Language Programming COE 308 Computer Architecture Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline Assembly

More information

MIPS Assembly Language Guide

MIPS Assembly Language Guide MIPS Assembly Language Guide MIPS is an example of a Reduced Instruction Set Computer (RISC) which was designed for easy instruction pipelining. MIPS has a Load/Store architecture since all instructions

More information

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

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

More information

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

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture The Instructions 1 1 Topics: Assembly language, assemblers MIPS R2000 Assembly language Instruction set

More information

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.

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. CSC258 Week 10 Logistics 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. Quiz review A word-addressable RAM

More information

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

More information

MIPS (SPIM) Assembler Syntax

MIPS (SPIM) Assembler Syntax MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

More information

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

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: MIPS Programming We spent some time looking at the MIPS Instruction Set Architecture. We will now consider

More information

ECE 250 / CS 250 Computer Architecture. Procedures

ECE 250 / CS 250 Computer Architecture. Procedures ECE 250 / CS 250 Computer Architecture Procedures Benjamin Lee Slides based on those from Alvin Lebeck, Daniel Sorin, Andrew Hilton, Amir Roth, Gershon Kedem Today s Lecture Admin HW #2 is up, due Sunday

More information

ECE 30 Introduction to Computer Engineering

ECE 30 Introduction to Computer Engineering ECE 30 Introduction to Computer Engineering Study Problems, Set #4 Spring 2015 Note: To properly study and understand the problems below, it is strongly recommended to implement and run your solution (and/or

More information

USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470

USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470 USING A SIMULATOR QUICK INTRODUCTION From various sources For cs470 INTRODUCTION MARS INTERFACE SIMULATOR USAGE MIPS ASSEMBLER LANGUAGE PROGRAM EXAMPLE Introduction MARS IDE A simulator for the MIPS processor

More information

MIPS Assembly (Functions)

MIPS Assembly (Functions) ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly (Functions) 2 Lab Schedule This Week Activities Lab work time MIPS functions MIPS Random Number Generator Lab 11 Assignments Due Due by Apr

More information

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

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures Review (1/2) CS61C - Machine Structures Lecture 11 - Starting a Program October 4, 2000 David Patterson http://www-inst.eecs.berkeley.edu/~cs61c/ IEEE 754 Floating Point Standard: Kahan pack as much in

More information

CPSC 330 Computer Organization

CPSC 330 Computer Organization CPSC 330 Computer Organization Chapter 2-II Instructions: Language of the computer MIPS Instructions - Review Instruction Meaning add $s1,$s2,$s3 $s1 = $s2 + $s3 sub $s1,$s2,$s3 $s1 = $s2 $s3 addi $s1,$s1,4

More information

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved. MIPS Coding Snippets Prof. James L. Frankel Harvard University Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved. Loading a 32-bit constant into a register # Example loading

More information

SPIM & MIPS Programming

SPIM & MIPS Programming Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 3010: Computer Architecture Discussion Lecture # 1 SPIM & MIPS Programming Eng. Eman R. Habib September, 2013 2 Computer

More information

MIPS Functions and the Runtime Stack

MIPS Functions and the Runtime Stack MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline

More information

Lab 4 : MIPS Function Calls

Lab 4 : MIPS Function Calls Lab 4 : MIPS Function Calls Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The objective of this lab

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming Remember the programmer shown in our first lecture? Originally, computers were programmed manually. After a while, scientists began to consider ways to accelerate and facilitate

More information

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

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization CSE2021 Computer Organization Chapter 2: Part 2 Procedure Calling Procedure (function) performs a specific task and return results to caller. Supporting Procedures Procedure Calling Calling program place

More information

MIPS Assembly Language

MIPS Assembly Language MIPS Assembly Language Chapter 15 S. Dandamudi Outline MIPS architecture Registers Addressing modes MIPS instruction set Instruction format Data transfer instructions Arithmetic instructions Logical/shift/rotate/compare

More information

MIPS Assembly Language

MIPS Assembly Language MIPS Assembly Language Prof. James L. Frankel Harvard University Version of 3:17 PM 1-May-2018 Copyright 2018, 2015 James L. Frankel. All rights reserved. Assembler Input The assembly language file should

More information

Compiling Techniques

Compiling Techniques Lecture 10: An Introduction to MIPS assembly 18 October 2016 Table of contents 1 Overview 2 3 Assembly program template.data Data segment: constant and variable definitions go here (including statically

More information

Going From C to MIPS Assembly. Getting Started

Going From C to MIPS Assembly. Getting Started Going From C to MIPS Assembly Getting Started Charles Gordon (version 1.1, September 2000) Contents 1 Downloading and Installing SPIM 1 1.1 Where to get SPIM. 1 1.2 Installing SPIM... 1 1.3 Running SPIM

More information

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei Computer Architecture Instruction Set Architecture part 2 Mehran Rezaei Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a MIPS Interpreter

More information

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Overview Last Lecture s Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a

More information

Lecture 7: Examples, MARS, Arithmetic

Lecture 7: Examples, MARS, Arithmetic Lecture 7: Examples, MARS, Arithmetic Today s topics: More examples MARS intro Numerical representations 1 Dealing with Characters Instructions are also provided to deal with byte-sized and half-word quantities:

More information

MIPS Assembly Programming

MIPS Assembly Programming COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

More information

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 17 Executing Programs: Compiling, Assembling, Linking and Loading (Part II) Project #3 Due June 10, 5pm Announcements Submit via email Homework #4 Due June 5, 5pm

More information

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

2/16/2018. Procedures, the basic idea. MIPS Procedure convention. Example: compute multiplication. Re-write it as a MIPS procedure Procedures, the basic idea CSCI206 - Computer Organization & Programming Introduction to Procedures zybook: 81 (for next class) MIPS Procedure convention 1 Prepare parameters in $a0 through $a3 2 Return

More information

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7 MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline Global variables and memory Arrays

More information

SPIM & MIPS. Department of Information and Management. Computer Organization and Structure 年 9 月 29 日星期 一

SPIM & MIPS. Department of Information and Management. Computer Organization and Structure 年 9 月 29 日星期 一 SPIM & MIPS Department of Information and Management Computer Organization and Structure 2013 Chi-Chi Liao 廖以圻 chichi@cmlab.csie.ntu.edu.tw TAs Chi-Chi Andi Outline Introduction to Assembly Language SPIM-Getting

More information

Course Administration

Course Administration 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

More information

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f CS2 Fall 28 Exam 2 Name: ) The Logisim TinyProc2 has four instructions, each using 8 bits. The instruction format is DR SR SR2 OpCode with OpCodes of for add, for subtract, and for multiply. Load Immediate

More information

Procedure Call and Return Procedure call

Procedure Call and Return Procedure call Procedures int len(char *s) { for (int l=0; *s!= \0 ; s++) l++; main return l; } void reverse(char *s, char *r) { char *p, *t; int l = len(s); reverse(s,r) N/A *(r+l) = \0 ; reverse l--; for (p=s+l t=r;

More information

Lecture 7: Procedures

Lecture 7: Procedures Lecture 7: Procedures CSE 30: Computer Organization and Systems Programming Winter 2010 Rajesh Gupta / Ryan Kastner Dept. of Computer Science and Engineering University of California, San Diego Outline

More information

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

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 Do-While Example In C++ do { z--; while (a == b); z = b; In assembly language loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero 25 Comparisons Set on less than (slt) compares its source registers

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #8: MIPS Procedures 2005-06-30 CS 61C L08 MIPS Procedures (1) Andy Carle Topic Outline Functions More Logical Operations CS 61C L08

More information

Chapter 2. Instructions:

Chapter 2. Instructions: Chapter 2 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions We ll be working with

More information

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

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015 Branch Addressing Branch instructions specify Opcode, two registers, target address Most branch targets are near branch Forward or backward op rs rt constant or address 6 bits 5 bits 5 bits 16 bits PC-relative

More information

Assembler. Lecture 8 CS301

Assembler. Lecture 8 CS301 Assembler Lecture 8 CS301 Discussion Given the following function header, int foo(int a, int b); what will be on the stack before any of the calculations in foo are performed? Assume foo() calls some other

More information

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

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0

More information

Chapter 3. Instructions:

Chapter 3. Instructions: Chapter 3 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions We ll be working with

More information

4.2: MIPS function calls

4.2: MIPS function calls 4.2: MIPS function calls Topics: Nested function calls: poly() and pow() Saving the return address ($31) Saving temporary registers Looking at activation records on the stack Introduction: In CSc 256 lectures,

More information

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address. The MIPS Register Set The MIPS R2000 CPU has 32 registers. 31 of these are general-purpose registers that can be used in any of the instructions. The last one, denoted register zero, is defined to contain

More information

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

We can emit stack-machine-style code for expressions via recursion Code Generation The Main Idea of Today s Lecture We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

More information

ECE 30 Introduction to Computer Engineering

ECE 30 Introduction to Computer Engineering ECE 30 Introduction to Computer Engineering Study Problems, Set #3 Spring 2015 Use the MIPS assembly instructions listed below to solve the following problems. arithmetic add add sub subtract addi add

More information

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

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information

MIPS Functions and Instruction Formats

MIPS Functions and Instruction Formats MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other

More information

EN164: Design of Computing Systems Lecture 11: Processor / ISA 4

EN164: Design of Computing Systems Lecture 11: Processor / ISA 4 EN164: Design of Computing Systems Lecture 11: Processor / ISA 4 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University

More information

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

The plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside

More information

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE 1 ARCHITECTURE MODEL The basic instruction set of a computer is comprised of sequences of REGISTER TRANSFERS. Example: Add A, B, C Register B # A

More information

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

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Procedure Calls A procedure of a subroutine is like an agent which needs certain information to perform a

More information

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 C functions main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } What information must compiler/programmer keep

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS Procedures I Sr Lecturer SOE Dan Garcia 2014-02-14 If cars broadcast their speeds to other vehicles (and the

More information

MIPS Assembly (FuncDons)

MIPS Assembly (FuncDons) ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly (FuncDons) 2 Lab Schedule AcDviDes Monday Discuss: MIPS FuncDons Lab 11 Assignments Due Sunday Apr 14 th Lab 11 due by 11:59pm Wednesday Discuss:

More information

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

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS Lectures 5 Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS 1 OOPS - What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; } 2

More information

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda MIPS ISA and MIPS Assembly CS301 Prof. Szajda Administrative HW #2 due Wednesday (9/11) at 5pm Lab #2 due Friday (9/13) 1:30pm Read Appendix B5, B6, B.9 and Chapter 2.5-2.9 (if you have not already done

More information

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.

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. MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to

More information

EEC 581 Computer Architecture Lecture 1 Review MIPS

EEC 581 Computer Architecture Lecture 1 Review MIPS EEC 581 Computer Architecture Lecture 1 Review MIPS 1 Supercomputing: Suddenly Fancy 2 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control

More information

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

ECE232: Hardware Organization and Design. Computer Organization - Previously covered ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

More information

instructions aligned is little-endian

instructions aligned is little-endian MEMÓRIA Data Types These instructions load and store aligned data: Load word (lw) Load halfword (lh) Load halfword unsigned (lhu) Load byte (lb) Load byte unsigned (lbu) Store word (sw) Store halfword

More information

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

Function Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read Function Calls Tom Kelliher, CS 240 Feb. 13, 2002 1 Administrivia Announcements Collect homework. Assignment Read 3.7 9. From Last Time SPIM lab. Outline 1. Function calls: stack execution model, memory

More information

MIPS Reference Guide

MIPS Reference Guide MIPS Reference Guide Free at PushingButtons.net 2 Table of Contents I. Data Registers 3 II. Instruction Register Formats 4 III. MIPS Instruction Set 5 IV. MIPS Instruction Set (Extended) 6 V. SPIM Programming

More information

COMP2611: Computer Organization MIPS function and recursion

COMP2611: Computer Organization MIPS function and recursion COMP2611 Fall2015 COMP2611: Computer Organization MIPS function and recursion Overview 2 You will learn the following in this lab: how to use MIPS functions in a program; the concept of recursion; how

More information

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

Lecture 5. Announcements: Today: Finish up functions in MIPS Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In

More information

Instructor: Francis G. Wolff Case Western Reserve University This presentation uses powerpoint animation: please viewshow

Instructor: Francis G. Wolff Case Western Reserve University This presentation uses powerpoint animation: please viewshow EECS 314: Load, Store, Arrays and Pointers C isn't that hard: void (* (*f[ ])( ) )( ) defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void.

More information

MIPS Assembly (FuncDons)

MIPS Assembly (FuncDons) ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly (FuncDons) Instructor: Dr. Vivek Pallipuram 2 Lab Schedule This Week AcDviDes Lab work Dme MIPS funcdons MIPS Random Number Generator Lab 10

More information

Instruction Set Architecture

Instruction Set Architecture Computer Architecture Instruction Set Architecture Lynn Choi Korea University Machine Language Programming language High-level programming languages Procedural languages: C, PASCAL, FORTRAN Object-oriented

More information

Assembler. #13 Running a Program II

Assembler. #13 Running a Program II CS61C L13 Running a Program II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures #13 Running a Program II aka Compiling, Assembling, Linking, Loading (CALL) 2007-7-17 Scott Beamer, Instructor

More information

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions Instructors: John Wawrzynek & Vladimir Stojanovic http://inst.eecs.berkeley.edu/~cs61c/fa15 1 Machine Interpretation Levels of Representation/Interpretation

More information

Review of Activation Frames. FP of caller Y X Return value A B C

Review of Activation Frames. FP of caller Y X Return value A B C Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C

More information

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

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline. The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

More information

Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9

Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9 Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline More on MIPS Calling Convention Functions calling functions

More information

A crash course in MIPS assembly programming

A crash course in MIPS assembly programming A crash course in MIPS assembly programming Computer Architecture 1DT016 distance Fall 2017 http://xyx.se/1dt016/index.php Per Foyer Mail: per.foyer@it.uu.se 1 MIPS Our processor Microprocessor without

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Instruction Formats July 2, 2014 Review New registers: $a0-$a3, $v0-$v1, $ra, $sp New instructions: slt, la, li, jal, jr Saved registers: $s0-$s7, $sp, $ra Volatile registers: $t0-$t9, $v0-$v1, $a0-$a3

More information

Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures #13 Running a Program II aka Compiling, Assembling, Linking, Loading (CALL) 2007-7-17 Scott Beamer, Instructor Green Subscription Based PC Announced

More information

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

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack

More information