These are slides from Comp411

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

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.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
L5 – Addressing Modes 1 Comp 411 – Spring /29/08 Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
Computer Organization
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
©These slides may be freely used, distributed, and incorporated into other works. 1 Addressing Modes For speed… we want fixed-size instructions, and they.
Computer Organization and Design Addressing Modes Montek Singh Wed, Sep 19, 2012 Lecture 6.
Computer Organization and Design Addressing Modes Montek Singh Sep 30, 2015 Lecture 7.
Computer Organization Instructions Language of The Computer (MIPS) 2.
ECE 15B Computer Organization Spring 2011 Dmitri Strukov Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy,
Addressing Modes and Formats
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
Displacement (Indexed) Stack
CS/COE 0447 (term 2181) Jarrett Billingsley
MIPS Instruction Set Advantages
A Closer Look at Instruction Set Architectures
Computer Organization and Design Instruction Sets - 2
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
Computer Organization and Design Instruction Sets - 2
COMP2121: Microprocessors and Interfacing
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
A Closer Look at Instruction Set Architectures: Expanding Opcodes
William Stallings Computer Organization and Architecture 8th Edition
Computer Organization and Design Instruction Sets
ECE/CS 552: Instruction Sets – MIPS
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CSCI206 - Computer Organization & Programming
CSCI206 - Computer Organization & Programming
Systems Architecture Lecture 5: MIPS Instruction Set
Computer Organization and Design Addressing Modes
Henk Corporaal TUEindhoven 2010
ECE232: Hardware Organization and Design
Operands and Addressing Modes
Instruction encoding The ISA defines Format = Encoding
Computer Organization and Design Assembly & Compilation
Computer Architecture
Instruction encoding The ISA defines Format = Encoding
COMP541 Datapaths I Montek Singh Mar 18, 2010.
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
Instruction Set Principles
Instruction encoding The ISA defines Format = Encoding
MIPS Coding Continued.
Evolution of ISA’s ISA’s have changed over computer “generations”.
Addressing Modes Don Porter.
Computer Organization and Design Addressing Modes
Operands and Addressing Modes
9/27: Lecture Topics Memory Data transfer instructions
Evolution of ISA’s ISA’s have changed over computer “generations”.
Presentation transcript:

These are slides from Comp411 For Comp541 projects, we are using different address ranges for instruction and data memories. Please be sure to use: “Default” as Memory Configuration in MARS Settings .data 0x10010000 .text 0x00400000

Computer Organization and Design Addressing Modes Montek Singh Oct 4, 2017 Lecture 7

Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection

Review the Lab 4 slide supplement: Pointers, Arrays and Strings in C Please Review Review the Lab 4 slide supplement: Pointers, Arrays and Strings in C

Addressing Modes What are all of the different ways to specify operands? Operands = the variables needed to perform an instruction’s operation Let us look more generally across various CPUs first, then focus on MIPS

Common “Addressing Modes” in various CPUs MIPS can do these with appropriate choices for Reg and const Absolute (Direct): lw $8, 0x1000($0) Value = Mem[constant] Use: accessing static data Register-Indirect: lw $8, 0($9) Value = Mem[Reg[x]] Use: pointer accesses Displacement: lw $8, 16($9) Value = Mem[Reg[x] + constant] Use: access to local variables Indexed: Value = Mem[Reg[x] + Reg[y]] Use: array accesses (base+index) Memory indirect: Value = Mem[Mem[Reg[x]]] Use: access thru pointer in mem Autoincrement: Value = Mem[Reg[x]]; Reg[x]++ Use: sequential pointer accesses Autodecrement: Value = Reg[X]--; Mem[Reg[x]] Use: stack operations Scaled: Value = Mem[Reg[x] + c + d*Reg[y]] Use: array accesses (base+index) Is the complexity worth the cost? Need a cost/benefit analysis!

Revisiting Operands in MIPS Operands = the variables needed for operation Three types in the MIPS ISA: Register: add $2, $3, $4 # operands are the “contents” of a register Immediate: addi $2,$2,1 # 2nd source operand is part of the instruction Displacement: lw $2, 12($28) # source operand is in memory sw $2, 12($28) # destination operand is memory 2 special cases of Displacement: Absolute (Direct): when rs is $0 Register-Indirect: when imm is 0 Simple enough, but is it enough?

Relative popularity of address modes Most common ones are Displacement/Absolute (combined under “Displacement” in graph) Register-Indirect Immediate (i.e., constants within instructions) (graduate architecture book) From Hennessy & Patterson

Absolute (Direct) Addressing What we want: Contents of a specific memory location, i.e. at a given address Example: Caveat: Sometimes generates a two instruction sequence If the address for x chosen by the programmer/compiler/assembler is too large to fit within the 16-bit immediate field “MIPS Assembly” .data x: .word 10 .text main: lw $2,x($0) addi $2,$2,1 sw $2,x($0) Allocates space for a single integer (4-bytes) and initializes its value to 10 “C” int x = 10; main() { x = x + 1; } ‘x’ here means address of x lui $1,xhighbits lw $2,xlowbits($1) e.g., if x is at address 0x12345678 lui $1,0x1234 lw $2,0x5678($1)

Absolute (Direct) Addressing: More detail “MIPS Assembly” .data x: .word 10 .text main: lw $2,x($0) addi $2,$2,1 sw $2,x($0) “After Compilation” .data 0x0100 x: .word 10 .text main: lw $2,0x100($0) addi $2,$2,1 sw $2,0x100($0) “C” int x = 10; main() { x = x + 1; } Assembler replaces “x” by its address e.g., here the data part of the code (.data) starts at 0x100 x is the first variable, so starts at 0x100 this mode works in MIPS only if the address fits in 16 bits

Indirect Addressing What we want: Examples: Caveats The contents at a memory address held in a register Examples: Caveats You must make sure that the register contains a valid address (double, word, or short aligned as required) “la” is not a real instruction, It’s a convenient pseudoinstruction that constructs a constant via either a 1 instruction or 2 instruction sequence “MIPS Assembly” .data x: .word 10 .text main: la $2,x addi $3,$0,2 sw $3,0($2) ori $2,$0,x “C” int x = 10; main() { int *y = &x; *y = 2; } lui $2,xhighbits ori $2,$2,xlowbits $2 performs the role of y, i.e., it is a pointer to x

Note on la pseudoinstruction la is a pseudoinstruction: la $r, x stands for “load the address of” variable x into register r not an actual MIPS instruction but broken down by the assembler into actual instructions if address of x is small (fits within 16 bits), then a single ori one could also use a single addiu if address of x is larger, use the lui + ori combo “MIPS Assembly” .data x: .word 10 .text .global main main: la $2,x addi $3,$0,2 sw $3,0($2) ori $2,$0,0x100 0x0100 0x80000010 lui $2,0x8000 ori $2,$2,0x0010

Displacement Addressing What we want: contents of a memory location at an offset relative to a register the address that is the sum of a constant and a register value Examples: Remember: Must multiply (shift) the “index” to be properly aligned “MIPS Assembly” .data 0x0100 a: .space 20 .text main: addi $2,$0,3 // i in $2 addi $3,$0,2 sll $1,$2,2 // i*4 in $1 sw $3,a($1) “C” int a[5]; main() { int i = 3; a[i] = 2; } Allocates space for a 5 uninitialized integers (20-bytes)

Displacement Addressing: 2nd example What we want: The contents of a memory location at an offset relative to a register Examples: Note: offsets to the various fields within a structure are constants known to the assembler/compiler “MIPS Assembly” .data p: .space 8 .text main: la $1,p addi $2,$0,13 sw $2,0($1) addi $2,$0,12 sw $2,4($1) “C” struct p { int x, y; } main() { p.x = 13; p.y = 12; } Allocates space for 2 uninitialized integers (8-bytes)