FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #7 – MIPS ISA, part 2: Procedures and Data.

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

Integer Arithmetic: Multiply, Divide, and Bitwise Operations
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.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
June 2005Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
Lecture 4: Loads, Logic, Loops. Review Memory is byte-addressable, but lw and sw access one word at a time. These instructions transfer the contents of.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Oct. 2014Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
RISC Concepts, MIPS ISA and the Mini–MIPS project
1 CS 430 Computer Architecture Clap if you like pizza! Pointless Poll.
Part II Instruction-Set Architecture
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
instruction set architecture (Part II of [Parhami])
Lecture 6 Sept 16 Chapter 2 continue MIPS translating c into MIPS – examples MIPS simulator (MARS and SPIM)
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Feb 18, 2009 Lecture 4-1 instruction set architecture (Part II of [Parhami]) MIPS assembly language instructions MIPS assembly programming.
More decisions and logic (1) Fall 2010 Lecture 4: Loads, Logic, Loops.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #13 – Instruction Execution Steps (in a Single-Cycle.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Jan. 2011Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Computer Organization and Design Instruction Sets Montek Singh Wed, Sep 12, 2012 Lecture 5.
Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return.
Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 4: MIPS Instruction Set
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #6 – MIPS ISA, part 1: Instructions and Addressing.
MIPS Assembly Language Chapter 13 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
MIPS Assembly Language Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
CDA 3101 Spring 2016 Introduction to Computer Organization
Mar. 2006Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Digital Logic Design Alex Bronstein
Integer Multiplication and Division
Computer Organization and Design Instruction Sets - 2
Lecture 4: MIPS Instruction Set
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Computer Organization and Design Instruction Sets
CSCI206 - Computer Organization & Programming
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
Part II Instruction-Set Architecture
Computer Instructions
Flow of Control -- Conditional branch instructions
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Flow of Control -- Conditional branch instructions
CS352H Computer Systems Architecture
Reduced Instruction Set Computer (RISC)
MIPS Arithmetic and Logic Instructions
Pointless Poll Clap if you like pizza!.
MIPS Arithmetic and Logic Instructions
7/6/
8/23/
Presentation transcript:

FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #7 – MIPS ISA, part 2: Procedures and Data

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 2 Part II Instruction-Set Architecture

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 3 II Instruction Set Architecture Topics in This Part Chapter 5 Instructions and Addressing Chapter 6 Procedures and Data Chapter 7 Assembly Language Programs Chapter 8 Instruction Set Variations Introduce machine “words” and its “vocabulary,” learning: A simple, yet realistic and useful instruction set Machine language programs; how they are executed RISC vs CISC instruction-set design philosophy

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 4 6 Procedures and Data Topics in This Chapter 6.1 Simple Procedure Calls 6.2 Using the Stack for Data Storage 6.3 Parameters and Results 6.4 Data Types 6.5 Arrays and Pointers 6.6 Additional Instructions Finish our study of MiniMIPS instructions and its data types: Instructions for procedure call/return, misc. instructions Procedure parameters and results, utility of stack

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Simple Procedure Calls Using a procedure involves the following sequence of actions: 1. Put arguments in places known to procedure (reg’s $a0-$a3 ) 2. Transfer control to procedure, saving the return address ( jal ) 3. Acquire storage space, if required, for use by the procedure 4. Perform the desired task 5. Put results in places known to calling program (reg’s $v0-$v1 ) 6. Return control to calling point ( jr ) MiniMIPS instructions for procedure call and return from procedure: jal proc# jump to loc “ proc ” and link; # “ link ” means “ save the return # address ” (PC)+4 in $ra ($31) jr rs # go to loc addressed by rs

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 6 Illustrating a Procedure Call Figure 6.1 Relationship between the main program and a procedure.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 7 Example 6.1 A Simple MiniMIPS Procedure Procedure to find the absolute value of an integer. $v0  | ($a0) | Solution The absolute value of x is –x if x < 0 and x otherwise. abs: sub $v0,$zero,$a0 # put -($a0) in $v0; # in case ($a0) < 0 bltz $a0,done # if ($a0)<0 then done add $v0,$a0,$zero # else put ($a0) in $v0 done: jr $ra # return to calling program In practice, we seldom use such short procedures because of the overhead that they entail. In this example, we have 3-4 instructions of overhead for 3 instructions of useful computation. int abs(int a0) { int v0 = -a0; if (a0 >= 0) v0 = a0; return v0; } /* C equiv. */

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 8 Nested Procedure Calls Figure 6.2 Example of nested procedure calls. Prep. to call Prep. to continue Save Restore

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Using the Stack for Data Storage Figure 6.4 Effects of push and pop operations on a stack. push: addi $sp,$sp,-4 sw $t4,0($sp) pop: lw $t5,0($sp) addi $sp,$sp,4

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 10 Memory Map in MiniMIPS Figure 6.3 Overview of the memory address space in MiniMIPS.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Parameters and Results Figure 6.5 Use of the stack by a procedure. Stack allows us to pass/return an arbitrary number of values

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 12 Example of Using the Stack proc:sw $fp,-4($sp)# save the old frame pointer addi $fp,$sp,0# save ($sp) into $fp addi $sp,$sp,–12# create 3 spaces on top of stack sw $ra,-8($fp)# save ($ra) in 2nd stack element sw $s0,-12($fp)# save ($s0) in top stack element. lw $s0,-12($fp)# put top stack element in $s0 lw $ra,-8($fp)# put 2nd stack element in $ra addi $sp,$fp, 0# restore $sp to original state lw $fp,-4($sp)# restore $fp to original state jr $ra# return from procedure Saving $fp, $ra, and $s0 onto the stack and restoring them at the end of the procedure

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Data Types Data size (number of bits), data type (meaning assigned to bits) Signed integer:byteword Unsigned integer:byteword Floating-point number:worddoubleword Bit string:byteworddoubleword Converting from one size to another Type 8-bit numberValue32-bit version of the number Unsigned Unsigned Signed Signed –

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 14 ASCII Characters Table 6.1 ASCII (American standard code for information interchange) SOHDC1!1AQaq STXDC2“2BRbr ETXDC3#3CScs EOTDC4$4DTdt ENQNAK%5EUeu ACKSYN&6FVfv BELETB‘7GWgw BSCAN(8HXhx HTEM)9IYiy LFSUB*:JZjz VTESC+;K[k{ FFFS,<L\l| CRGS-=M]m} SORS.>N^n~ SIUS/?O_oDEL abcdef abcdef a-f More controls More symbols 8-bit ASCII code (col #, row #) hex e.g., code for + is (2b) hex or ( ) two

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 15 Loading and Storing Bytes Figure 6.6 Load and store instructions for byte-size data elements. Bytes can be used to store ASCII characters or small integers. MiniMIPS addresses refer to bytes, but registers hold words. lb $t0,8($s3) # load rt with mem[8+($s3)] # sign-extend to fill reg lbu $t0,8($s3) # load rt with mem[8+($s3)] # zero-extend to fill reg sb $t0,A($s3) # LSB of rt to mem[A+($s3)]

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 16 Meaning of a Word in Memory Figure 6.7 A 32-bit word has no inherent meaning and can be interpreted in a number of equally valid ways in the absence of other cues (e.g., context) for the intended meaning.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Arrays and Pointers Index: Use a register that holds the index i and increment the register in each step to effect moving from element i of the list to element i + 1 Pointer: Use a register that points to (holds the address of) the list element being examined and update it in each step to point to the next element Figure 6.8 Stepping through the elements of an array using the indexing method and the pointer updating method.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 18 Selection Sort Example 6.4 Figure 6.9 One iteration of selection sort. To sort a list of numbers, repeatedly perform the following: Find the max element, swap it with the last item, move up the “last” pointer swap x&y

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 19 Selection Sort Using the Procedure max Example 6.4 (continued) sort: beq $a0,$a1,done # single-element list is sorted jal max # call the max procedure lw $t0,0($a1) # load last element into $t0 sw $t0,0($v0) # copy the last element to max loc sw $v1,0($a1) # copy max value to last element addi $a1,$a1,-4 # decrement pointer to last element j sort # repeat sort for smaller list done:... # continue with rest of program Inputs to proc max Outputs from proc max in $a0 in $a1 in $v0 in $v1

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Additional Instructions Figure 6.10 The multiply ( mult ) and divide ( div ) instructions of MiniMIPS. Figure 6.11 MiniMIPS instructions for copying the contents of Hi and Lo registers into general registers. MiniMIPS instructions for multiplication and division: mult $s0, $s1# set Hi,Lo to ($s0)  ($s1) div $s0, $s1 # set Hi to ($s0)mod($s1) # and Lo to ($s0)/($s1) mfhi $t0# set $t0 to (Hi) mflo $t0# set $t0 to (Lo)

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 21 Logical Shifts Figure 6.12 The four logical shift instructions of MiniMIPS. MiniMIPS instructions for left and right shifting: sll $t0,$s1,2 # $t0=($s1) left-shifted by 2 srl $t0,$s1,2 # $t0=($s1) right-shifted by 2 sllv $t0,$s1,$s0 # $t0=($s1) left-shifted by ($s0) srlv $t0,$s1,$s0 # $t0=($s1) right-shifted by ($s0)

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 22 Unsigned Arithmetic and Miscellaneous Instructions MiniMIPS instructions for unsigned arithmetic (no overflow exception): addu $t0,$s0,$s1# set $t0 to ($s0)+($s1) subu $t0,$s0,$s1# set $t0 to ($s0) – ($s1) multu $s0,$s1# set Hi,Lo to ($s0)  ($s1) divu $s0,$s1# set Hi to ($s0)mod($s1) # and Lo to ($s0)/($s1) addiu $t0,$s0,61# set $t0 to ($s0)+61; # the immediate operand is # sign extended To make MiniMIPS more powerful and complete, we introduce later: sra $t0,$s1,2# sh. right arith (Sec. 10.5) srav $t0,$s1,$s0# shift right arith variable syscall# system call (Sec. 7.6)

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 23 The 20 MiniMIPS Instructions from Chapter 6 (40 in all so far) InstructionUsage Move from Hi mfhi rd Move from Lo mflo rd Add unsigned addu rd,rs,rt Subtract unsigned subu rd,rs,rt Multiply mult rs,rt Multiply unsigned multu rs,rt Divide div rs,rt Divide unsigned divu rs,rt Add immediate unsigned addiu rs,rt,imm Shift left logical sll rd,rt,sh Shift right logical srl rd,rt,sh Shift right arithmetic sra rd,rt,sh Shift left logical variable sllv rd,rt,rs Shift right logical variable srlv rt,rd,rs Shift right arith variable srav rd,rt,rd Load byte lb rt,imm(rs) Load byte unsigned lbu rt,imm(rs) Store byte sb rt,imm(rs) Jump and link jal L System call syscall Copy Control transfer Shift Arithmetic Memory access op fn Table 6.2 (partial)

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 24 Table 6.2 The MiniMIPS Instructions Covered So Far InstructionUsage Move from Hi mfhi rd Move from Lo mflo rd Add unsigned addu rd,rs,rt Subtract unsigned subu rd,rs,rt Multiply mult rs,rt Multiply unsigned multu rs,rt Divide div rs,rt Divide unsigned divu rs,rt Add immediate unsigned addiu rs,rt,imm Shift left logical sll rd,rt,sh Shift right logical srl rd,rt,sh Shift right arithmetic sra rd,rt,sh Shift left logical variable sllv rd,rt,rs Shift right logical variable srlv rd,rt,rs Shift right arith variable srav rd,rt,rs Load byte lb rt,imm(rs) Load byte unsigned lbu rt,imm(rs) Store byte sb rt,imm(rs) Jump and link jal L System call syscall InstructionUsage Load upper immediate lui rt,imm Add add rd,rs,rt Subtract sub rd,rs,rt Set less than slt rd,rs,rt Add immediate addi rt,rs,imm Set less than immediate slti rd,rs,imm AND and rd,rs,rt OR or rd,rs,rt XOR xor rd,rs,rt NOR nor rd,rs,rt AND immediate andi rt,rs,imm OR immediate ori rt,rs,imm XOR immediate xori rt,rs,imm Load word lw rt,imm(rs) Store word sw rt,imm(rs) Jump j L Jump register jr rs Branch less than 0 bltz rs,L Branch equal beq rs,rt,L Branch not equal bne rs,rt,L