Addressing Modes on the x86

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

Hardware and Software Architecture. Chapter 2

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

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

Code segment Stack segment

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

The Microprocessor and its Architecture

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

Assembler Programming. Lecture 2

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

The x86 Architecture

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

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

EC-333 Microprocessor and Interfacing Techniques

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

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

Complex Instruction Set Computer (CISC)

Module 3 Instruction Set Architecture (ISA)

Chapter 3: Addressing Modes

Chapter 11. Addressing Modes

The Instruction Set. Chapter 5

Chapter 2: The Microprocessor and its Architecture

4.0 Chapter Overview. 4.1 The 80x86 CPUs:A Programmer s View

EEM336 Microprocessors I. Addressing Modes

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

Basic Execution Environment

EEM336 Microprocessors I. The Microprocessor and Its Architecture

x86 Assembly Tutorial COS 318: Fall 2017

Intel 8086 MICROPROCESSOR ARCHITECTURE

Basic characteristics & features of 8086 Microprocessor Dr. M. Hebaishy

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

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

icroprocessor istory of Microprocessor ntel 8086:

Intel 8086 MICROPROCESSOR. By Y V S Murthy

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

IA32 Intel 32-bit Architecture

MICROPROCESSOR TECHNOLOGY

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

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

Reverse Engineering II: The Basics

Instruction Set Architecture (ISA) Data Types

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.

Computer Architecture 1 ح 303

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

On 386 and later machines, segment had a size of 64 KB. Therefore, to get the actual physical address, we can calculate it in the following way:

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

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

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

Advanced Microprocessors

1. Introduction to Assembly Language

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

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

Chapter 4: Data Movement Instructions. 4 1 MOV Revisited

8086 INTERNAL ARCHITECTURE

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Moodle WILLINGDON COLLEGE SANGLI (B. SC.-II) Digital Electronics

16.317: Microprocessor Systems Design I Spring 2014

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

CS241 Computer Organization Spring 2015 IA

Chapter Three Addressing Mode MOV AX, BX

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

UNIT 2 PROCESSORS ORGANIZATION CONT.

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

9/25/ Software & Hardware Architecture

Assembly Language Lab # 9

MICROPROCESSOR TECHNOLOGY

Credits and Disclaimers

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

iapx Systems Electronic Computers M

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 Language Programming Introduction

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

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Instruction Set Architectures

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

Introduction to Microprocessor

A4 Sample Solution Ch3

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

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

16.317: Microprocessor Systems Design I Fall 2013

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

CC411: Introduction To Microprocessors

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

System calls and assembler

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

Microprocessor (COM 9323)

Real instruction set architectures. Part 2: a representative sample

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

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

16-Bit Intel Processor Architecture

EEM336 Microprocessors I. Data Movement Instructions

Northern India Engineering College, Delhi (GGSIP University) PAPER I

Addressing Modes. Outline

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

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

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

Transcription:

Addressing Modes on the x86 register addressing mode mov ax, ax, mov ax, bx mov ax, cx mov ax, dx constant addressing mode mov ax, 25 mov bx, 195 mov cx, 2056 mov dx, 1000 accessing data in memory There are three addressing modes which deal with accessing data in memory mov ax, [1000] //direct addressing mov ax, [bx] // indirect addressing mode mov ax, [1000+bx] // indexed addressing

Encoding x86 Instructions To determine a particular instruction s opcode, you need only select the appropriate bits for the iii, rr, and mmm fields. For example, to encode the mov ax, bx iii=110 (mov reg, reg), rr=00 (ax), and mmm=001 (bx). This produces the one-byte instruction 11000001 or 0C1h. Some x86 instructions require more than one byte Example mov ax, [1000] //encoding 11000110 or 0C6h mov=110, ax=00, [1000] 110 //loads Ax from memory location 1000 mov ax, [2000] //encoding 11000110 or 0C6h mov=110, ax=00, [1000] 110 //loads Ax from memory location 1000 The above instructions do different things,

To encode an address for the [xxxx] or [xxxx+bx] addressing modes, or to encode the constant for the immediate addressing mode. Follow the opcode with the 16-bit address or constant, with the L.O. byte immediately following the opcode in memory and the H.O. byte after that. The three byte encoding for mov ax, [1000] would be 0C6h, 00h,10h and opcode r r m m m H.O L.O 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 The three byte encoding for mov ax, [2000] would be 0C6h, 00h, 20h. opcode r r m m m H.O L.O 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

1. expands the instruction set with a set of zero-operand instructions 2. provides all the x86 jump instructions 3. bitwise logical not operation that inverts all the bits in the destination register or memory operand 4. Not assigned

The special opcode allows the x86 CPU to expand the set of available instructions. This opcode handles several zero and one-operand instructions as shown in Figure 3.20 and Figure 3.21.

Memory Layout and Access 8086 Purpose Registers There are eight 16 bit general purpose registers on the 8086: ax, bx, cx, dx, si, di, bp, andsp. can use many of these registers interchangeably in a computation The ax register (Accumulator) I most arithmetic and logical computations take place. most arithmetic and logical operations can be done in other registers More efficient to use the ax register The bx register (Base) has some special purposes It is commonly used to hold indirect addresses The cx register (Count) Counts things. use it to count off the number of iterations in a loop or specify the number of characters in a string. The dx register (Data) has two special purposes: holds the overflow from certain arithmetic operations, holds I/O addresses when accessing data on the 80x86 I/O bus.

8086 Purpose Registers (cont) The si and di registers (Source Index and Destination Index ) have some special purposes You may use these registers as pointers (much like the bx register) to indirectly access memory. these registers used with the 8086 string instructions when processing character strings. The bp register (Base Pointer) is similar to the bx register. generally used to access parameters and local variables in a procedure.

The sp register (Stack Pointer) has a very special purpose Maintains the program stack. Usually not used arithmetic computations. Carefully used

Besides the eight 16 bit registers, the 8086 CPUs also have eight 8 bit registers. Called al, ah, bl, bh, cl, ch, dl, and dh. Changing of al does not effect ah while it affect AX. The si, di, bp, and sp registers are only 16 bits.

8086 Segment Registers Segment: special areas defined to contain CODE, DATA and STACK The 8086 has four special segment registers (16 bits): Cs Code Segment Ds Data Segment Es Extra Segment Ss Stack Segment Stack Segment Data Segment They deal with selecting blocks (segments) of main memory. e.g., cs points at the beginning of a segment in memory. SS DS CS Code Segment

Code segment cs register points at the segment containing the currently executing machine instructions. Limitation to 64k Data segment register, ds, generally points at global variables for the program. limited to 65,536 bytes of data in the data segment; possible to change the value of the ds register to access additional data in other segments. Extra segment register, es, Used to gain access to segments when it is difficult or impossible to modify the other segment registers. Stack Segment ss points at the segment containing the 8086 stack. The stack is where the 8086 stores important machine state information, subroutine return addresses, procedure parameters, and local variables. In general, you do not modify the stack segment register because too many things in the system depend upon it.

8086 Special Purpose Registers accessing these registers is different than the other registers CPU generally manipulates these registers directly. instruction pointer (ip) Contains the address of the currently executing instruction provides a pointer into the current code segment 16 bits allow selection any one of 65,536 2 16 different memory locations. flags register. unlike the other registers on the 8086. The flags register is simply an eclectic collection of one bit values which help determine the current state of the processor.

8086 uses only nine of those bits. 1. Zero, 2. carry, 3. sign, and 4. overflow. These flags are the 8086 condition codes.

80286 Registers The 80286 microprocessor adds one major programmer-visible feature to the 8086 protected mode operation. We shall not cover the 80286 protected mode of operation because the protected mode of the 80286 was poorly designed.

80386/80486 Registers The 80386 processor extended the 8086 register set The 80486 did not add any new registers to the 80386 s basic register set, but it defines a few bits in some registers left undefined by the 80386. The most important change the introduction of a 32 bit register set. The ax, bx, cx, dx, si, di, bp, sp, flags, and ip registers were all extended to 32 bits. The 80386 calls these new 32 bit versions eax, ebx, ecx, edx, esi, edi, ebp, esp, eflags, and eip to differentiate them from their 16 bit versions 80386 also provides two new 16 bit segment registers, fs and gs, Allow concurrently access six different segments in memory without reloading a segment register.

SS: contains the address of the beginning of the stack CS: contains the address of the beginning of the code segment DS: contains the address of the beginning of the data segment SP: contains the size of stack

80x86 Physical Memory Organization We discussed the basic organization of a Von Neumann Architecture VNA computer system In VNA machine, the CPU connects to memory via the bus. The 80x86 selects some particular memory element using a binary number on the address bus. View memory as an array of bytes. Memory : array [0..MaxRAM] of byte; The value on the address bus corresponds to the index supplied to this array. E.g., Writing data to memory is equivalent to Memory [address] := Value_to_Write; Reading data from memory is equivalent to Value_Read := Memory [address];

Addressing data in Memory Difference between address of a memory Location and its content Processor stores the data in memory in reverse by sequence Two types of addressing schemes absolute address segment-offset address

Segmented address contains a segment component and an offset component. Segmented addresses as segment:offset. On the 8086 through the 80286, these two values are 16 bit constants. On the 80386 and later, the offset can be a 16 bit constant or a 32 bit constant. The actual (physical) memory connected to the CPU is linear array of bytes.

converts the segment value to a physical memory address 8086, 8088, 80186, and 80188 (and other processors operating in real mode) The CPU multiplies the segment value by sixteen (10h=16) and adds the offset portion. example, the segmented address 1000:1F00. To convert this to a physical address multiply the segment value (1000h) by sixteen (add 0 to the right) Add 1F00h to (1000h), the obtained physical address is 11F00h.

8086 Register Addressing Modes mov destination, source This instruction copies the data from the source operand to the destination operand. The only restriction is that both operands must be the same size mov ax, bx ;Copies the value from BX into AX mov dl, al ;Copies the value from AL into DL mov si, dx ;Copies the value from DX into SI mov sp, bp ;Copies the value from BP into SP mov dh, cl ;Copies the value from CL into DH mov ax, ax ;Yes, this is legal!

There aretwo restrictions on the use of the segment registers with the mov instruction. 1. may not specify cs as the destination operand, 2. only one of the operands can be a segment register. You cannot move data from one segment register to another with a single mov instruction. 1. mov ax, cs 2. mov ds, ax

Displacement Only Addressing Mode The easiest addressing mode to understand, is the displacement-only (or direct) addressing mode. consists of a 16 bit constant that specifies the address of the target location. The instruction mov al,ds:[8088h] loads the al register with a copy of the byte at memory location 8088h The instruction mov ds:[1234h],dl stores the value in the dl register to memory location 1234h

Register Indirect Addressing Modes As with the x86 [bx] addressing mode, these four addressing modes reference the byte at the offset found in the bx, bp, si, or di register, respectively. The [bx], [si], and [di] modes use the ds segment by default. The [bp] addressing mode uses the stack segment (ss) by default.

Indexed Addressing Modes If bx contains 1000h, then the instruction mov cl,20h[bx] will load cl from memory location ds:1020h. if bp contains 2020h, mov dh,1000h[bp] will load dh from location ss:3020. The offsets generated by these addressing modes are the sum of the constant and the specified register.