7 8086 Addressing Mode

4
7/21/2019 7 8086 Addressing Mode http://slidepdf.com/reader/full/7-8086-addressing-mode 1/4 College of Engineering – URSM fmfernando DATA TRANSFER (  MOV  INSTRUCTION) & DIRECTION OF DATA TRANSFER The 8086/8088 most versatile and useful for novice low-level programmer is the  MOV  instruction. A  MOV  can be  from (source) a register, memory, or an immediate number to (destination) a register or memory. While either  the source or the destination can be a memory location, both cannot be memory locations in the same instruction. The source & destination must be both either 8 bits wide or 16 bits wide; you cannot mix data widths in the same instruction. A few examples of the  MOV  commands are as follows:  MOV  AL, DL AL  DL  MOV  BH, BL BH  BL  MOV  AX, DX AX  DX  MOV  AL, 76 AL  76  MOV  AX, 89E3 AX  89E3  MOV  [1234], AX RAM address 1234  AX  MOV  BL, [4456] BL  RAM address 4456 content SAMPLE 8086/8088 Program C>debug -r AX=0000 BX=0000 CX=0000 DX=0000 SP= . . . . . . DS= ... ES= . . . . NV UP EI PL NZ NA . . . -a XXXX:0100 mov al,dl XXXX:0102 u 100 101 XXXX:0100 88D0 MOV AL,DL -r AX=0000 BX=0000 CX=0000 DX=0000 SP= . . . . . . DS= ... ES= . . . . NV UP EI PL NZ NA XXXX:0100 88D0 MOV AL,DL -rdx DX 0000 :00f3 -r AX=0000 BX=0000 CX=0000 DX=00F3 SP= . . . . . . DS= ... ES= . . . . NV UP EI PL NZ NA XXXX:0100 88D0 MOV AL,DL -t  AX=00F3 BX=0000 CX=0000 DX=00F3 SP= . . . . . . DS= ... ES= . . . . NV UP EI PL NZ NA XXXX:0102 . . . . . - C> 8086 ADDRESSING MODES There are 5 most basic addressing modes: 1. Implied Addressing: sometimes called inherent addressing , no address is necessary because the location is implied in the instruction itself. Two examples are HLT (halt) and  NOP (no operation). 2.  Register Addressing: sometimes called accumulator addressing , involves only internal registers or an accumulator and no external RAM. Since the 8086/8088 chips have eight 8-bit (or four 16-bit) general-  purpose registers in addition to a number of other special-purpose registers, there are hundreds of  MOV  command combinations. One example is to move the contents of the CX and BX registers  –   MOV  BX,CX (note that you should notice that where the data is going to BX is written  first , and where the data is coming from CX is written last .

description

ADDRESSING MODE

Transcript of 7 8086 Addressing Mode

Page 1: 7 8086 Addressing Mode

7/21/2019 7 8086 Addressing Mode

http://slidepdf.com/reader/full/7-8086-addressing-mode 1/4

College of Engineering – URSM fmfernando

DATA TRANSFER ( MOV  INSTRUCTION) & DIRECTION OF DATA TRANSFER

The 8086/8088 most versatile and useful for novice low-level programmer is the MOV  instruction. A MOV  

can be  from  (source) a register, memory, or an immediate number to  (destination) a register or memory.While either  the source or the destination can be a memory location, both cannot be memory locations inthe same instruction. The source & destination must be both either 8 bits wide or 16 bits wide; you cannotmix data widths in the same instruction. A few examples of the MOV  commands are as follows:

 MOV  AL, DL AL DL

 MOV  BH, BL BH BL

 MOV  AX, DX AX DX

 MOV  AL, 76 AL 76

 MOV  AX, 89E3 AX 89E3

 MOV  [1234], AX RAM address 1234 AX

 MOV  BL, [4456] BL RAM address 4456 content

SAMPLE 8086/8088 Program

C>debug 

-r 

AX=0000 BX=0000 CX=0000 DX=0000 SP= . . . . . .DS= ... ES= . . . . NV UP EI PL NZ NA

. . .

-a 

XXXX:0100 mov al,dl 

XXXX:0102

u 100 101

XXXX:0100 88D0 MOV AL,DL

-r 

AX=0000 BX=0000 CX=0000 DX=0000 SP= . . . . . .

DS= ... ES= . . . . NV UP EI PL NZ NA

XXXX:0100 88D0 MOV AL,DL

-rdx 

DX 0000

:00f3

-rAX=0000 BX=0000 CX=0000 DX=00F3  SP= . . . . . .

DS= ... ES= . . . . NV UP EI PL NZ NA

XXXX:0100 88D0 MOV AL,DL

-t 

 AX=00F3  BX=0000 CX=0000 DX=00F3  SP= . . . . . .

DS= ... ES= . . . . NV UP EI PL NZ NA

XXXX:0102 . . . . .

-q  

C>

8086 ADDRESSING MODES 

There are 5 most basic addressing modes:

1.  Implied Addressing: sometimes called inherent addressing , no address is necessary because the

location is implied in the instruction itself . Two examples are HLT (halt) and NOP (no operation).

2. 

Register Addressing: sometimes called accumulator addressing , involves only internal registers or anaccumulator and no external RAM. Since the 8086/8088 chips have eight 8-bit (or four 16-bit) general-

 purpose registers in addition to a number of other special-purpose registers, there are hundreds of MOV  

command combinations. One example is to move the contents of the CX and BX registers  –   MOV  

BX,CX (note that you should notice that where the data is going to BX is written  first , and where thedata is coming from CX is written last .

Page 2: 7 8086 Addressing Mode

7/21/2019 7 8086 Addressing Mode

http://slidepdf.com/reader/full/7-8086-addressing-mode 2/4

College of Engineering – URSM fmfernando

3.  Immediate Addressing: is a mode in which the number or data to be operated on or moved is in thememory location immediately  following the instruction op code. For example, the instruction MOV  

AL,37 would place the hex number 37 in the AL register.

4.  Direct Addressing: uses an op code followed by a 1- or 2-byte memory address where the data which

is to be used can be found. The data is outside the P itself, in one of the many thousands of RAM

address. Direct addressing in Intel-based P make used of paging concept or memory segmentation since this mode of addressing uses not only the address specified in the instruction but also the address

in one of the segment registers. In case of the MOV  instruction, the data segment  (DS) register is usedas follows:

For the command

 MOV  DL, [0100]

and assuming DS contains 0723 , the effective RAM address would be calculated

07230 DS (shifted left)+ 0100 address specified in the operand [0100]

07330 effective address

5. 

Program Direct Addressing: it is simply direct addressing used for a different purpose. For example,JMP and CALL instructions direct the flow of the program. They are not used to manipulate data.

In summary,

 NOP   Implied addressing

 MOV  BX,CX  Register addressing

 MOV  AL, 37  Immediate addressing

 MOV  BL,[0100]  Direct addressing (with RAM segmentation)

JMP 100  Program direct addressing

SUGGESTED PROCEDURES/TECHNIQUES IN ASSEMBLY/DISASSEMBLY PROGRAMMING OF THE8086/8088 MICROPROCESSOR USING MS-DOS DEBUG UTILITY PROGRAMMING

1. Run the MS-DOS DEBUG utility program at the DOS prompt, for example

C:\Windows\temp>debug <enter>

2. When the DEBUG prompt (-) is shown, you may optionally check the contents of all registers and flags.

-r <enter>

3. Write down (or, assemble) the machine code using the format: <op code> <operand> and refer to themicroprocessor instruction set. An example follows:

-a 100 <enter>

xxxx:0100 jmp 126

xxxx:0102 db 0d,0a,”This is my first DEBUG program!” xxxx:0123 db 0d,0a,”$” xxxx:0126 mov ah,9

xxxx:0128 mov dx,102

xxxx:012B int 21

xxxx:012D mov ah,0xxxx:012F int 21

xxxx:0131<enter>-g =100

This is my first DEBUG program!

Program terminated normally

-

4. Verify your entered code for bugs, or unassemble your code in the RAM.

-u 126 12F

Page 3: 7 8086 Addressing Mode

7/21/2019 7 8086 Addressing Mode

http://slidepdf.com/reader/full/7-8086-addressing-mode 3/4

College of Engineering – URSM fmfernando

XXXX:0126 B409 MOV AH,9

XXXX:0128 BA0201 MOV DX,102

XXXX:012B CD21 INT 21

XXXX:012D B400 MOV AH,0

XXXX:012F CD21 INT 21

-

5. Trace the step-by-step execution of your program when necessary to follow through each command.Specify the starting address when re-executing your program and make sure the IP (instruction pointer)

contain the starting address of your program. If not use

-rip 

[IP 0000]  this is DEBUG's output to screen:_ enter correct starting address here

Then, enter the go command:

-g 012B  starting address is given by IP register

6. If the IP is 0100H and executes it with a “g” command only without the starting and ending addresses,  all registers and flags will return to their previous state prior to running this program. This is a majordisadvantage of go command and to overcome this, use a “breakpoint” like

-g =0100 012B  (Note that command at address 012B will not be executed)

7. While tracing the command execution, watch out for INTerrupt calls (i.e. INT 20 or INT 21), use the

 proceed command “p” instead. INT 20 is use to stop program execution. INT 21 also terminates   program only if the AH register contains 00H.

8. End program run or quit from DEBUG and go back to DOS prompt by entering “q” at DEBUG prompt. 

Summary and Examples of Basic Data Addressing Mode

1. Register addressing: MOV BX,CX2. Immediate addressing: MOV AL, FF3. Direct addressing: MOV BL,[0100]4. Program Direct addressing: JMP 1265. Implied addressing: NOP

Memory Segmentation

The 8-bit microprocessors may use 16-bit addresses, hence, that gives a range from 0000h to FFFFh (up to64Kb). Notice that the addresses use 4 hex digits. The 3 right-most digits express which bits is beingreferred to. The 2 left-most digits express which memory page the bytes are in. There are 256 bytes per

 page and 256 pages from 0000h to FFFFh. The 8086/8088 chips use a large 20-bit address instead of the16-bit address used by the 8-bit chips. 20 bits is 5 hex digits from 00000h to FFFFFh (in decimal, this is up

to 1,048,575 addresses or 1MB) memory locations.

A segment is a 64K block of memory, thus there could be as many as 16 overlapping segments in 1MB ofmemory. For example, in direct addressing instruction:

 MOV  DL, [0100]

assuming DS contained 2000h, the address would be calculated in the following manner:

20000h DS register shifted LEFT 1 bit

+ 0100h20100h effective addressing    memory page

So, the MOV  DL,[0100] instruction places a copy of the data found in memory address 20100h and not

0100h, in the DL register.

We generally, won't be concerned with segment registers for simple and very small program codes, sinceall segment registers will be the same, so the offset (the address of the IP) will be all we must pay attention

for now.

Page 4: 7 8086 Addressing Mode

7/21/2019 7 8086 Addressing Mode

http://slidepdf.com/reader/full/7-8086-addressing-mode 4/4

College of Engineering – URSM fmfernando

Recall also, the command

JMP 100

where the offset 100h is added to the code segment CS rather than the DS register. Remember that the

content of the CS register, like the DS register, are shifted one hex digit to the left before being added to theoffset.

LESSON CHECK-UP:

1. What is the DOS utility program which are used to do assembly, disassembly, running, and debugging of

8086/8088 assembly-language programs?

2. What 3 areas can serve as a source for the MOV  command?

3. What are the 2 areas which can serve as destinations for the MOV  instruction?

4. Which area cannot be both a source and a destination at the same time?

5. What is the source of a MOV  AL,DL instruction?

6. What is the destination of a MOV  AL,76 code?

7. Does the command MOV   BX,[4455] transfer the hex 4455 or the contents of RAM address 4455 to

register BX?

8. What does the DEBUG command “r” stand for and what does it do? 

9. What does the DEBUG command “a” stand for and what does it do? 

10. What does the DEBUG command “u” stand for and what does it do?

11. What does the DEBUG trace command do?

12. What is the DEBUG quit command?

13. Using DEBUG, write an assembly program which will –  

a. place the number 89H into the low byte of the base register, then

 b. copy the contents of the base register into the data register and the into RAM address 333H

(Note: use DEBUG’s trace command to verify the above data transfer.)