Professional Documents
Culture Documents
SY2018 7 8086 Addressing Mode PDF
SY2018 7 8086 Addressing Mode PDF
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
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
-t
AX=00F3 BX=0000 CX=0000 DX=00F3 SP= . . . . . .
DS= ... ES= . . . . NV UP EI PL NZ NA
XXXX:0102 . . . . .
-q
C>
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.
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 the
memory 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 used
as follows:
and assuming DS contains 0723, the effective RAM address would be calculated
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,
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 the
microprocessor 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,0
xxxx: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
College of Engineering – URSM fmfernando
-rip
[IP 0000] this is DEBUG's output to screen
:_ enter correct starting address here
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 major
disadvantage 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.
Memory Segmentation
The 8-bit microprocessors may use 16-bit addresses, hence, that gives a range from 0000h to FFFFh (up to
64Kb). Notice that the addresses use 4 hex digits. The 3 right-most digits express which bits is being
referred 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 the
16-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 of
memory. For example, in direct addressing instruction:
assuming DS contained 2000h, the address would be calculated in the following manner:
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, since
all segment registers will be the same, so the offset (the address of the IP) will be all we must pay attention
for now.
College of Engineering – URSM fmfernando
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 the
offset.
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?
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?
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?
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.)