An Introduction to 8086 Microprocessor.. 8086 Microprocessor.
Addressing Modes in Microprocessor 8086/8088. Fayez F. M. El-Sousy Objectives of Addressing Modes in...
Transcript of Addressing Modes in Microprocessor 8086/8088. Fayez F. M. El-Sousy Objectives of Addressing Modes in...
Prof. Fayez F. M. El-Sousy
Prof. Fayez F. M. ElProf. Fayez F. M. El--SousySousy
Department of Electrical EngineeringDepartment of Electrical Engineering
College of EngineeringCollege of Engineering
SalmanSalman bin bin AbdulazizAbdulaziz UniversityUniversity
AlAl--KharjKharj, Saudi Arabia, Saudi Arabia
Addressing Modes in Addressing Modes in
Microprocessor Microprocessor
8086/80888086/8088
Prof. Fayez F. M. El-Sousy
Objectives of Addressing Modes in Objectives of Addressing Modes in
Microprocessor 8086/8088Microprocessor 8086/8088
Upon completion of this chapter, you will be able to:Upon completion of this chapter, you will be able to:
�� Explain the operation of each dataExplain the operation of each data--addressing addressing
mode.mode.
�� Use the dataUse the data--addressing modes to form assembly addressing modes to form assembly
language statements.language statements.
�� Explain the operation of each program memoryExplain the operation of each program memory--
addressing mode.addressing mode.
�� Use the program memoryUse the program memory--addressing modes to addressing modes to
form assembly and machine language statements.form assembly and machine language statements.
Prof. Fayez F. M. El-Sousy
�� Select the appropriate addressing mode to Select the appropriate addressing mode to
accomplish a given task.accomplish a given task.
�� Detail the difference between addressing Detail the difference between addressing
memory data using real mode and protected memory data using real mode and protected
mode operation.mode operation.
�� Describe the sequence of events that place data Describe the sequence of events that place data
onto the stack or remove data from the stack.onto the stack or remove data from the stack.
�� Explain how a data structure is placed in Explain how a data structure is placed in
memory and used with software.memory and used with software.
Objectives of Addressing Modes in Objectives of Addressing Modes in
Microprocessor 8086/8088Microprocessor 8086/8088
Prof. Fayez F. M. El-Sousy
��Types of Addressing Modes:Types of Addressing Modes:
(1) Data Addressing Modes(1) Data Addressing Modes
(2) Program(2) Program--Memory Addressing Memory Addressing
ModesModes
(3) Stack(3) Stack--Memory Addressing ModesMemory Addressing Modes
Addressing Modes in Microprocessor Addressing Modes in Microprocessor
8086/80888086/8088
Prof. Fayez F. M. El-Sousy
�� An addressing mode means the method by which An addressing mode means the method by which an operand can be specified in a register or a an operand can be specified in a register or a memory locationmemory location
�� 8086/8088 provide a seven Addressing Modes8086/8088 provide a seven Addressing Modes:
(1) Register Addressing(1) Register Addressing
(2) Immediate Addressing(2) Immediate Addressing
(3) Direct Addressing(3) Direct Addressing
(4) Register Indirect Addressing(4) Register Indirect Addressing
(5) Base(5) Base––PlusPlus––Index AddressingIndex Addressing
(6) Register Relative Addressing(6) Register Relative Addressing
(7) Base Relative(7) Base Relative––PlusPlus––Index AddressingIndex Addressing
11-- Data Addressing Modes in Data Addressing Modes in
Microprocessor 8086/8088Microprocessor 8086/8088
Prof. Fayez F. M. El-Sousy
8-bit 8-bit 8-bit
OP CODE OPERAND
1 byte 1 to 2 byte
�� An An opcodeopcode is a short of is a short of ““operation codeoperation code””
�� An An opcedeopcede is a singe instruction can be executed by the CPU. is a singe instruction can be executed by the CPU.
In machine language it is a binary or hexadecimal value such In machine language it is a binary or hexadecimal value such
as B7 loaded into the instruction register.as B7 loaded into the instruction register.
�� In assembly language mnemonic form an In assembly language mnemonic form an opcodeopcode is a is a
command such as MOV or ADD or JMP.command such as MOV or ADD or JMP.
�� Example: Example:
MOV AX, 1000H MOV AX, 1000H ;; MOV is the MOV is the opcodeopcode. .
; AX (register) is an opera; AX (register) is an operand.nd.
�� Operands are manipulated by the Operands are manipulated by the opcodeopcode. In this example, . In this example,
the operands are the register AX and the value 1000H. the operands are the register AX and the value 1000H.
OpcodeOpcode and Operand in Microprocessor and Operand in Microprocessor
8086/80888086/8088
Prof. Fayez F. M. El-Sousy
Register Addressing ModeRegister Addressing Mode
�� Transfers a copy of a byte or word from the source register Transfers a copy of a byte or word from the source register
or memory location to the destination register or memory or memory location to the destination register or memory
location.location.
�� Use of registers to hold the data to be manipulated Use of registers to hold the data to be manipulated
�� Memory is not accessed when this addressing mode is Memory is not accessed when this addressing mode is
executed executed
�� Example:Example:
MOV BX, DX MOV BX, DX ; copy the contents of DX into BX; copy the contents of DX into BX
MOV ES, AX MOV ES, AX ; copy the contents of AX into ES; copy the contents of AX into ES
ADD AL, BH ADD AL, BH ; add the contents of BH to ; add the contents of BH to
contents of ALcontents of AL
�� Source and destination registers must have the same sizeSource and destination registers must have the same size
Prof. Fayez F. M. El-Sousy
Register Addressing ModeRegister Addressing Mode
Prof. Fayez F. M. El-Sousy
�� Transfers the source, an immediate byte or word Transfers the source, an immediate byte or word
of data, into the destination register or memory of data, into the destination register or memory
locationlocation
�� The source operand is a constant The source operand is a constant
�� The operand comes immediately after the opcode The operand comes immediately after the opcode
�� For this reason, this addressing mode executes For this reason, this addressing mode executes
quickly quickly
�� Immediate addressing mode can be used to load Immediate addressing mode can be used to load
information into any of the registers except the information into any of the registers except the
segment registers and flag registers.segment registers and flag registers.
Immediate Addressing ModeImmediate Addressing Mode
Prof. Fayez F. M. El-Sousy
Immediate Addressing ModeImmediate Addressing Mode
�� Example: Example:
MOV AX, 2550HMOV AX, 2550H ; move 2550H into AX; move 2550H into AX
MOV CX, 625MOV CX, 625 ; load the decimal value 625 into; load the decimal value 625 into
CXCX
MOV BL, 40HMOV BL, 40H ; load 40H into BL; load 40H into BL
�� The data must first be moved to a generalThe data must first be moved to a general--purpose purpose register and then to the segment register. register and then to the segment register.
�� Example:Example:
MOV AX, 2550HMOV AX, 2550H
MOV DS, AXMOV DS, AX
MOV DS, 0123HMOV DS, 0123H ; illegal instruction!; illegal instruction!
Prof. Fayez F. M. El-Sousy
Immediate Addressing ModeImmediate Addressing Mode
Prof. Fayez F. M. El-Sousy
Direct Addressing ModeDirect Addressing Mode
��Moves a byte or word between a memory location and Moves a byte or word between a memory location and a register. a register.
��The data is in some memory The data is in some memory location(slocation(s) and the ) and the address of the data in memory comes immediately address of the data in memory comes immediately after the instruction after the instruction
��This address is the offset address This address is the offset address
��Example:Example:
MOV AX, [2400]MOV AX, [2400] ; move contents of DS:2400H; move contents of DS:2400H
into AXinto AX
��The physical address is calculated by combining the The physical address is calculated by combining the contents of offset location 2400 with DS contents of offset location 2400 with DS
Prof. Fayez F. M. El-Sousy
�� Example:Example:
Find the physical address of the memory location and its Find the physical address of the memory location and its contents after the execution of the following, assuming that DS contents after the execution of the following, assuming that DS = 1512H. = 1512H.
MOV AL, 3BH MOV AL, 3BH
MOV [3518], ALMOV [3518], AL
�� Solution:Solution:
�� First 3BH is copied into AL,First 3BH is copied into AL,
�� Then in line two, the contents of AL are moved to logical Then in line two, the contents of AL are moved to logical address DS:3518 which is 1512:3518. address DS:3518 which is 1512:3518.
�� Shifting DS left and adding it to the offset gives the physical Shifting DS left and adding it to the offset gives the physical address of 18638H (15120H + 3518H = 18638H). address of 18638H (15120H + 3518H = 18638H).
�� After the execution of the second instruction, the memory After the execution of the second instruction, the memory location with address 18638H will contain the value 3BH.location with address 18638H will contain the value 3BH.
Direct Addressing ModeDirect Addressing Mode
Prof. Fayez F. M. El-Sousy
Direct Addressing ModeDirect Addressing Mode
Prof. Fayez F. M. El-Sousy
Register Indirect Addressing ModeRegister Indirect Addressing Mode
��Transfers a byte or word between a register and a Transfers a byte or word between a register and a
memory location addressed by an index or base memory location addressed by an index or base
registerregister
��The address of the memory location where the The address of the memory location where the
operand resides is held by a register operand resides is held by a register
��The registers used for this purpose are SI, DI, and BX The registers used for this purpose are SI, DI, and BX
��They must be combined with DS in order to generate They must be combined with DS in order to generate
the 20the 20--bit physical address.bit physical address.
Prof. Fayez F. M. El-Sousy
Register Indirect Addressing ModeRegister Indirect Addressing Mode
��Example:Example:
MOV AX, [BX]MOV AX, [BX] ; moves into AX the contents of ; moves into AX the contents of
the memory location pointedthe memory location pointed
to by DS:BX, 1000:1234to by DS:BX, 1000:1234
�� The physical address is calculated asThe physical address is calculated as
1000x10+1234=11234H1000x10+1234=11234H
��The same rules apply when using register SI or DI.The same rules apply when using register SI or DI.
��Example:Example:
MOV CL, [SI]MOV CL, [SI] ; move contents of DS:SI into CL ; move contents of DS:SI into CL
MOV [DI], AHMOV [DI], AH ; move contents of AH into DS:DI; move contents of AH into DS:DI
Prof. Fayez F. M. El-Sousy
Register Indirect Addressing ModeRegister Indirect Addressing Mode
�� Example:Example:
�� Assume that DS = 1120, SI = 2498, and AX = 17FE Show Assume that DS = 1120, SI = 2498, and AX = 17FE Show
the contents of memory locations after the execution ofthe contents of memory locations after the execution of
MOV [SI], AX MOV [SI], AX ; move contents of AX into DS:SI; move contents of AX into DS:SI
�� Solution: Solution:
��The contents of AX are moved into memory locations The contents of AX are moved into memory locations
with logical address with logical address DS:SI and DS:SI + 1DS:SI and DS:SI + 1;;
��The physical address starts at The physical address starts at DS (shifted left) + SI = DS (shifted left) + SI =
13698.13698. According to the little According to the little endianendian convention, convention,
��Low address Low address 13698H13698H contains contains FEFE, the low byte,, the low byte,
��High address High address 13699H13699H will contain will contain 1717, the high byte., the high byte.
Prof. Fayez F. M. El-Sousy
Register Indirect Addressing ModeRegister Indirect Addressing Mode
Prof. Fayez F. M. El-Sousy
BaseBase--PlusPlus--Index Addressing ModeIndex Addressing Mode
�� Transfers a byte or word between a register and the memory locatTransfers a byte or word between a register and the memory location ion addressed by a base register (BP or BX) plus an index register (addressed by a base register (BP or BX) plus an index register (DI or DI or SI).SI).
�� Combining based and indexed addressing modes. Combining based and indexed addressing modes.
�� One base register and one index register are used.One base register and one index register are used.
�� Examples:Examples:
MOV [BX+DI], CL MOV [BX+DI], CL ; move contents of CL into DS:BX+DI; move contents of CL into DS:BX+DI
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+DI+ BX+DI
MOV CH, [BX+SI] MOV CH, [BX+SI] ; move contents of the DS:BX+SI into CH; move contents of the DS:BX+SI into CH
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+SI+ BX+SI
MOV AH, [BP+DI] MOV AH, [BP+DI] ; move contents of the SS:BP+SI into AH; move contents of the SS:BP+SI into AH
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 + BP+DI+ BP+DI
MOV [BP+SI], AL MOV [BP+SI], AL ; move contents of AL into SS:BP+SI; move contents of AL into SS:BP+SI
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 + BP+SI+ BP+SI
Prof. Fayez F. M. El-Sousy
BaseBase--PlusPlus--Index Addressing ModeIndex Addressing Mode
Prof. Fayez F. M. El-Sousy
Register Relative Addressing ModeRegister Relative Addressing Mode
�� Moves a byte or word between a register and the memory location Moves a byte or word between a register and the memory location addressed by an index or base register plus a displacement.addressed by an index or base register plus a displacement.
�� The data The data in a segment of memory are addressed by adding the in a segment of memory are addressed by adding the displacement to the contents of a base or an index register (BP,displacement to the contents of a base or an index register (BP, BX, DI, BX, DI, or SI).or SI).
�� Examples:Examples:
MOV AX, [BX+4] MOV AX, [BX+4] ; move contents of DS:BX+4 into AX ; move contents of DS:BX+4 into AX
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+4+ BX+4
MOV CH, [SI+5] MOV CH, [SI+5] ; move contents of the DS:SI+5 into CH; move contents of the DS:SI+5 into CH
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 +SI+5+SI+5
MOV AH, [DI+1] MOV AH, [DI+1] ; move contents of the DS:DI+1 into AH; move contents of the DS:DI+1 into AH
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + DI+1+ DI+1
MOV [BP+2], AL MOV [BP+2], AL ; move contents of AL into SS:BP+2; move contents of AL into SS:BP+2
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 + BP+2+ BP+2
Prof. Fayez F. M. El-Sousy
Register Relative Addressing ModeRegister Relative Addressing Mode
�� Example:Example:
�� Assume that DS = 4500, SS = 2000, BX = 2100, SI = 1486, DI = Assume that DS = 4500, SS = 2000, BX = 2100, SI = 1486, DI = 8500, BP= 7814, and AX = 2512. Show the exact physical 8500, BP= 7814, and AX = 2512. Show the exact physical memory location where AX is stored in each of the following. Allmemory location where AX is stored in each of the following. Allvalues are in hex.values are in hex.
11-- MOV [BX+20], AX MOV [BX+20], AX
22-- MOV [SI+10], AX MOV [SI+10], AX
33-- MOV [DI+4], AX MOV [DI+4], AX
44-- MOV [BP+12], AXMOV [BP+12], AX
�� Solution:Solution:
Physical Address = segment reg. x 10 + (offset reg.) + Physical Address = segment reg. x 10 + (offset reg.) + displacementdisplacement
11-- DS:BX+20 DS:BX+20 location 47120 = (12) and 47121 = (25) location 47120 = (12) and 47121 = (25)
22-- DS:SI+10DS:SI+10 location 46496 = (12) and 46497 = (25 )location 46496 = (12) and 46497 = (25 )
33-- DS:DI+4DS:DI+4 location 4D504 = (12) and 4D505 = (25) location 4D504 = (12) and 4D505 = (25)
44-- SS:BP+12SS:BP+12 location 27826 = (12) and 27827 = (25)location 27826 = (12) and 27827 = (25)
Prof. Fayez F. M. El-Sousy
Register Relative Addressing ModeRegister Relative Addressing Mode
Prof. Fayez F. M. El-Sousy
Base RelativeBase Relative--PlusPlus--Index Index
Addressing ModeAddressing Mode
�� The base relativeThe base relative--plusplus--index addressing mode is similar to the index addressing mode is similar to the basebase--plusplus--index addressing mode, but adds a displacement index addressing mode, but adds a displacement besides using a base register and an index register to form the besides using a base register and an index register to form the memory address. memory address.
�� This type of addressing mode often addresses a twoThis type of addressing mode often addresses a two--dimensional dimensional array of memory data. array of memory data.
�� The data The data in a segment of memory are addressed by adding the in a segment of memory are addressed by adding the displacement to the contents of a base and an index register (BPdisplacement to the contents of a base and an index register (BP, , BX, DI, or SI).BX, DI, or SI).
�� Examples:Examples:
MOV [BX+DI+1], AX MOV [BX+DI+1], AX ; move contents of AX into; move contents of AX into
DS:BX+DI+1DS:BX+DI+1
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+DI+1H+ BX+DI+1H
MOV AX, [BX+SI+10] MOV AX, [BX+SI+10] ; move contents of the DS:BX+SI+10 ; move contents of the DS:BX+SI+10
into AXinto AX
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+SI+10H+ BX+SI+10H
Prof. Fayez F. M. El-Sousy
Base RelativeBase Relative--PlusPlus--Index Index
Addressing ModeAddressing Mode
MOV AH, [BP+DI+3] MOV AH, [BP+DI+3] ; move contents of the SS:BP+SI+3; move contents of the SS:BP+SI+3
into AHinto AH
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 + BP+DI+3H+ BP+DI+3H
MOV [BP+SI+6], AL MOV [BP+SI+6], AL ; move contents of AL into; move contents of AL into
SS:BP+SI+6SS:BP+SI+6
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 + BP+SI+6+ BP+SI+6
MOV AX, FILE[BX+DI] MOV AX, FILE[BX+DI] ; move contents of the ; move contents of the
DS:FILE+BXDS:FILE+BX+DI into AX+DI into AX
�� Physical Address = DSPhysical Address = DSxxxxxxxx1010 + BX+DI+FILE+ BX+DI+FILE
MOV LIST[BP+SI+4], DH MOV LIST[BP+SI+4], DH ; move contents of DH into; move contents of DH into
SS:LIST+BP+SS:LIST+BP+SI+4 SI+4
�� Physical Address = SSPhysical Address = SSxxxxxxxx1010 +LIST+ BP+SI+4+LIST+ BP+SI+4
Prof. Fayez F. M. El-Sousy
Base RelativeBase Relative--PlusPlus--Index Index
Addressing ModeAddressing Mode
Prof. Fayez F. M. El-Sousy
SP, BPSP, BPSI, DI, BXSI, DI, BXSI, DI, BXSI, DI, BXIPIPOffset RegisterOffset Register
SSSSESESDSDSCSCSSegment RegisterSegment Register
Offset Registers for Various SegmentsOffset Registers for Various Segments
The following Table provides a summary of the The following Table provides a summary of the
offset registers that can be used with the four offset registers that can be used with the four
segment registers of the 8086/8088.segment registers of the 8086/8088.
Prof. Fayez F. M. El-Sousy
22-- ProgramProgram--Memory Addressing Modes Memory Addressing Modes
in Microprocessor 8086/8088in Microprocessor 8086/8088
�� Program memoryProgram memory--addressing modes, used with addressing modes, used with
the JMP and CALL instructions, consist of the JMP and CALL instructions, consist of
three distinct forms: three distinct forms:
11-- Direct Program Memory AddressingDirect Program Memory Addressing
22-- Relative Relative Program Memory AddressingProgram Memory Addressing
33-- Indirect Indirect Program Memory AddressingProgram Memory Addressing
�� These three addressing forms are introduced in These three addressing forms are introduced in
the next Chapter (5) using the JMP instruction the next Chapter (5) using the JMP instruction
to illustrate their operation.to illustrate their operation.
Prof. Fayez F. M. El-Sousy
33-- StackStack--Memory Addressing Modes in Memory Addressing Modes in
Microprocessor 8086/8088Microprocessor 8086/8088
�� The stack plays an important role in all The stack plays an important role in all
microprocessors. microprocessors.
�� It holds data temporarily and stores return addresses It holds data temporarily and stores return addresses
for procedures. for procedures.
�� The stack memory is a LIFO (lastThe stack memory is a LIFO (last--in, firstin, first--out) memory, out) memory,
which describes the way that data are stored and which describes the way that data are stored and
removed from the stack. removed from the stack.
�� Data are placed onto the stack with a PUSH instruction Data are placed onto the stack with a PUSH instruction
and removed with a POP instruction. and removed with a POP instruction.
�� The CALL instruction also uses the stack to hold the The CALL instruction also uses the stack to hold the
return address for procedures and a RET (return) return address for procedures and a RET (return)
instruction to remove the return address from the stack.instruction to remove the return address from the stack.