Ch2b- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
SPIM and MIPS programming
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
MIPS Function Continued
MIPS Assembly Language Programming
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Comp Sci vars & expns 1 Ch. 4 Variables and Expressions.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
Ch2a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what.
June 14, 2016Machine Language and Pointers1 What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; }
CS 312 Computer Architecture & Organization
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Instruction Set Advantages
Lecture 7: MARS, Computer Arithmetic
Morgan Kaufmann Publishers
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
MIPS coding.
Instructions - Type and Format
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Single-Cycle CPU DataPath.
Lecture 4: MIPS Instruction Set
MPIS Instructions Functionalities of instructions Instruction format
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
MIPS Coding.
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
COMS 361 Computer Organization
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
MIPS coding.
CPU Structure CPU must:
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Presentation transcript:

Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost all the time, actually), you can’t fit all of your data into 32 measly registers. What do you do? Put some (most) of the data in main memory. Remember: Smaller is faster. Registers: Small and Fast Memory: Big and Slow In MIPS, all operations (i.e. arithmetic) are done on registers, only. Memory is used only for storing what won’t fit in registers. In MIPS, all operations (i.e. arithmetic) are done on registers, only. Memory is used only for storing what won’t fit in registers.

Ch2b- 3 EE/CS/CPE Computer Organization  Seattle Pacific University Loading and Storing So you’ve got some data in memory. Big deal. You need it in a register to do anything useful. You need to load a register with a value from memory. lw $10, 1000($0)# copy memory location 1000 to $10 Load Word - Loads a whole 32-bit word This value is added to for now, it is zero Say you’ve added 1 to register $10 (now it has the value 44). Now you want to put it back in memory again. You need to store the register’s value back to memory. sw $10, 1000($0)# copy $10 to memory location Afterwards, $10 has the value 43 44

Ch2b- 4 EE/CS/CPE Computer Organization  Seattle Pacific University Load/Store Format What instruction format do LW and SW have? lw $5, 240($9) # load M[240+$9] into $5 Needs Opcode Source register ($9) Immediate Operand (240) Destination register ($5) Opcode for LW: 35 Think Regularity! Opcode RS RT Immediate Data 6 bits5 bits 16 bits I-Type Instruction Opcode for SW: 43 Hmmm, we’ve seen this before....

Ch2b- 5 EE/CS/CPE Computer Organization  Seattle Pacific University Aside: Load and Store Architectures The only way to communicate with memory is through a LW or SW instruction If you want to operate on memory, you have to use at least three instructions (usually) lw $15, 4500($0) # load M[4500] into $15 add $15, $15, $3 # add $3 to $15 sw $15, 4500($0) # store $15 back into M[4500] It doesn’t have to be this way Contrast this with the Motorola ADD D3, 4500 ; add register D3 to M[4500] Is the grass greener on the other side? MIPS: Takes more, simpler instructions... RISC MC68000: Takes fewer, complex instructions... CISC

Ch2b- 6 EE/CS/CPE Computer Organization  Seattle Pacific University Assembler directives Somehow, we’ve got to get data into memory User input Involves system calls (we’ll get to that later) Constant data Constant data is data that is in memory before our program starts executing Machine-language instructions don’t give much help The only way is to use Immediate instructions The assembler helps us here! Assembler directives are special commands to the assembler. The most common directives put data into memory.

Ch2b- 7 EE/CS/CPE Computer Organization  Seattle Pacific University Buffer: Buffer+ 4:.word Assembler Directive Buffer:.word01, 02 Label: A name for this memory to go by. Acts as a variable name. Label: A name for this memory to go by. Acts as a variable name..word: Directive to store words in memory here. Data to be stored. lw $12, Buffer($0) # $12 < addi $10, $0, 4 # $10 <-- 4 lw $13, Buffer($10) # $13 < Remember: Words are 4 bytes each! Loads from Buffer+0Loads from Buffer+4

Ch2b- 8 EE/CS/CPE Computer Organization  Seattle Pacific University The Assembler Location Counter The assembler keeps track of where to put things by using a location counter. The location counter just points to the memory location to put the “next” item. buffer1:.word12 buffer2:.word3, 4, 0x20, 0x5 add$9, $0, $0 firstld:lw$8, buffer1($9) addi$9, $9, 4 secld:lw$10, buffer2($9) For this example, assume the location counter starts at : 4004: 4020: 4024: 4028: 4032: Hex Constants a denoted by the “0x” prefix buffer1 = 4000 buffer2 = 4004 firstld = 4024 secld = 4032 Label Table Loc. Ctr. Instructions – stored in ordinary memory. Execute by telling the CPU to start running at location 4020.

Ch2b- 9 EE/CS/CPE Computer Organization  Seattle Pacific University Other Memory Assembler Directives borg:.byte33, 22, 12, 10, 8, 1 greeting:.asciiz“Resistance is futile.” greeting2:.ascii“You will be assimilated.” greeting: 02E656C... Null-terminated 20756F59 --2E greeting2:.byte - reserves bytes in memory.asciiz - reserves Null- terminated ASCII chars.ascii - reserves ASCII characters (no NULL) borg: ??18 Resi le.

Ch2b- 10 EE/CS/CPE Computer Organization  Seattle Pacific University Meeting all your needs for space Sometimes, we need to allocate (empty) space to be used later. inputbuffer:.space100 Allocates 100 bytes of space for an input buffer. Space allocated this way is just reserved by the assembler. You have to make your own use of it. addi$12, $0, 6 sw$12, inputbuffer($0) # stores 6 in buffer.align 2 inputbuffer:.space100 If the space is to be used as words (with LW,SW), make sure it is aligned to a multiple of 2 2 using the.align directive

Ch2b- 11 EE/CS/CPE Computer Organization  Seattle Pacific University Our first program! # This is our first program! Yeah!.data Tonto:.word0x44, 0x22.text main: add$9, $0, $0 # clear $9 lw$8, Tonto($9) # put Tonto[0] in $8 addi$9, $9, 4 # increment $9 lw$10, Tonto($9) # put Tonto[1] in $10 addi$v0,$0,10 syscall.data means that data follows.text means that code follows main: tells SPIM where to start these two instructions end the program

Ch2b- 12 EE/CS/CPE Computer Organization  Seattle Pacific University SPIM The SPIM simulator is a MIPS simulator Allows development and debugging of MIPS programs without having to run on a MIPS CPU QTSPIM (newer, many platforms) or PCSPIM at Help on SPIM Appendix A of your textbook Handouts and sample programs Look under Resources on the course web page

Ch2b- 13 EE/CS/CPE Computer Organization  Seattle Pacific University Pseudoinstructions Some “missing” instructions are commonly composed of others The assembler “implements” these by allowing the “missing” instructions to be entered in assembly code. When machine code is generated, the pseudoinstructions are converted to real instructions. move$5, $3add$5, $3, $0 neg$8, $9sub$8, $0, $9 li$8, 44addi$8, $0, 44 or ori$8, $0, 44

Ch2b- 14 EE/CS/CPE Computer Organization  Seattle Pacific University Pseudoinstructions for branches Branches can be nasty to figure out SPIM provides several pseudoinstructions for branches blt$3, $4, destslt$1, $3, $4 bne$1, $0, dest bgt$3, $4, destslt$1, $4, $3 bne$1, $0, dest $3 > $4 same as $4 < $3 ble$3, $4, destslt$1, $4, $3 beq$1, $0, dest bge$3, $4, destslt$1, $3, $4 beq$1, $0, dest $3 >= $4 is the opposite of $3 < $4 $3 $4

Ch2b- 15 EE/CS/CPE Computer Organization  Seattle Pacific University SPIM I/O SPIM I/O uses the SYSCALL pseudoinstruction Set up parameters Place correct code in $v0 Execute SYSCALL To print the value in $t3: move $a0, $t3 li $v0, 1 syscall To display a string prompt:.asciiz “hello world” la $a0,prompt li $v0, 4 syscall ActionCode (in $v0)Parameters Print an Integer1$a0 = value to print Print a String4$a0 = location of string Input an Integer5(after syscall) $v0 contains integer Input a String8$a0 = location of buffer, $a1 = length Exit program10

Ch2b- 16 EE/CS/CPE Computer Organization  Seattle Pacific University Data Structures - Arrays A single-dimensional array (vector) is a simple linear data structure int A[5]; /* integers are 4 bytes each */ start of array (2004 in this example) A[0] A[1] A[2] A[3] A[4] For 4-byte integers: Location of A[n] = Start + n*4; For data items of size s bytes: Location of A[n] = Start + n*s; To declare an array named A with 40 bytes: A:.space 40 A is the address of element 0. The program must do all computations needed to access any other elements.

Ch2b- 17 EE/CS/CPE Computer Organization  Seattle Pacific University Accessing data structures in memory Assume that the variable List points to the beginning of an array of 32-bit integers. List= Note: Memory addresses refer to 8-bit bytes! We usually reference 32-bit words. All lw/sw instructions must use an address that is a multiple of 4! To get proper index, have to multiply by 4. Note: Memory addresses refer to 8-bit bytes! We usually reference 32-bit words. All lw/sw instructions must use an address that is a multiple of 4! To get proper index, have to multiply by 4. Move List[0] into $3: lw $3, List($0) # $3 <-- List[0] Move List[1] into $4: addi $8, $0, 4 # $8 <-- 4 lw $4, List($8) # $4 <-- List[1] addi $8, $0, 16 # $8 <-- 16 lw $5, List($8) # $5 <-- List[4] Move List[4] into $5: List and contents of $8 are added together to form address List[0] List[1] List[2] List[3] List[4]