CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University.

Slides:



Advertisements
Similar presentations
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Advertisements

Goal: Write Programs in Assembly
CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Instruction Set-Intro
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.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
Instructions Set Bo Cheng Instruction Set Design An Instruction Set provides a functional description of a processor. It is the visible.
CS 61C L06 MIPS Intro (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Cs 61C L2 Asm Ops.1 Patterson Spring 99 ©UCB CS61C C/Assembler Operators and Operands Lecture 2 January 22, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CS1104 Assembly Language: Part 1
ECE 4436ECE 5367 ISA I. ECE 4436ECE 5367 CPU = Seconds= Instructions x Cycles x Seconds Time Program Program Instruction Cycle CPU = Seconds= Instructions.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
MIPS assembly. Computer What’s in a computer? Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
1 Computer Architecture COSC 3430 Lecture 3: Instructions.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
CHAPTER 6 Instruction Set Architecture 12/7/
CWRU EECS 3141 EECS 314: Load, Store, Arrays and Pointers Instructor: Francis G. Wolff Case Western Reserve University This presentation.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
Computer Architecture & Operations I
Computer Architecture & Operations I
CS2100 Computer Organisation
Instruction Set Architecture
Morgan Kaufmann Publishers
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
CSCI206 - Computer Organization & Programming
Lecture 4: MIPS Instruction Set
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
The University of Adelaide, School of Computer Science
MIPS History MIPS is a computer family
Chapter 2 Instructions: Language of the Computer
Computer Architecture
September 17 Test 1 pre(re)view Fang-Yi will demonstrate Spim
3.
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
COMS 361 Computer Organization
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Presentation transcript:

CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University This presentation uses powerpoint animation: please viewshow Load, Store and Dense Arrays

CWRU EECS 3222 Review: Design Abstractions High Level Language Program (e.g., C) Assembly Language Program (e.g. MIPS) Machine Language Program (MIPS) Control Signal Specification Compiler Assembler Machine Interpretation An abstraction omits unneeded detail, helps us cope with complexity temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw$t0,0($2) lw$t1,4($2) sw$t1,0($2) sw$t0,4($2) ALUOP[0:3] <= InstReg[9:11] & MASK

CWRU EECS 3223 Review: Registers Unlike C++, assembly instructions cannot directly use variables. Why not? clk bit0 bit31 Instruction operands are registers: limited number of special locations; 32 registers in MIPS ($r0 - $r31) Why 32? Each MIPS register is 32 bits wide Groups of 32 bits called a word in MIPS Keep Hardware Simple Performance issues: Smaller is faster A word is the natural size of the host machine.

CWRU EECS 3224 Register Organization Viewed as a tiny single-dimension array (32 words), with an register address bits of data bits of data 28 $r0 $r1 $r2 $r3 $r29 $r30 $r31 $r28... A register address ($r0-$r31) is an index into the array

CWRU EECS 3225 ANSI C integers (section A4.2 Basic Types) Plain int objects have the natural size suggested by the host machine architecture; the other sizes are provided to meet special needs Longer integers provide at least as much as shorter ones, but the implementation may make plain integers equivalent to either short integers, or long integers. The int types all represent signed values unless specified otherwise. Examples: short x; int y; long z; unsigned int f;

CWRU EECS 3226 Review: Compilation using Registers Compile by hand using registers: int f, g, h, i, j; f = (g + h) - (i + j); add $s0,$s1,$s2# $s0 = g+h Assign MIPS registers: # $s0=int f, $s1=int g, $s2=int h, # $s3=int i, $s4=int j MIPS Instructions: Note: whereas C declares its operands, Assembly operands (registers) are fixed and not declared add $t1,$s3,$s4# $t1 = i+j sub $s0,$s0,$t1# f=(g+h)-(i+j)

CWRU EECS 3227 ANSI C register storage class (section A4.1) Objects declared register are automatic, and (if possible) stored in fast registers of the machine. The register keyword tells the compiler your intent. This allows the programmer to guide the compiler for better results. (i.e. faster graphics algorithm) This is one reason that the C language is successful because it caters to the hardware architecture! Previous example: register int f, g, h, i, j; f = (g + h) - (i + j); If your variables exceed your number of registers, then not possible

CWRU EECS 3228 Assembly Operands: Memory C variables map onto registers What about data structures like arrays? But MIPS arithmetic instructions only operate on registers? Data transfer instructions transfer data between registers and memory Think of memory as a large single dimensioned array, starting at 0

CWRU EECS 3229 Memory Organization: bytes Viewed as a large, single-dimension array, with an address. A memory address is an index into the array "Byte addressing" means that the index points to a byte of memory bits of data C Language: –bytes multiple of word – Not guaranteed though char f; unsigned char g; signed char h;

CWRU EECS Memory Organization: words Bytes are nice, but most data items use larger "words" For MIPS, a word is 32 bits or 4 bytes words with byte addresses 0, 4, 8, bytes with byte addresses from 0 to Note: Registers hold 32 bits of data = word size (not by accident) bits of data...

CWRU EECS Memory Organization: alignment MIPS requires that all words start at addresses that are multiples of 4 Called alignment: objects must fall on address that is multiple of their size. (Later we’ll see how alignment helps performance) Aligned Not Aligned

CWRU EECS Memory Organization: Endian Words are aligned (i.e. 0,4,8,12,16,… not 1,5,9,13,…) i.e., what are the least 2 significant bits of a word address? Selects the which byte within the word How? lsb msb A 6 B Little Endianaddress of least significant byte: Intel 80x86, DEC Alpha little endian byte 0 67 A231 H = B6 H = A B Big Endian address of most significant byte: HP PA, IBM/Motorola PowerPC, SGI, Sparc big endian byte 0

CWRU EECS Data Transfer Instruction: Load Memory to Reg (lw) Load: moves a word from memory to register MIPS syntax, lw for load word: example: lw $t0, 8($s3) Called “offset”Called “base register” operation name register to be loaded constant and register to access memory MIPS lw semantics: reg[$t0] = Memory[8 + reg[$s3]]

CWRU EECS lw example s1 s2 s3 t0 g h A[0] 0 0xFFFFFFFF A[8] Then lw$t0,8($s3) Adds offset “8” to $s3 to select A[8], to put “42” into $t0 The value in register $s3 is an address Think of it as a pointer into memory The value in register $s3 is an address Think of it as a pointer into memory Suppose: Array A address = 3000 reg[$s3]=Array A reg[$t0]=12; mem[3008]=42; reg[$t0]=mem[8+reg[$s3]] =Hitchhikers Guide to the Galaxy =mem[8+3000]=mem[3008] =42

CWRU EECS Data Transfer Instruction: Store Reg to Memory (sw) Store Word (sw): moves a word from register to memory MIPS syntax: sw $rt, offset($rindex) MIPS semantics: mem[offset + reg[$rindex]] = reg[$rt] MIPS syntax: lw $rt, offset($rindex) MIPS semantics: reg[$rt] = mem[offset + reg[$rindex]] MIPS syntax: add $rd, $rs, $rt MIPS semantics: reg[$rd] = reg[$rs]+reg[$rt] MIPS syntax: sub $rd, $rs, $rt MIPS semantics: reg[$rd] = reg[$rs]-reg[$rt]

CWRU EECS Compile Array Example C code fragment: register int g, h, i; int A[66]; /* 66 total elements: A[0..65] */ g = h + A[i]; /* note: i=5 means 6rd element */ Compiled MIPS assembly instructions: add$t1,$s4,$s4# $t1 = 2*i add$t1,$t1,$t1# $t1 = 4*i add$t1,$t1,$s3 #$t1=addr A[i] lw$t0,0($t1) # $t0 = A[i] add$s1,$s2,$t0 # g = h + A[i]

CWRU EECS Execution Array Example: g = h + A[i]; Instruction$s1$s2$s3$s4 $t0$t1 C variablesghAi suppose (mem[3020]=38) ? ?? ????,?,? ?20 lw$t0,0($t1) ? ? 3020 add$s1,$s2,$t0 ? add$t1,$t1,$s3 ? ?20 add$t1,$t1,$t1 ? ?10 add$t1,$s4,$s4? ??

CWRU EECS Immediate Constants C expressions can have constants: i = i + 10; MIPS using constants: (addi: add immediate) So common operations, have instruction to add constants (called “immediate instructions”) addi $s3,$s3,10 # i = i + 10 MIPS assembly code: # Constants kept in memory with program lw$t0, 0($s0)# load 10 from memory add $s3,$s3,$t0 # i = i + 10

CWRU EECS Constants: Why? Why include immediate instructions? Design principle: Make the common case fast Why faster? a) Don’t need to access memory b) 2 instructions v. 1 instruction

CWRU EECS Zero Constant Also,perhaps most popular constant is zero. MIPS designers reserved 1 of the 32 register to always have the value 0; called $r0, $0, or “$zero” Useful in making additional operations from existing instructions; copy registers: $s2 = $s1; add $s2, $s1, $zero# $s2 = $s1 + 0 Load a constant: $s2 = number; addi $s2, $zero, 42# $s2 = 42 2’s complement: $s2 = –$s1; sub $s2, $zero, $s1# $s2 = – $s1

CWRU EECS C Constants C code fragment int i; const int limit = 10; i = i + limit; Is the same as i = i + limit; /* but more readable */ And the compiler will protect you from doing this limit=5;

CWRU EECS Class Homework: Due next class C code fragment: register int g, h, i, k; int A[5], B[5]; B[k] = h + A[i+1]; 1. Translate the C code fragment into MIPS 2. Execute the C code fragment using: A=address 1000, B=address 5000, i=3, h=10, k=2, int A[5]={24, 33, 76, 2, 19}; /* i.e. A[0]=24; A[1]=33; … */.