Address Modes effective address

Similar documents
Problem with Scanning an Infix Expression

The MARIE Architecture

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats

Computer Architecture and Organization. Instruction Sets: Addressing Modes and Formats

Addressing Modes. Immediate Direct Indirect Register Register Indirect Displacement (Indexed) Stack

Chapter 2 Instruction Set Architecture

CDA 3103 Computer Organization Homework #7 Solution Set

Notes: The Marie Simulator

Lecture V Toy Hardware and Operating System

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

CHAPTER 8: Central Processing Unit (CPU)

94 CPU (CM8051) Incompatible Instruction ERRATA AND DATASHEET CLARIFICATION V1.0. Leader of Microcontroller Technology A Fabless Semiconductor Company

CS401 Assembly Language Solved MCQS From Midterm Papers

Department of Computer and Mathematical Sciences. Lab 4: Introduction to MARIE

Computer Organization II CMSC 3833 Lecture 33

Chapter 11. Instruction Sets: Addressing Modes and Formats. Yonsei University

Computer Organization CS 206 T Lec# 2: Instruction Sets

This simulated machine consists of four registers that will be represented in your software with four global variables.

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

Machine code. Nils Jansen December 12, 2017

We briefly explain an instruction cycle now, before proceeding with the details of addressing modes.

Parsing Scheme (+ (* 2 3) 1) * 1

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Chapter 5. A Closer Look at Instruction Set Architectures

MARIE: An Introduction to a Simple Computer

Instruction Sets: Characteristics and Functions Addressing Modes

CHAPTER 5 A Closer Look at Instruction Set Architectures

Chapter 4. MARIE: An Introduction to a Simple Computer

Virtual Machine Tutorial

CC312: Computer Organization

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

add R1,x add R1,500 add R1,[x] The answer is: all of these instructions implement adding operation on R1 and all of them have two addresses.

Problem with Scanning an Infix Expression

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label

Chapter. Computer Architecture

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

Virtual machines. Virtual machines. Abstractions for computers. Abstractions for computers. Virtual machines

Understand the factors involved in instruction set

OSIAC Read OSIAC 5362 posted on the course website

Chapter 14 Design of the Central Processing Unit

ENGR 2031 Digital Design Laboratory Lab 7 Background

COMPUTER ORGANIZATION & ARCHITECTURE

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

CHAPTER 5 A Closer Look at Instruction Set Architectures

8051 Addressing Modes

Chapter 3 Machine Instructions & Programs. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Addressing Modes. To review data transfer instructions and applying the more advanced addressing modes.

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

Lecture 04: Machine Instructions

Slides for Lecture 6

Instruction Set Architecture

EEL 5722C Field-Programmable Gate Array Design

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture

CPU Structure and Function. Chapter 12, William Stallings Computer Organization and Architecture 7 th Edition

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

Chapter 4. Chapter 4 Objectives. MARIE: An Introduction to a Simple Computer

Computing Layers. Chapter 5 The LC-3

The Instruction Set. Chapter 5

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

Architecture Project Phase (1)

CPSC 121: Models of Computation. Module 10: A Working Computer

Lecture-12 INTERNAL ARCHITECTURE OF INTEL 8085: The Functional Block Diagram Of 8085 Is Shown In Fig 16.

COMP1917 Computing 1 Written Exam Sample Questions

Lecture 7: Primitive Recursion is Turing Computable. Michael Beeson

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

Computer Architecture 1 ح 303

Fortunately not. In LC-3, there are a variety of addressing modes that deal with these concerns.

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points]

Expectations. Why learn Assembly Language? Administrative Issues. Assignments. CSC 3210 Computer Organization and Programming

Systems I. Machine-Level Programming V: Procedures

Syntax of LC-3 assembly: Language elements. Instructions

Microcontroller. Instruction set of 8051

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

CS311 Lecture: The Architecture of a Simple Computer

x64 Windows Debugging

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

PACE figforth Implementation

MARIE: An Introduction to a Simple Computer

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Computer Architecture /

Microcontroller Intel [Instruction Set]

MOS 6502 Architecture

CHAPTER SIX BASIC COMPUTER ORGANIZATION AND DESIGN

COSC121: Computer Systems: Review

Lecture 4: Instruction Set Architecture

CS 3330 Exam 1 Fall 2017 Computing ID:

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

2.2 THE MARIE Instruction Set Architecture

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

LECTURE 17. Expressions and Assignment

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

Chapter 7 Assembly Language

Transcription:

Address Modes The MARIE supports only three addressing modes: immediate, direct, and indirect. We are now going to discuss addressing modes in general. Most computers support quite a few of these modes. We shall discuss both direct and indirect addressing. We begin with the idea of an effective address, or EA. This is the address in memory of the actual operand (variable) used in the operation. We use the term EA loosely when it is not strictly appropriate, as in the following three addressing modes, none of which reference memory at all. Immediate mode addressing Register addressing Stack addressing. We begin by jumping ahead and discussing direct addressing. We then use this to define and illustrate the three addressing modes mentioned above.

Direct and Immediate Addressing The MARIE supports a Add instruction, with opcode 0011 = 0x3 It also supports Add Indirect, with opcode 1011 = 0xB. The expanded version supports Add Immediate, with opcode 1110 = 0xE. Consider the following memory map (Figure 5.3 in the textbook). Let the AC = 50. Let X have the value 0x800 and assume the table uses hexadecimal addresses. Add X 0x3800 // Go to address 800 and add its contents to the AC. // The value of the AC is now 950. AC (AC) + M[X] AddM X 0xE800 // Add the value 800 to the AC. AC (AC) + X 98% of Load Immediate and Add Immediate use the values 1, 0, and + 1.

Stack and Register Addressing In stack addressing, the operands are on the stack. We illustrate. Push A // Direct addressing. A is the address of the value to be pushed. Push B // Direct addressing. B is the address of the value to be pushed. Add // Stack addressing. Values to be added are on the stack. Pop C // Again, this is direct addressing. Place result in address C. In register addressing, the operands are in registers. We illustrate this mode using notation for a Load Store RISC machine with two registers: R1 and R2. Load R1, A // Direct addressing. A is the address of the value to be // loaded into register R1. Use of a register does not change this. Load R2, B // Again direct addressing, even if the value goes into a register. Add R1, R2 // Register addressing. Values to be added are in the registers. Store R1, C // Again, this is direct addressing.

Calculation of Effective Address We now step back and think about how to calculate an effective address. Having done this, we return to direct addressing and see how it fits in. Again, we are speaking about computers in general. This is not an issue for the MARIE. We begin with the format of a generic instruction referencing memory Opcode Register Address Mode Address Fields Flags Field In general, the only parts of the instruction that are used in computing the EA are the Address Field this contains an address, which may be modified. the Mode Flags these indicate how to modify the given address in order to compute the EA (Effective Address). the Register Fields used in indexed addressing and in register indirect. The order of the fields shown here is generic and probably does not apply to all computers.

No Addressing We first handle the very simple case in which the operator does not use an address. The MARIE has several such instructions: Input, Output, Halt, and Clear. The opcode for Halt is binary 0000 or hexadecimal 0. The machine code for a halt would be written as 0000, as it needs 4 hexadecimal digits. Question: What is the address associated with the machine code 0000? Answer: There is none. The instruction does not use an address. Question: What is the address associated with the machine code 0777? Answer: Note: There is none. The instruction does not use an address. One wonders how the last three hexadecimal digits were set, but they are ignored. One might view this as a variant of immediate mode addressing, but such an approach is probably not helpful.

Direct and Indirect Addressing Opcode Registers Mode Flags Address Field In each of direct and indirect addressing, the computation is simple: Just copy the address field itself. In direct addressing, the address field contains the address of the argument. In indirect addressing, the address field contains the address of a pointer to the argument. Put another way, the contents of the memory indicated by the address field contain the address of the argument.

Direct and Indirect Addressing (Example) Consider again the memory map taken from the textbook. Let X refer to the value 0x800. Load X this loads the AC from address 0x800. The value 900 goes into the AC. EA = X AC M[X] Load Indirect X Go to address 0x800. Its contents are 0x900. Load the AC from address 0x900. The value 1000 goes into the AC. EA = M[X] AC M[ M[X] ] NOTE: The complexity of notation such as AC M[ M[X] ] is one reason we use the Effective Address idea. Break the address computation into small steps.

Register and Register Indirect Addressing Opcode Registers Mode Flags Address Field In each of register and register indirect addressing, the address field is ignored. Conventionally, it is set at all zeroes. In register addressing, a general purpose register contains the argument. In register indirect addressing, a general purpose register contains the address of the argument. The MARIE does not support either addressing mode.

Register and Register Indirect Addressing (Example) Consider again the memory map taken from the textbook. We assume the MARIE has an AC and a register R1. Assume (R1) = 0x800. Register addressing: Load AC, R1 The accumulator is loaded from the register. AC = 0x800 AC (R1) Register Indirect addressing The accumulator is loaded from the address pointed to by the register. Here AC = 0x900. AC M[ (R1) ], the memory addresses by the contents of R1.

Indexed Addressing This is used to support array addressing in all computers. Languages such as C and C++ implement this directly using zero based arrays. The contents of the register are added to the address field to form the effective address. EA = (Address Field) + (Register)

Indexed Addressing (Example) Consider again the memory map taken from the textbook. We assume the MARIE has an AC and one registers: R1. Use R1 in the address calculations. Suppose X = 0x200. Load X[R1] // Syntax is made up to look reasonable. AC is loaded. EA = X + (R1) = 0x200 + 0x800 = 0xA00. AC M[0xA00], whatever that is.

Another Indexed Addressing Example Suppose now that X refers to address 0x800 and that register R1 contains a small number, say (R1) = 0x02. Consider the instruction Load X[R1] The effective address is EA = X + (R1) = 0x800 + 0x02 = 0x802. This can be viewed as X[2] where X is a zero based array. Its memory layout appears similar to the figure below. Memory Map 0x800 0x801 0x802 0x803 X[0] X[1] X[2] X[3]

Indexed Indirect Addressing This is a combination of both modes. Question: Which is done first. Preindexed indirect. The indexing is done first. We have an array of pointers. Postindexed indirect. The indirect is done first. We have a pointer to an array.

Sample Problem (from CPSC 5155) This question references the following memory map. Address 10 11 12 13 14 15 Contents 13 7 4 86 46 77 If the symbol X stands for address 12 and (%R6) == 1, what is the effective address for a) STR %R2, X direct addressing b) STR %R2, *X indirect addressing c) STR %R2, X, 6 indexed by register %R6. d) STR %R2, *X, 6 pre-indexed indirect, indexed by %R6. Analysis: First a few comments on the problem and then we start. 1. Question: Are the addresses decimal or hexadecimal? Answer: This is ambiguous, but not important. We need to compute (12 1), which is 11 in each of decimal and hexadecimal. 2. Question: What does STR do? Answer: We don t care. We just want the address.

Sample Problem (Page 2) Address 10 11 12 13 14 15 Contents 13 7 4 86 46 77 The symbol X stands for address 12 and (%R6) == 1, a) STR %R2, X direct addressing The label X refers to address 12. In direct addressing that is the address. EA = 12. PLEASE NOTE: The contents of address 12 are 4; M[12] == 4. In a higher level language, we would say X is 4, because the memory location contains that value. In this context, we say X references the address 12. b) STR %R2, *X indirect addressing The label X refers to address 12. For indirect addressing, the address is M[X], here M[12] or 4. Note that contents of address 4 are not specified. However, EA = 4.

Sample Problem (Page 3) Address 10 11 12 13 14 15 Contents 13 7 4 86 46 77 The symbol X stands for address 12 and (%R6) == 1, c) STR %R2, X, 6 indexed by register %R6. The effective address is X + (%R6), which is 12 + ( 1) or 12 1 = 11. EA = 11. NOTE: Do not add the contents of the address associated with X. This would be another addressing mode. d) STR %R2, *X, 6 pre-indexed indirect, indexed by %R6. The effective address is M[X + (%R6)]. Do the indexing first. X + (%R6) is 12 + ( 1) = 12 1 = 11. The effective address is M[11] = 7. EA = 7.