khaled a. al-utaibi [email protected]. data allocation addressing modes data addressing modes

30
The 8086 Assembly Programming Data Allocation & Addressing Modes Khaled A. Al-Utaibi [email protected]

Upload: roland-horn

Post on 17-Dec-2015

235 views

Category:

Documents


0 download

TRANSCRIPT

The 8086 Assembly ProgrammingData Allocation & Addressing ModesKhaled A. [email protected]

Agenda

Data Allocation Addressing Modes Data Addressing Modes

Data Allocation In 8086 assembly, data can be allocated (or defined) using

the following directives:−DB (Define Byte) Allocates 1-byte−DW (Define Word) Allocates 2-bytes−DD (Define Double word) Allocates 4-bytes−DQ (Define Quad Word) Allocates 8-bytes

The general format of data allocation is−data-definition-type { init {{, init}} }−Where:

data-definition-type is one of {DB, DW, DD, DQ}, and init is/are initial value/values

Examples:−DB 0AH−DB 1BH, 20H, 34H−DW 01ACH

Data AllocationVariables

A variable is a datum in memory that has been give a name and that may be referred to by name in an instruction.

Variables are created and named and can be initialized by data allocation statements.

The general format for a variable declaration statement is−{variable-name} data-allocation-type {init{{,init}}}

Examples:−V1 DB 12H−V2 DW 0ABCDH

Data AllocationArrays

We can allocate an array by specifying more than one initial (init) value in a data allocation statement.

The general format for an array declaration statement is−{array-name} data-allocation-type {init{{,init}}}

Examples:−A1 DB 12H, 10H, 88H, 44H−A2 DB 14H, 15H, 23H 13H, 17H, 24H

Data AllocationArrays

The DUP (Duplicate) construct facilitates initialization of large array.

The general format of DUP construct is−expr DUP (init)−Where:

expr is a numeric experssion for the number of elements to be allocated and initialized, and

init is the initial value to be given to each element Examples:−A1 DB 10 DUP(0)−A2 DW 20 DUP(1234H)

Addressing Modes Addressing modes define how to identify the

operand(s) of each instruction. An addressing mode specifies how to calculate

the memory address of an operand using information held in – −registers and/or −constants contained within the instruction or

elsewhere. Addressing modes are specified by the

instruction set architecture of the CPU.

Data Addressing Modes Data addressing modes are concerned with instructions

accessing/manipulating data such as: −Data movement instructions (e.g., MOV, IN, OUT, etc.)−Arithmetic instructions (e.g., ADD, SUB, MUL, DIV, etc.)−Logical instructions (e.g., AND, OR, NOT, CMP, etc.)

There are 7 data addressing modes in the 8086:−(1) Register addressing−(2) Immediate addressing−(3) Direct addressing−(4) Register indirect addressing−(5) Base-plus-index addressing−(6) Register relative addressing−(7) Base relative-plus-index addressing

Figure 1 shows illustrates examples of data addressing modes

Figure 1: Data Addressing Modes

MOV [BX+SI], AX RegisterAX

Register Addressing Register addressing transfers a copy of a byte (8-

bits) or word (16-bits) from one register (the source) to another register (the destination) as shown in Figure 2.

Figure 2: The MOV instruction showing the source, destination, and direction of data flow.

Register Addressing The 8086 contains the following register names

which can be used with register addressing: −8-bits registers: AH, AL, BH, BL, CH, CL, DH, and DL. −16-bits registers: AX, BX, CX, DX, SP, BP, SI, and DI.

Note that mixing an 8-bit register addressing with a 16-bit register addressing is not allowed results in an error when assembled.

Table 1 shows examples of register addressing.

Table 1: Examples of Register Addressing.

Immediate Addressing Immediate addressing transfers the source, an

immediate byte or word, into the destination register or memory location.

Example: the MOV AX, 3456H (See Figure 3)−This instruction copies a word-sized constant (3456H)

into register AX.−Note that AH = 34H and AL = 56H.

Note that immediate data are constant data, whereas the data transferred from a register or memory location are variable data.

Table 2 shows examples of immediate addressing.

Figure 3: The operation of the MOV AX,3456H instruction. This instruction copies the immediate data (3456H) into AX.

Table 2: Examples of Immediate Addressing.

Direct Addressing Direct addressing moves a byte or word between a

memory location and a register. The 8086 instruction set does not support a memory-to-

memory transfer, except with the MOVS instruction. Example(1): The MOV CX, LIST −This instruction copies the word-sized contents of memory location

LIST into register CX.−LIST is a memory label (variable) defined in the program.

Example(2): MOV AL, [1234H] (See Figure 4)−This instruction copies the byte-sized content of memory location

DS:1234−If DS = 1000H, then the memory byte at location 11234H is copied

into AL. Table 3 shows different examples of this type of addressing

modes.

Figure 4: The operation of the MOV AL,[1234H] instruction when DS = 1000H.

Table 3: Examples of Direct Addressing.

Register Indirect Addressing Register indirect addressing transfers a byte or word

between a register and a memory location addressed by an index or base register.

The index and base registers are BP, BX, DI, and S1. Example: The MOV AX, [BX] (See Figure 5)−This instruction copies the word-sized data from the data

segment offset address indexed by BX into register.−If DS = 0100H, this instruction addresses a word stored at

memory bytes 2000H and 2001H, and transfers it into register AX. −Note that the contents of 2000H are moved into AL and the

contents of 2001H are moved into AH. −The [ ] symbols denote indirect addressing in assembly language.

Table 4 shows examples of this type of addressing modes

Figure 5: The operation of the MOV AX,[BX] instruction when BX = 1000H and DS = 0100H.

Table 4: Examples of Register Indirect Addressing.

Base-Plus-Index Addressing Base-plus-index addressing transfers a byte or word

between a register and the memory location addressed by a base register (BP or BX) plus an index register (DI or SI).

Example: The MOV DX, [BX+DI] (See Figure 6)−This instruction transfers a copy of the word-sized contents

of the data segment memory location addressed by BX plus DI into register DX.

−If BX = 1000H, DI = 0010H, and DS = 0100H, then this translates into memory address 02010H.

−This instruction transfers a copy of the word from location 02010H into the DX register.

Table 5 shows examples of this type of addressing modes

Figure 6: An example showing how the base-plus-index addressing mode functions for the MOV DX,[BX_DI ] instruction. Notice that memory address 02010H is accessed because DS = 0100H, BX = 100H, and DI = 0010H.

Table 5: Examples of Base plus Index Addressing.

Register Relative Addressing Register relative addressing moves a byte or word

between a register and a memory location addressed by an index or base register plus a displacement.

Example(1): MOV AX,[BX+1000H] (See Figure 7)−The instruction loads AX from the data segment address

formed by BX plus 1000H. −If BX = 0100H and DS = 0200H, then the address generated =

DS x 10H + BX + 1000H = 03100H Example(2): MOV AX, ARRAY[DI] (See Figure 8)−The second instruction loads AX from the data segment

memory location in ARRAY plus the contents of DI. Table 6 shows examples of this type of addressing

modes

AXBX

Figure 7: The operation Memory of the MOV AX, [BX+1000H] instruction, when BX = 0100H and DS = 0200H.

Figure 8: Register relative addressing used to address an element of ARRAY. The displacement addresses the start of ARRAY, and DI accesses an element.

DI

Table 6: Examples of Register Relative Addressing.

Base Relative Plus Index Addressing Base relative-plus-index addressing transfers a

byte or word between a register and the memory location addressed by a base and an index register plus a displacement.

Example(1): MOV AX, ARRAY[BX+DI]−This instruction uses an address formed by adding

ARRAY, BX, and DI. Example(2): MOV AX, [BX+DI+4]−This instruction uses an address formed by adding BX,

DI, and 4. Table 7 shows examples of this type of

addressing modes

Table 7: Examples of Base Relative Plus Index Addressing.