Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.

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

Lecture 5: MIPS Instruction Set
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.
Procedure Calls Prof. Sirer CS 316 Cornell University.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
ELEN 468 Advanced Logic Design
Chapter 2 Instructions: Language of the Computer
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Procedure call frame: Hold values passed to a procedure as arguments
Assembly Language II CPSC 321 Andreas Klappenecker.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
CHAPTER 2 ISA Instructions (logical + procedure call)
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
Lecture 4: MIPS Instruction Set
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
CHAPTER 6 Instruction Set Architecture 12/7/
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Computer Science 210 Computer Organization
Computer Architecture Instruction Set Architecture
COMPUTER ARCHITECTURE & OPERATIONS I
Computer Architecture Instruction Set Architecture
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Instructions - Type and Format
Appendix A Classifying Instruction Set Architecture
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
MIPS Procedure Calls CSE 378 – Section 3.
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Logical and Decision Operations
Review.
10/4: Lecture Topics Overflow and underflow Logical operations
Computer Instructions
Computer Architecture
Program and memory layout
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Program and memory layout
Computer Architecture
Program and memory layout
Program and memory layout
Presentation transcript:

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 42 Instruction formats Every MIPS instruction consists of a single 32-bit word aligned on a word boundary Three different instruction formats:  I type (immediate)  R type (register)  J type (jump)

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 43 Instruction formats

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 44 Parts of instruction op – 6-bit opcode (2 6 = 64 so 64 different operations are possible) rs – 5-bit source register (2 5 = 32 so 32 different registers are possible) rd – 5-bit destination register rt – 5-bit target register or branch condition immediate – 16-bit immediate value, branch displacement or address displacement target – 26-bit jump target address shamt – 5-bit shift amount funct – 6-bit function field (allows additional operations by combining with op field)

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 45 Register addressing Just indicate the register name/number as the operand Simplest and fastest addressing mode A form of direct addressing (the data is actually in the register) Example: add $t0,$t1,$t2

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 46 Register addressing

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 47 Base addressing A small constant is added to a pointer held in a register Gives you the ability to address fixed offsets from a base address of a data structure A form of indirect addressing since the operand is at the memory location whose address is in a register Examples (assuming a valid address is in $t2): lb $t0,($t2) lw $t1,4($t2)

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 48 Base addressing

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 49 Immediate addressing One operand is a constant within the instruction itself Does not require an extra memory access to fetch the operand Operand is limited to 16 bits in size Example: addi $t1,$t1,1

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 410 Immediate addressing

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 411 Immediate addressing

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 412 Program counter relative addressing Address is the sum of the program counter and a constant in the instruction Used for conditional branches Branch can only be instructions above or below the program counter because the offset is a 16-bit two’s complement number Example: beqz $t0,strEnd

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 413 Program counter relative addressing

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 414 In-class exercise Write a program to sum the elements of an array Use the template sum.asm as a starting point

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 415 Shift instructions sll reg dest,reg src1, src2  Shift left logical  reg src1 shifted left by the distance specified in src2 and the result put in reg dest  0 fill the empty bits srl reg dest,reg src1, src2  Shift right logical  reg src1 shifted right by the distance specified in src2 and the result put in reg dest  0 fill the empty bits sra reg dest,reg src1, src2  Shift right arithmetic  reg src1 shifted right by the distance specified in src2 and the result put in reg dest  sign fill the empty bits

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 416 Rotate instructions rol reg dest,reg src1, src2  Rotate left  reg src1 rotated left by the distance specified in src2 and the result put in reg dest ror reg dest,reg src1, src2  Rotate right  reg src1 rotated right by the distance specified in src2 and the result put in reg dest

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 417 Logical instructions and or xor nor not All take 3 operands except not, which takes 2

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 418 Example program Look at uppercase.asm, which converts a string to all uppercase letters. Demo it. Demo it

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 419 The stack A stack is last in, first out data structure Special register, $sp, points to top of the stack In MIPS, the stack is actually upside down, with the top of the stack growing toward lower memory addresses

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 420 Stack operations Push – add something to the stack, e.g. push the word in $t0 onto the stack sub $sp,$sp,4 sw $t0,($sp) Pop – remove the top item from the stack, e.g. to pop the top of stack to $t0 lw $t0,($sp) add $sp,$sp,4

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 421 Procedure calls Jump and link instruction ( jal ) puts the return address into register $ra, which is a special register to hold the return address Procedure just needs to execute jr $ra at the end of the procedure to return

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 422 If a procedure calls another procedure … The return address will be lost, as $ra will be overwritten The first procedure will have to save the return address in $ra on the stack before it calls the second procedure, and then restore it before returning sub $sp,4lw $ra,($sp) sw $ra,($sp)add $sp,4 jr $ra

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 423 Passing parameters to procedures First four parameters are passed in the argument registers $a0..$a3 Additional parameters are passed on the stack Return values are sent back in $v0 and $v1

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 424 Register usage in procedures A procedure may need to have local variables Best to keep these in registers for speed of access If one procedure calls another, it may lose the local variables’ values in the registers if the second procedure uses the registers as well Thus, need to save register values This can be done either by the calling procedure or the called procedure

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 425 MIPS conventions Registers $s0..$s7 are callee saves, they will be saved by the called procedure and restored before returning Registers $t0..$t9 are caller saves, the procedure doing the calling must save them if there are values that are needed after the called procedure returns

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 426 Stack frames A block of memory on the stack allocated at procedure entry to hold all local variables needed by the procedure A special register, $fp, contains the address of the stack frame for the procedure Base mode addressing off $fp addresses local variables

Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 427 Example program uppercaseProc.asm takes the string conversion to uppercase example and does the work in a procedure Demo