Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Instructions: Part the Last.

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

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.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Procedure Calls Prof. Sirer CS 316 Cornell University.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
SPIM and MIPS programming
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.
MIPS Assembly Language Programming
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
1 Computer Architecture MIPS Simulator and Assembly language.
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
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.”
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
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)
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
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
OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
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,
Lecture 4: MIPS Instruction Set
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Logic Design: Part 1.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
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
Rocky K. C. Chang Version 0.1, 25 September 2017
Computer Science 210 Computer Organization
Lecture 5: Procedure Calls
Computer Architecture & Operations I
MIPS Procedures.
Lecture 4: MIPS Instruction Set
Procedures (Functions)
Procedures (Functions)
Assembly Programming using MIPS R3000 CPU
Instructions - Type and Format
MIPS Procedures.
MIPS Instructions.
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Logical and Decision Operations
MIPS Procedures.
10/4: Lecture Topics Overflow and underflow Logical operations
MIPS function continued
Program and memory layout
Lecture 6: Assembly Programs
Assembly Programming using MIPS R3000 CPU
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
Presentation transcript:

Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Instructions: Part the Last

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 2 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Brief review Different Types Instructions – R-Type – I-Type – J-Type Assembly Instructions – Arithmetic – Memory – Branching

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 3 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Today Support for procedures – Assembler and Hardware Shifting Data other than numbers And Last, But Certainly Not Least... Actually programming in assembly!

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 4 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Procedures AKA Subroutines Reusable chunks of code Used to structure programs – Easier to read – Easier to understand Leave no trace

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 5 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Properties of Procedures Have the following properties: – Parameters- the input to the procedure – Code Block- the actual instructions of the procedure – Return value- the result of the procedure – Separate from the current program location Often need: – Storage for local variables

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 6 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) How do we call a procedure? 1.Place parameters someplace procedure can access them 2.Transfer execution to the procedure location 3.Acquire local storage resources 4.Execute the code 5.Place the result someplace the original code can access 6.Return control to the original code

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 7 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) How does the hardware help? Well, registers are fast... – MIPS reserves $a0-$a3 for passing parameters – $v0 and $v1 are reserved for return values – $ra is reserved for the address to return control to

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 8 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) And what about instructions? Because the procedure's code is not close by – Use a jump instruction MIPS provides a specialized jump instructions – Jump and link instruction jal ProcedureAddress Link means store the address we are coming from in $ra – Called the return address – Jump register instruction jr $ra We can do this at the end of a procedure to return

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 9 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) A short example Proc1:add $t0, $a0, $a1 mul $t0, $0, $a3 sub $t0, $a4, $t0 add $v0, $t0, $zero jr $ra Main:li $a0, 12 li $a1, 42 li $a3, 123 li $a4, jal Proc1 (do some more instructions) Start Here

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 10 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Great, but... What happens if: – More parameters than 4? – Need to call another procedure? Destroy $ra as well as parameters ($a0-$a4) – Need storage for more than 8 temporaries? Answer – We need non-register memory to store information

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 11 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Ahh, the Stack Recall, the stack is used for local storage – LIFO structure- Last In First Out Operations – Push values on Adds data to stack – Pop top the value off Removes data from the stack Keep in mind – Stack grows downward in memory

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 12 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Making it work Need to know – Where the top of the stack is MIPS: Stack Pointer $sp – How to put data on stack Use $sp as the offset register and use – Store word instruction – Load word insrtuction Use arithmetic to allocate/deallocate space – Add/subtract to/from $sp to adjust stack

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 13 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) The Stack Push example subi $sp, $sp, 12 sw $a0, 8($sp) sw $a1, 4($sp) sw $t0, 0($sp) Pop example lw $t0, 0($sp) lw $a1, 4($sp) lw $a0, 8($sp) addi $sp, $sp, 12 Top of memory $sp -12 $t0 $a1 $a0 Top of memory $sp +12 $t0 $a1 $a0

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 14 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Using the stack Push parameters on the stack Push registers that need to be saved – $s0..$s7 – NOT $t0..$t7 Allocate local temporary storage – Subtract appropriate amount from $sp When calling another procedure – Save $ra

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 15 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) But if stack changes... How do we access local arrays, etc? – Use a register to keep track of where they are located Frame Pointer – Register $fp – Set to value of $sp when procedure starts – Change $sp as much as we want, but always have a reference point Handled by the program, not by the processor

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 16 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Stack Frame $sp $fp $sp $fp $sp $fp Saved arg Regs Saved $ra Saved regs Local storage

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 17 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Shifting Operations that move bits – Shift Left Move all the bits in register left a certain amount – Shift Right Move all the bits in the register right a certain amount Examples – Shift Left sll $t0, $t1, 3 – Shift Right srl $t0, $t1,

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 18 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Shifting Notice – Shift left by 1 is like muliplying by 2 – Shift right by 2 is like dividing by 2 If bits are shifted past the 32 nd (or 0 th ) bit – They are just shifted away, to be lost forever

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 19 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Rotating Similar to shifting, except – Bits shifted off the end are wrapped around to the other side – Example: rotate left

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 20 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) More than numbers Computers not calculators – Work with not just numbers – But also text Deal with characters – Encoded with ASCII – Combined into sequences of strings Use the load/store byte instruction to get data lb $t0, 1($s0) sb $t0, 1($s0) Use load address to get the address of data la $t0, DataLabel (Address)

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 21 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) String representations Reserve the first position to indicate length – Can only store 255 characters in the string – Pascal Use an external variable – Requires more memory – Java Use a special character to terminate the string – C uses the 0 (zero) character Null terminated strings

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 22 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Finally, we are ready to code Syntax – One instruction per line – # starts a comment Continues until the end of the line – Identifiers Alphanumeric, '_' and '.' Cannot start with a number – Labels Identifiers at the start of a line followed by ':'

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 23 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) More Language Syntax – Strings enclosed in “ ” \n A new line \t A tab character \” A quotation mark – Numbers Base 10 Hexadecimal – 0xABCD

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 24 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Directives Special commands for the assembler Usually starts with '.' – Example:.asciiz“The sum from is %d\n” Is equivalent to:.byte84, 104, 101, 32, 115, 117, 109, 32.byte102, 114, 111, 109, 32, 48, 32, 46.byte46, 32, 49, 48, 32, 105, 115, 32.byte37, 100, 10, 0 – Note: 10 is ASCII code for line feed 0 is ASCII code for the NULL character

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 25 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Directives Some example directives:.asciiz str# Store null-terminated string.byte b1,..., bn# Store in successive bytes.data # Store in data segment.float fl1,..., fn # Store floating-pt. single precision.globl sym # sym can be referenced from other files.space n # Allocate n-bytes of space in data seg..text # Put text items in text segment.word w1,..., wn # Full word in successive memory

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 26 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) I/O Need to be able to read and write data – For the user SPIM, this is accomplished with syscall In general, uses interrupt – Stalls processor state – Tells the processor to execute a procedure associated with the interrupt. – In PCs, this is what an IRQ is

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 27 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Using syscall (interrupts) Put a given constant into register $v0 Fill in the set of argument registers Execute the syscall instruction The result will be in register $v0 Look on page A-49 of the book for available service codes

OCC - CS/CIS CS116-Ch00-Orientation Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 28 OCC-CS 116 Fall Morgan Kaufmann Publishers (Augmented & Modified by M.Malaty and M. Beers) Example syscall.data var:.asciiz “This is a string\n”.text.globl main main:li $v0, 4 la $a0, var syscall