Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.

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.
Branches Two branch instructions:
The University of Adelaide, School of Computer Science
Deeper Assembly: Addressing, Conditions, Branching, and Loops
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
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.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
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.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
1 Lecture 3a: Supplemental Notes for Chapter 3 CS 447 Jason Bakos.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Intro to Computer Architecture
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
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.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
Lecture 4: MIPS Instruction Set
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CDA 3101 Spring 2016 Introduction to Computer Organization
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
Intro Assembly Computer Organization I 1 June 2010 © McQuain, Feng & Ribbens MIPS Hello World # Program: Hello, World!.data # data declaration.
CSCI206 - Computer Organization & Programming
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
Lecture 6: Assembly Programs
Computer Architecture Instruction Set Architecture
CS2100 Computer Organisation
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Computer Organization and Design Instruction Sets
CSCI206 - Computer Organization & Programming
Instructions - Type and Format
MIPS Instructions.
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
Review.
MIPS function continued
Flow of Control -- Conditional branch instructions
Lecture 6: Assembly Programs
Flow of Control -- Conditional branch instructions
Computer Architecture
CS352H Computer Systems Architecture
9/27: Lecture Topics Memory Data transfer instructions
Presentation transcript:

Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language

Fall 2003SYCS-401 Operating Systems Overview Review of the concept of an Instruction SetArchitecture (ISA) Understand the format of MIPS assembly source files Be able to identify the registers of the R3000 and their purpose Be able to understand the effects of a subset of instructions of the MIPS R3000 Instruction Set Architecture (ISA)

Fall 2003SYCS-401 Operating Systems Opcodes and Operands add $a0, $t1, $t0 Opcode (Instruction) Operands (“arguments”)

Fall 2003SYCS-401 Operating Systems Simple Assembler Program.globl main.text main: # Program starts here. li $t0, 5 # Load the integer value 5 # into register t0 li $t1, 19# Load 19 into register t1 add $t2, $t1, $t0 # Add registers t0 and t1 # to produce t2 li $v0, 1 # Setup a print integer call # to print the result move $a0, $t2 syscall li $v0, 10 # Setup an exit call syscall # Do the exit thing Add the integers 5 and 19, and print the result. 8

Fall 2003SYCS-401 Operating Systems Instruction Set Architecture (ISA) Think of the ISA as the hardware/software interface In this lecture we look at some aspects of MIPS ISA, including: Some opcodes Required operands there are no implicit operands in MIPS Means of accessing RAM Number of registers Instruction format etc., etc.

Fall 2003SYCS-401 Operating Systems MIPS: ISA generations (‘I’ to ‘IV’) MIPS I (8 MHz, 32b architecture) R2000 (first commercial MIPS processor) MIPS II (40 MHz, 32b architecture) R3000 MIPS III (to 250 MHz pipeline, 64b architecture) R4x00 MIPS IV R8000 R10000 R5000

Fall 2003SYCS-401 Operating Systems

Fall 2003SYCS-401 Operating Systems MIPS Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems General-Purpose Registers

Fall 2003SYCS-401 Operating Systems MIPS opcode formats

Fall 2003SYCS-401 Operating Systems MIPS Instruction Categories Arithmetic instructions add, subtract, multiply, divide comparison Logical instructions Branch and jump instructions conditional (branch) unconditional (jump) Data transfer (load & store) instructions

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions add subtract multiply divide compare shift / rotate not covered here

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Add Registers ADD destinationReg, sourceReg, targetReg Destination  Source + Target

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Add Unsigned ADDU destinationReg, sourceReg, targetReg Destination  Source + Target

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Add Immediate ADDI destinationReg, sourceReg, targetReg Destination  Source + Target

Fall 2003SYCS-401 Operating Systems MIPS Opcode Map

Fall 2003SYCS-401 Operating Systems MIPS Opcode Map

Fall 2003SYCS-401 Operating Systems MIPS System Calls ( syscall )

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Divide Registers DIV sourceReg, targetReg $lo (quotient), $hi (remainder)  Source / Target

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Multiply Registers MUL sourceReg, targetReg $lo (low word), $hi (high word)  Source x Target

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Set if Less Than SLT destinationReg, sourceReg, targetReg Destination  Source < Target) ? 1 : 0

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: SLT Immediate SLTI destinationReg, sourceReg, immediate Destination  Source < immediate) ? 1 : 0

Fall 2003SYCS-401 Operating Systems Some other arithmetic instructions

Fall 2003SYCS-401 Operating Systems Logical Instructions Logical AND logical OR XOR NOT

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Logical AND AND destinationReg, sourceReg, targetReg Destination  Source AND Target

Fall 2003SYCS-401 Operating Systems Arithmetic Instructions: Logical OR OR destinationReg, sourceReg, targetReg Destination  Source OR Target

Fall 2003SYCS-401 Operating Systems Some other Logical instructions

Fall 2003SYCS-401 Operating Systems Branch and Jump Instructions These alter the (otherwise) linear flow of control. There are two main types of “go to” instruction unconditional ( always go to … ) > jump conditional ( if … then go to … ) > branch (indicating an alternative flow)

Fall 2003SYCS-401 Operating Systems Branch and Jump Instructions

Fall 2003SYCS-401 Operating Systems Jump Instructions: Jump J label Jump to instruction at label

Fall 2003SYCS-401 Operating Systems Jump Instructions: Jump & Link JAL label Place the address of the next instruction (PC + 4) in $ra. Jump to the instruction at ‘label’

Fall 2003SYCS-401 Operating Systems Jump Instructions: Jump & Link

Fall 2003SYCS-401 Operating Systems Branch Instructions: Branch on Equal BEQ sourceRegister, targetRegister, label If (sourceRegister == targetRegister) go to instruction at ‘label’

Fall 2003SYCS-401 Operating Systems Branch Instructions: Branch if Equal to Zero BEQZ sourceRegister, label If (sourceRegister == 0) go to instruction at ‘label’

Fall 2003SYCS-401 Operating Systems Some other Jump/Branch instructions

Fall 2003SYCS-401 Operating Systems Data transfer instructions MIPS is a load-and-store architecture The only instructions that access RAM are those\ which load to (or store from) registers Note that all other instructions operate on registers To change a value in memory, you must therefore: load it to a register alter it store it back in memory

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Load Address LA destinationRegister, address destinationRegister  calculated address

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Load Immediate LI destinationRegister, immediate destinationRegister  immediate value

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Move from HI MFHI destinationRegister destinationRegister  HI register

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Load Byte LB targetRegister, label Load targetRegister with the byte value at address “label”

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Store Byte SB targetRegister, label Store low byte value in targetRegister at address “label”

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Load Word LW targetRegister, label Load targetRegister with the word value at address “label”

Fall 2003SYCS-401 Operating Systems Data Transfer Instructions: Move MOVE destinationRegister, sourceRegister destinationRegister  sourceRegister

Fall 2003SYCS-401 Operating Systems Some other Data Transfer instructions

Fall 2003SYCS-401 Operating Systems Assembler directives: Examples

Fall 2003SYCS-401 Operating Systems Template.s

Fall 2003SYCS-401 Operating Systems Example.s

Fall 2003SYCS-401 Operating Systems Assembler Syntax Comments begin with a ‘#’ and continue to the end of the line Identifiers identifier  { a-z A-Z _. } { a-z A-Z _. 0-9 }* Label declaration (follow by a colon) identifier: Strings (use double quotes; special characters use backslash) “ \t \“Hello World\” is \nthe usual example!”

Fall 2003SYCS-401 Operating Systems High Level Language Constructs How do we code if-then, if-then-else, while, do-while, for, and switch statements. Examples: Assume The existence of a 32b integer (labelled ‘x’) is assumed:.data x:.word 0

Fall 2003SYCS-401 Operating Systems If Construct

Fall 2003SYCS-401 Operating Systems If Construct

Fall 2003SYCS-401 Operating Systems If Construct

Fall 2003SYCS-401 Operating Systems Post-Test Loop

Fall 2003SYCS-401 Operating Systems Post-Test Loop

Fall 2003SYCS-401 Operating Systems Simple Assembler Program.globl main.text main: # Program starts here. li $t0, 5 # Load the integer value 5 # into register t0 li $t2, $a0# set t2 = 0 start: bgtz $t0, done# if t0 <= 0 then goto done add $t2, $t2, $t0 # Add registers t0 and t1 # to produce t2 subi $t0, t0, 1# t0 = t0 - 1 j start done: li $v0, 1 # Setup a print integer call # to print the result move $a0, $t2 syscall li $v0, 10 # Setup an exit call syscall # Do the exit thing

Fall 2003SYCS-401 Operating Systems Assembly vs. High-Level Languages (HLLs)

Fall 2003SYCS-401 Operating Systems Producing an Executable

Fall 2003SYCS-401 Operating Systems Procedure Calls The terminology tends to be rather loose. One view: functions return values whereas procedures do not Here the terms are used interchangeably

Fall 2003SYCS-401 Operating Systems Link Instructions Link instructions leave a return address on register $ra (31) This is the address of the next instruction, PC + 4. Unconditional (jump and link) jal Conditional (branch and link) b*al bgezal, bltzal, etc.

Fall 2003SYCS-401 Operating Systems Returning from a procedure There is a “jump register” instruction that jumps to the address held in the specified register Typical use: jr $ra Note, however, that the specified register does not need to be $ra

Fall 2003SYCS-401 Operating Systems Procedure Calls

Fall 2003SYCS-401 Operating Systems Passing function arguments Recall the register conventions that MIPS uses $a0 - $a3 are used for passing arguments Arguments must be simple There is a limit of 4 by this convention Greater demands than these are met by use of the stack

Fall 2003SYCS-401 Operating Systems Returning values Register conventions also specify that registers $v0 - $v1 may be used for returning values from a function Similar constraints apply to argument- passing

Fall 2003SYCS-401 Operating Systems The Stack

Fall 2003SYCS-401 Operating Systems Uses of the stack Save registers that are meant to be preserved by the calling code. Pass complex arguments to a procedure Use for local variables variables with local scope that are destroyed once the procedure has completed

Fall 2003SYCS-401 Operating Systems Procedure Call Conceptually

Fall 2003SYCS-401 Operating Systems Caller Template (Calling the function) Pass arguments to the function first 4 arguments use registers $a0 - $a3 more arguments must use the stack Save any important values that are held in temporary registers Execute jump/branch and link instruction

Fall 2003SYCS-401 Operating Systems Called template (Start) Make room on the stack subi $sp, $sp, Why subtraction? Store any registers of interest $ra if your routine makes a function call Why? Any $s0-$s7 registers that will be used Why?

Fall 2003SYCS-401 Operating Systems Called template (Finish) Make returned values available Put in $v0, $v1 Restore any registers that were saved $ra, $s0-$s7 Pop the stack addi $sp, $sp, Return jr $ra

Fall 2003SYCS-401 Operating Systems Caller template (Returning from the function) Handle results, if any registers $v0, $v1 Restore saved values, if any

Fall 2003SYCS-401 Operating Systems Example.s

Fall 2003SYCS-401 Operating Systems Sources Indigo image and specs For the R2000 instruction set Patterson, D.A., & Hennesy, J.L., (1994). “ComputerOrganization and Design: The Hardware / Software Interface”, Morgan Kaufmann. (Appendix A) Available online at: For the R3000 instruction set