Operands and Addressing Modes

Similar documents
Operands and Addressing Modes

Operands and Addressing Modes

Compilers and Interpreters

Compilers and Interpreters

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Chapter 2. Instructions:

Chapter 3. Instructions:

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Topic Notes: MIPS Instruction Set Architecture

Chapter 2: Instructions:

Lecture 4: MIPS Instruction Set

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Chapter 2. Instruction Set Architecture (ISA)

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Instruction Set Architecture. "Speaking with the computer"

The MIPS Instruction Set Architecture

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

CS222: MIPS Instruction Set

Designing an Instruction Set

Computer Architecture

CS/COE1541: Introduction to Computer Architecture

CS 61c: Great Ideas in Computer Architecture

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

MIPS%Assembly% E155%

Mips Code Examples Peter Rounce

Reduced Instruction Set Computer (RISC)

Designing an Instruction Set

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

ECE 30 Introduction to Computer Engineering

ECE232: Hardware Organization and Design

CS3350B Computer Architecture MIPS Instruction Representation

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

ECE260: Fundamentals of Computer Engineering

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

Reduced Instruction Set Computer (RISC)

CS3350B Computer Architecture

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Concocting an Instruction Set

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

MIPS Coding Continued

ECE260: Fundamentals of Computer Engineering

Lectures 3-4: MIPS instructions

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

Instruction encoding. MIPS Instruction encoding

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Unsigned Binary Integers

Unsigned Binary Integers

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

CSE 378 Midterm 2/12/10 Sample Solution

Instruction Set Architectures

Instructions: Assembly Language

Instructions: Language of the Computer

Computer Architecture

Systems Architecture I

Computer Architecture. The Language of the Machine

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

Lecture 4: Instruction Set Architecture

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Communicating with People (2.8)

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

Computer Architecture. MIPS Instruction Set Architecture

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

ECE 15B Computer Organization Spring 2011

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

CS3350B Computer Architecture Quiz 3 March 15, 2018

MACHINE LANGUAGE. To work with the machine, we need a translator.

Examples of branch instructions

EEC 581 Computer Architecture Lecture 1 Review MIPS

ECE369. Chapter 2 ECE369

Instructions: Language of the Computer

MIPS (SPIM) Assembler Syntax

Course Administration

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

CS3350B Computer Architecture MIPS Introduction

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Chapter 2A Instructions: Language of the Computer

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

EE108B Lecture 3. MIPS Assembly Language II

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Concocting an Instruction Set

Thomas Polzer Institut für Technische Informatik

Transcription:

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

Last Time - Machine Language 32-bit (4-byte) ADD instruction: 00000 0 00 100 00 0 1 0 000 1 1 op = R-type Rs Rt Rd 00000100000 func = add Means, to MIPS, Reg[3] = Reg[4] + Reg[2] But, most of us would prefer to write add $3, $4, $2 (ASSEMBLER) or, better yet, a = b+c; (C) L5 Addressing Modes 2

Revisiting Operands Operands the variables needed to perform an instruction s operation Three types in the MIPS ISA: Register: add $2, $3, $4 # operands are the Contents of a register Immediate: addi $2,$2,1 # 2 nd source operand is part of the instruction Register-Indirect: lw $2, 12($28) # source operand is in memory sw $2, 12($28) # destination operand is memory Simple enough, but is it enough? L5 Addressing Modes 3

Common Addressing Modes MIPS can do these with appropriate choices for Ra and const Absolute: lw $8, 0x1000($0) Value = Mem[constant] Use: accessing static data 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) Argh! Is the complexity worth the cost? Need a cost/benefit analysis! L5 Addressing Modes 4

From Hennessy & Patterson Memory Operands: Usage Usage of different memory operand modes L5 Addressing Modes 5

Absolute Addressing What we want: The contents of a specific memory location Examples: Caveats C int x = 10; main() { x = x + 1; MIPS Assembly.data.global x x:.word 10 In practice $gp is used instead of $0.text.global main main: lw $2,x($0) addi $2,$2,1 sw $2,x($0) Can only address the first and last 32K of memory this way Sometimes generates a two instruction sequence: lui $1,xhighbits lw $2,xlowbits($1) L5 Addressing Modes 6

What we want: Indirect Addressing The contents of a memory location held in a register Examples: C int x = 10; main() { int *y = &x; *y = 2; MIPS Assembly.data.global x x:.word 10.text.global main main: la $2,x addi $3,$0,2 sw $3,0($2) la is not a real instruction, It s a convenience pseudoinstruction that constructs a constant via either a 1 instruction or 2 instruction sequence ori $2,$0,x lui $2,xhighbits ori $2,$2,xlowbits Caveats You must make sure that the register contains a valid address (double, word, or short aligned as required) L5 Addressing Modes 7

Displacement Addressing What we want: The contents of a memory location relative to a register Examples: C int a[5]; main() { int i = 3; a[i] = 2; MIPS Assembly.data.global a a:.space 20.text.global main main: addi $2,$0,3 addi $3,$0,2 sll $1,$2,2 sw $3,a($1) Caveats Must multiply (shift) the index to be properly aligned L5 Addressing Modes 8

Displacement Addressing: Once More What we want: The contents of a memory location relative to a register Examples: C struct p { int x, y; MIPS Assembly.data.global p p:.space 8 Caveats main() { p.x = 3; p.y = 2;.text.global main main: la $1,p addi $2,$0,3 sw $2,0($1) addi $2,$0,2 sw $2,4($1) Constants offset to the various fields of the structure Structures larger than 32K use a different approach L5 Addressing Modes 9

Conditionals C code: if (expr) { STUFF MIPS assembly: (compute expr in $rx) beq $rx, $0, Lendif (compile STUFF) Lendif: C code: if (expr) { STUFF1 else { STUFF2 MIPS assembly: Lelse: (compute expr in $rx) beq $rx, $0, Lelse (compile STUFF1) beq $0, $0, Lendif (compile STUFF2) Lendif: There are little tricks that come into play when compiling conditional code blocks. For instance, the statement: if (y > 32) { x = x + 1; compiles to: lw $24, y ori $15, $0, 32 slt $1, $15, $24 beq $1, $0, Lendif lw $24, x addi $24, $24, 1 sw $24, x Lendif: L5 Addressing Modes 10

Loops C code: while (expr) { STUFF MIPS assembly: Lwhile: Lendw: (compute expr in $rx) beq $rx,$0,lendw (compile STUFF) beq $0,$0,Lwhile Alternate MIPS assembly: beq $0,$0,Ltest Lwhile: (compile STUFF) Ltest: Lendw: (compute expr in $rx) bne $rx,$0,lwhile Compilers spend a lot of time optimizing in and around loops. - moving all possible computations outside of loops - unrolling loops to reduce branching overhead - simplifying expressions that depend on loop variables L5 Addressing Modes 11

For Loops Most high-level languages provide loop constructs that establish and update an iteration variable, which is used to control the loop s behavior C code: int sum = 0; int data[10] = {1,2,3,4,5,6,7,8,9,10; MIPS assembly: sum:.word 0x0 data:.word 0x1, 0x2, 0x3, 0x4, 0x5.word 0x6, 0x7, 0x8, 0x9, 0xa int i; for (i=0; i<10; i++) { sum += data[i] add $30,$0,$0 Lfor: lw $24,sum($0) sll $15,$30,2 lw $15,data($15) addu $24,$24,$15 sw $24,sum add $30,$30,1 slt $24,$30,10 bne $24,$0,Lfor Lendfor: L5 Addressing Modes 12

Next Time We ll write some real assembly code Play with a simulator Bring your Laptops! L5 Addressing Modes 13