Chapter 11. Addressing Modes

Similar documents
Addressing Modes. Outline

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

Assembly Language Each statement in an assembly language program consists of four parts or fields.

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Addressing Modes on the x86

Chapter 3: Addressing Modes

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Assembler Programming. Lecture 2

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

ADDRESSING MODES. Operands specify the data to be used by an instruction

Complex Instruction Set Computer (CISC)

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

The Instruction Set. Chapter 5

EEM336 Microprocessors I. Addressing Modes

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-11: 80x86 Architecture

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Basic Execution Environment

Introduction to IA-32. Jo, Heeseung

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

INTRODUCTION TO IA-32. Jo, Heeseung

Load Effective Address Part I Written By: Vandad Nahavandi Pour Web-site:

History of the Intel 80x86

Low Level Programming Lecture 2. International Faculty of Engineerig, Technical University of Łódź

Hardware and Software Architecture. Chapter 2

x86 Assembly Tutorial COS 318: Fall 2017

The x86 Architecture

Assembly Language Lab # 9

Reverse Engineering II: The Basics

MICROPROCESSOR ARCHITECTURE

A4 Sample Solution Ch3

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Machine and Assembly Language Principles

The Microprocessor and its Architecture

MICROPROCESSOR TECHNOLOGY

CS241 Computer Organization Spring 2015 IA

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

T Reverse Engineering Malware: Static Analysis I

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

UMBC. 1 (Feb. 9, 2002) seg_base + base + index. Systems Design & Programming 80x86 Assembly II CMPE 310. Base-Plus-Index addressing:

Chapter Three Addressing Mode MOV AX, BX

Machine Code and Assemblers November 6

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee

MICROPROCESSOR TECHNOLOGY

Credits and Disclaimers

Module 3 Instruction Set Architecture (ISA)

IA32 Intel 32-bit Architecture

An Introduction to x86 ASM

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Experiment 8 8 Subroutine Handling Instructions and Macros

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

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

Reverse Engineering II: The Basics

iapx Systems Electronic Computers M

Computer Architecture 1 ح 303

Advanced Microprocessors

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Assembly Language Programming Introduction

IA32/Linux Virtual Memory Architecture

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Tutorial 10 Protection Cont.

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

HLA v2.0 Intermediate Code Design Documentation

Credits and Disclaimers

Processes and Tasks What comprises the state of a running program (a process or task)?

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 2: IA-32 Processor Architecture Included elements of the IA-64 bit

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 4: Data Movement Instructions. 4 1 MOV Revisited

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 03, SPRING 2013

6/17/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

SYSC3601 Microprocessor Systems. Unit 2: The Intel 8086 Architecture and Programming Model

Assembly Language. Lecture 2 x86 Processor Architecture

W4118: PC Hardware and x86. Junfeng Yang

CS 16: Assembly Language Programming for the IBM PC and Compatibles

Chapter 2: The Microprocessor and its Architecture

3- ADDRESSING MODES in 8086: In this section we use the MOV instruction to describe the data-addressing modes. Figure 3-1 shows the MOV instruction.

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Ethical Hacking. Assembly Language Tutorial

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

EEM336 Microprocessors I. The Microprocessor and Its Architecture

Systems Architecture I

Computer System Architecture

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

Lab 4: Basic Instructions and Addressing Modes

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

appendix b From LC-3 to x86

Writing 32-Bit Applications

Project 1: Bootloader. COS 318 Fall 2015

Memory Models. Registers

MICROPROCESSOR ALL IN ONE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

Transcription:

Chapter 11 Addressing Modes 1

2 Chapter 11 11 1 Register addressing mode is the most efficient addressing mode because the operands are in the processor itself (there is no need to access memory).

Chapter 11 3 11 2 Immediate addressing mode can be used to specify constants; thus, it cannot be used to specify the destination operand of an instruction.

4 Chapter 11 11 3 Operand specified by the immediate addressing mode is part of the instruction and therefore is in the code segment.

Chapter 11 5 11 4 Note that to locate a data item in a data segment, we need to specify two components: the data segment base address and an offset value within the segment. In direct addressing mode, the offset is specified directly as part of the instruction. This addressing mode is the simplest of all the memory addressing modes. The direct addressing can be used to access simple variables. The main drawback of this addressing mode is that it is not useful for accessing complex data structures such as arrays and records that are used in high-level languages. The indirect addressing mode remedies this deficiency. In this addressing mode, offset of the data is in one of the general registers. For this reason, this addressing mode is sometimes called the register indirect addressing mode. For 16-bit segments, only BX, BP, SI, and DI registers are allowed to hold the offset. The 16-bit memory addressing modes supported are shown in the following figure: Memory Direct [disp] Indirect Register Indirect [BX] [BP] [SI] [DI] Based [BX + disp] [BP + disp] Indexed [SI + disp] [DI + disp] Based-Indexed with no displacement [BX + SI] [BP + SI] [BX + DI] [BP + DI] Based-Indexed Based-Indexed with displacement [BX + SI + disp] [BX + DI + disp] [BP + SI + disp] [BP + DI + disp]

6 Chapter 11 11 5 The Pentium supports a more flexible set of memory addressing modes for 32-bit addresses (shown in the following figure). Addressing Modes Register Immediate Memory Direct [disp] Indirect Register Indirect [Base] Based [Base + disp] Indexed [(Index * scale) + disp] Based-Indexed Based-Indexed with no scale factor [Base + Index + disp] Based-Indexed with scale factor [Base + (Index * scale) + disp] As shown in this figure, for 32-bit segments, all eight 32-bit registers (i.e., EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP) can be used. A summary of these memory addressing modes is given below: Segment + Base + (Index * Scale) + displacement CS EAX EAX 1 No displacement SS EBX EBX 2 8-bit displacement DS ECX ECX 4 32-bit displacement ES EDX EDX 8 FS ESI ESI GS EDI EDI EBP EBP ESP

Chapter 11 7 11 6 Segment override prefix is necessary to assign non-default segment association. For example, if the offset in BX refers to a data item on the stack, we need to use segment override to specify this fact as shown below: add AX,SS:[BX] We can use this code to access a data item from the stack whose offset relative to the SS register is given in the BX register. Similarly, the BP register can be used as an offset into the data segment by add AX,DS:[BP] The CS, ES, FS, and GS segment registers can also be used to override the default association, even though the CS register is not used frequently.

8 Chapter 11 11 7 Operand override prefix is necessary when 16- and 32-bit operands are mixed in a program. When the default is 16-bit operands, if we use a 32-bit operand, as in mov EAX,123 the following code is generated by the assembler: 66 B8 0000007B The assembler automatically inserts the operand size override prefix (66H).

Chapter 11 9 11 8 Address size override prefix is necessary when mixed address sizes are used in a program. The greatest benefit of the address size override prefix is that we can use all the addressing modes provided for 32-bit addresses in the 16-bit addressing modes. For instance, we can use a scale factor, as in the following example: mov AX,[EBX+ESI*2] The assembler automatically inserts the address size override prefix (67H) as shown below: 67 8B 04 73

10 Chapter 11 11 9 Real mode: No difference. Protected mode: Indexed addressing allows the scale factor, which is useful in accessing arrays of element size 2, 4, and 8 bytes.

Chapter 11 11 11 10 Based-indexed addressing is more flexible as it allows us to use two registers (a base register and an index register) to specify the effective address. This facilitates, for example, in accessing two-dimensional arrays, arrays of records, etc.

12 Chapter 11 11 11 The code is shown below: mov SI, 8 ; SI = displacement of 5th element ; (i.e., table1[4] in C) mov AX,table1[SI] cmp AX,table1[SI-2]; compare 5th and 4th elements

Chapter 11 13 11 12 In row-major ordering, arrays are stored row-by-row whereas in the column-major ordering, the layout is column-by-column as shown in the following figure (for a 4 4 matrix class_marks): High memory High memory class_marks[4,2] class_marks[4,2] class_marks[4,1] class_marks[3,2] class_marks[4,0] class_marks[2,2] class_marks[3,2] class_marks[1,2] class_marks[3,1] class_marks[0,2] class_marks[3,0] class_marks[4,1] class_marks[2,2] class_marks[3,1] class_marks[2,1] class_marks[2,1] class_marks[2,0] class_marks[1,1] class_marks[1,2] class_marks[0,1] class_marks[1,1] class_marks[4,0] class_marks[1,0] class_marks[3,0] class_marks[0,2] class_marks[2,0] class_marks[0,1] class_marks[1,0] class_marks class_marks[0,0] class_marks class_marks[0,0] Low memory Low memory (a) Row-major order (b) Column-major order

14 Chapter 11 11 13 High-level languages provide data structures for multidimensional arrays. However, assembly language does not provide such facilities. Therefore, it is necessary to specify a pointer to the element you want to access. Obviously, to do this, you need to know how the data is stored.

Chapter 11 15 11 14 Row-major order as the program specifies the values row-by-row and the assembler uses the same order to allocate storage.

16 Chapter 11 11 15 The following stores class_marks in column-major order: class_marks DW 90,79,70,60,51 DW 89,66,60,55,59 DW 99,70,77,68,57

Chapter 11 17 11 16 Displacement in bytes = (j * ROWS + i) * ELEMENT_SIZE where ROWS is the number of rows and ELEMENT_SIZE is the size of each element in bytes.

18 Chapter 11 11 17 Assume that X and Y are the low subscripts for the first and second dimensions, respectively. We can modify the formula given on page 451 as Displacement in bytes = ((i - X) * COLUMNS + (j - Y)) * ELEMENT_SIZE where COLUMNS is the number of columns in the array and ELEMENT_SIZE is the number of bytes required to store an element.