Computer Organization 2015 - 2016 1. Instructions Language of The Computer (MIPS) 2.

Slides:



Advertisements
Similar presentations
Instruction Set Design
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.
Control path Recall that the control path is the physical entity in a processor which: fetches instructions, fetches operands, decodes instructions, schedules.
There are two types of addressing schemes:
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Memory Locatıons and Addresses (Week 3)
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Computer Organization and Architecture
1 Registers and MAL - Part I. Motivation So far there are some details that we have ignored instructions can have different formats most computers have.
Execution of an instruction
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Memory - Registers Instruction Sets
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
MIPS Instruction Set Advantages
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
MIPS assembly. Computer What’s in a computer? Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
ITEC 352 Lecture 12 ISA(3). Review Buses Memory ALU Registers Process of compiling.
Introduction to Computing Systems from bits & gates to C & beyond The Von Neumann Model Basic components Instruction processing.
Chapter 4 The Von Neumann Model
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Instruction Set Architecture The portion of the machine visible to the programmer Issues: Internal storage model Addressing modes Operations Operands Encoding.
Execution of an instruction
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
Computer Architecture Lecture 03 Fasih ur Rehman.
Computer Studies/ICT SS2
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
UConn CSE CSE241: Instruction Level Architecture Base CPU/Memory Architecture Registers Fetch-Execute Cycle Instructions Addressing Modes.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Computer Organization Instructions Language of The Computer (MIPS) 2.
Dale & Lewis Chapter 5 Computing components
Computer Organization Rabie A. Ramadan Lecture 3.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Our programmer needs to do this !
Von Neumann Model Computer Organization I 1 September 2009 © McQuain, Feng & Ribbens The Stored Program Computer 1945: John von Neumann –
Question What technology differentiates the different stages a computer had gone through from generation 1 to present?
Chapter 4 The Von Neumann Model
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
Processor Organization
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
MIPS assembly. Computer  What’s in a computer?  Processor, memory, I/O devices (keyboard, mouse, LCD, video camera, speaker), disk, CD drive, …
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
MIPS Processor.
Functions of Processor Operation Addressing modes Registers i/o module interface Memory module interface Interrupts.
MIPS Instruction Set Advantages
Chapter 4 The Von Neumann Model
Chapter 4 The Von Neumann Model
Computer Organization and Assembly Language (COAL)
Chapter 4 The Von Neumann Model
The Processor and Machine Language
Central Processing Unit
MIPS assembly.
Topic 6 LC-3.
The Von Neumann Model Basic components Instruction processing
The Von Neumann Architecture Odds and Ends
The Stored Program Computer
Basic components Instruction processing
CPU Structure and Function
MIPS Processor.
COMPUTER ARCHITECTURE
Chapter 4 The Von Neumann Model
MIPS Assembly.
Presentation transcript:

Computer Organization

Instructions Language of The Computer (MIPS) 2

Memory organization Information is stored in the memory as a collection of bits. Collection of bits are stored or retrieved simultaneously is called a word Number of bits in a word is called word length Word length can be 16 to 64 bits Collection of 8 bits known as a “byte” Word length of 16 bits, is equivalent to word length of 2 bytes Words may be 2 bytes (older architectures), 4 bytes (current architectures), or 8+ bytes (modern architectures). 3

Memory organization (cont.) Accessing the memory to obtain information requires specifying the “address” of the memory location Addresses are assigned to a single byte. “Byte addressable memory” Suppose k bits are used to hold the address of a memory location: size of the memory in bytes is given by 2 k For example, a 24-bit address generates an address space of 2 24 (16,777,216) locations (bytes) 4

Memory Words 5

Memory organization Consider a memory organization: 16-bit memory addresses Size of the memory is ? 2 16 Bytes Word length is 4 bytes Number of words = Memory size(bytes) = ? Word length(bytes) Word #0 starts at Byte #0. Word #1 starts at Byte #4. Byte 0 Byte 1 Byte 2 Byte 3 Byte Byte Byte Byte Word #0 Word #1 Word #? Byte 4 6

Execution of an instruction The steps involved in the execution of an instruction by a processor: Fetch an instruction from the memory. Fetch the operands. Execute the instruction. Store the results. Basic processor architecture has several registers to assist in the execution of the instructions. 7

Registers in the control path Instruction Register (IR): Instruction that is currently being executed. Program Counter (PC): Address of the next instruction to be fetched and executed. Memory Address Register (MAR): Address of the memory location to be accessed. Memory Data Register (MDR): Data to be read into or read out of the current memory location, whose address is in the Memory Address Register (MAR). 8

Basic Processor Architecture Processor Memory PC IR MDR Control ALU R(n-1) - R1 R0 MAR n general purpose registers Address of the memory location to be accessed Address of the next instruction to be fetched and executed. Instruction that is currently being executed Data to be read into or read out of the current location General purpose registers 9

Basic processor architecture (cont.) Control Path Data Path MARMDR Memory Processor Control path is responsible for: Instruction fetch and execution sequencing Operand fetch Saving results Data path: Contains general purpose registers Contains ALU Executes instructions 10

Fetch/Execute cycle Execution of an instruction takes place in two phases: Instruction fetch. Instruction execute. Instruction fetch: Fetch the instruction from the memory location whose address is in the Program Counter (PC). Place the instruction in the Instruction Register (IR). 11

Fetch/Execute cycle (cont.) Instruction execute: Instruction in the IR is examined (decoded) to determine which operation is to be performed. Fetch the operands from the memory or registers. Execute the operation. Store the results in the destination location. Basic fetch/execute cycle repeats indefinitely. 12

Byte 0 Byte 1 Byte 2 Byte 3 Byte Byte Byte Byte Word #0 Word #1 Word #16383 Byte 4 MAR MDR Addr MAR register contains the address of the memory location addressed MDR contains either the data to be written to that address or read from that address. 13

14

15

Addressing Modes A high-level language enables the programmer to use constants, local and global variables, pointers, and arrays When translating a high-level language program into assembly language, the compiler must be able to implement these constructs using the facilities in the instruction set of the computer The different ways in which the location of an operand is specified in an instruction are referred to as addressing modes 16

Addressing Modes (cont.) Some of important addressing modes are: Immediate mode Register mode Absolute mode Indirect mode Index mode 17

Addressing Modes (cont.) Immediate mode Operand is given explicitly in the instruction. E.g. Move R0, 200 Can be used to represent constants. Register mode Operand is the contents of a processor register. Address of the register (its Name) is given in the instruction. E.g. Clear R1 or Move R1, R2 18

Addressing modes (cont.) Absolute mode Operand is in a memory location. Address of the memory location is given explicitly in the instruction. E.g. Clear Aor Move R2, LOC Also called as “Direct mode” in some assembly languages 19

Addressing Modes: Indirection and Pointers Indirect mode: the effective address of the operand is the contents of a register or memory location whose address appears in the instruction Indirection is denoted by placing the name of the register or the memory address given in the instruction in parentheses The register or memory location that contains the address of an operand is called a pointer E.g. Move R1, (R2): in this case R2 contains the address of the operand to be loaded in R1 20

Register Indirect Addressing Diagram 21

Addressing Modes: Indexing and Arrays Index mode the effective address of the operand is generated by adding a constant value to the contents of a register The index mode is useful in dealing with lists and arrays We denote the Index mode symbolically as X(Ri), where X denotes the constant value (offset) contained in the instruction and Ri is the name of the register involved. The effective address of the operand is given by EA=X+(Ri). E.g. Move R1, X(R2): in this case X+R2 represents the address of the operand to be loaded in R1 22

Instruction types Computer instructions must be capable of performing 4 types of operations. 1. Arithmetic and logic operations: E.g., addition, subtraction, comparison between two numbers. 2. Data transfer/movement between memory and processor registers. E.g., memory read, memory write 3. Program sequencing and flow of control: Branch instructions (decisions and loops) 4. Input/output transfers: to transfer data to and from the real world. 23

MIPS Arithmetic operations MIPS assembly language notation for arithmetic operations: operation destination, source1, sourse2 Each MIPS arithmetic instruction performs only one operation Each MIPS arithmetic instruction must have exactly three operands Operand order is fixed (destination first) The words to the right of the sharp symbol (#) are comments Comments always terminate at the end of a line 24

Exercise (1) Write a MIPS assembly code that places the sum of the four integer variables b, c, d, and e into integer variable a, then subtracts integer variable f from a and puts the result in integer variable g C code: a = b + c + d + e; g = a - f; 25

Exercise (1) Sol. C code: a = b + c + d + e; g = a - f; MIPS code: add a, b, c # b + c → a add a, a, d # a + d → a add a, a, e # a + e → a sub g, a, f # a - f → g 26

MIPS Operands In MIPS, arithmetic instructions’ operands must be registers MIPS has only 32 registers (limited number!) For MIPS, a word is 32 bits (or 4 bytes) MIPS registers hold 32 bits of data (a word size) MIPS is a general-purpose register architecture MIPS registers are general-purpose registers (GPRs) MIPS registers can be used for addresses or data with any instruction It is the compiler’s job to associate program variables with registers 27

MIPS Registers 28

Exercise (2) The following C statements contain the six integer variables e, f, g, h, i, j: f = (g + h) - (i + j); e = f; Suppose that the compiler associates variables e, f, g, h, i, and j with registers $s0 through $s5, respectively What is the compiled MIPS assembly code? 29

Exercise (1) Sol. C code: f = (g + h) - (i + j); e = f; MIPS code: add $t0, $s2, $s3 # $t0 is a temporary register add $t1, $s4, $s5 # $t1 is a temporary register sub $s1, $t0, $t1 add $s0, $s1, $zero # copy f ($s1) to e ($s0) 30

Data Transfer Instructions Data transfer instructions: transfer data between memory and registers load word (lw): copies a word from memory to a register store word (sw): copies a word from a register to memory lw $s0, c ($s1) # Memory [$s1 + c] → $s0 sw $s0, c ($s1) # $s0 → Memory [$s1 + c] $s1 is the Index (base) register constant c is the offset MIPS memory is only accessed through loads and stores 31

Exercise (3) Registers $s1 and $s2 of a computer contain the decimal values 1200 and What is the effective address of the memory operand in each of the following instructions? And explain their action. lw $S4,20($S1) sw$S5, 1000($S2) 32

Exercise (3) Sol. For the instruction: lw $S4,20($S1) The address is: =1220 it reads the word in the memory location 1220 and loads it in the register $s4 For the instruction: sw $S5, 1000($S2) The address is: =5600 it writes the word in the register $s5 to the memory location 5600 and loads it in 33

Exercise (4) Lets also assume that the base address of the integer array d is in register $s4 and a value is in register $s1 Compile the following C statement into MIPS assembly code: d[3] = d[2] + a; 34

Exercise (4) Sol. C code: d[3] = d[2] + a; MIPS code: lw $t0, 8($s4) # Memory [$s4 + 2*4] → $t0 add $t0, $t0, $s1 # $t0= $t0+ $t1 sw $t0, 12($s4) # $t0 → Memory [$s4 + 3*4] 35

Exercise (5) Lets assume that the compiler has associated integer variables h and i with registers $s2 and $s4, respectively Lets also assume that the base address of the integer array A is in register $s3 Compile the following C statement into MIPS assembly code: A[i] = h + A[8]; 36

Exercise (5) Sol. C code: A[i] = h + A[8]; MIPS code: lw $t0, 32 ($s3) # Memory [$s3 + 8*4] → $t0 add $t0, $s2, $t0 # h + A[8] → $t0 add $t1, $s4, $s4 # $t1 = 2*i add $t1, $t1, $t1 # $t1 = 4*i add $t1, $t1, $s3 # $t1 = $s3 + 4*i (address of A[i]) sw $t0, 0 (t1) # $t0 → Memory [$t1] 37