Top Banner
69

8086 segmentation and addressing modes

Nov 23, 2014

Download

Documents

heytall
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 8086 segmentation and addressing modes
Page 2: 8086 segmentation and addressing modes
Page 3: 8086 segmentation and addressing modes
Page 4: 8086 segmentation and addressing modes
Page 5: 8086 segmentation and addressing modes
Page 6: 8086 segmentation and addressing modes
Page 7: 8086 segmentation and addressing modes
Page 8: 8086 segmentation and addressing modes
Page 9: 8086 segmentation and addressing modes
Page 10: 8086 segmentation and addressing modes
Page 11: 8086 segmentation and addressing modes
Page 12: 8086 segmentation and addressing modes
Page 13: 8086 segmentation and addressing modes
Page 14: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE

Page 15: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000

Page 16: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE

Page 17: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

Page 18: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER

Page 19: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX

Page 20: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

Page 21: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

Page 22: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT

Page 23: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000]

Page 24: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA

Page 25: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

Page 26: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

Page 27: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI]

JMP [DI]

INC BYTEPTR[BP]

DEC WORDPTR[BX]

Page 28: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI] DATA

JMP [DI] DATA

INC BYTEPTR[BP] STACK

DEC WORDPTR[BX] DATA

Page 29: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI] DATA AL<=[SI]AH<=[SI+1]

JMP [DI] DATA

INC BYTEPTR[BP] STACK

DEC WORDPTR[BX] DATA

Page 30: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI] DATA AL<=[SI]AH<=[SI+1]

JMP [DI] DATA IP <={[DI+1] [DI]}

INC BYTEPTR[BP] STACK

DEC WORDPTR[BX] DATA

Page 31: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI] DATA AL<=[SI]AH<=[SI+1]

JMP [DI] DATA IP <={[DI+1] [DI]}

INC BYTEPTR[BP] STACK [BP]<=[BP]+1

DEC WORDPTR[BX] DATA

Page 32: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

IMMEDIATE MOV AX,1000 CODE AH<=10, AL<=00

REGISTER MOV DX,CX WITHIN THE CPU

DX<=CX

DIRECT MOV AL,[2000] DATA AL<=[2000]

REGISTER INDIRECT

MOV AX,[SI] DATA AL<=[SI]AH<=[SI+1]

JMP [DI] DATA IP <={[DI+1] [DI]}

INC BYTEPTR[BP] STACK [BP]<=[BP]+1

DEC WORDPTR[BX] DATA {[BX+1][BX]}<={[BX+1][BX]} – 1

Page 33: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6]

JMP [DI+6]

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2]

JMP [BX+2]

Page 34: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6] DATA

JMP [DI+6] DATA

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2] STACK

JMP [BX+2] DATA

Page 35: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6] DATA AL<=[SI+6], AH<=[SI+7]

JMP [DI+6] DATA

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2] STACK

JMP [BX+2] DATA

Page 36: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6] DATA AL<=[SI+6], AH<=[SI+7]

JMP [DI+6] DATA IP <={[DI+7] [DI+6]}

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2] STACK

JMP [BX+2] DATA

Page 37: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6] DATA AL<=[SI+6], AH<=[SI+7]

JMP [DI+6] DATA IP <={[DI+7] [DI+6]}

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2] STACK AL<=[BP+2], AH<=[BP+3]

JMP [BX+2] DATA

Page 38: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

RELATIVE INDEXED(RELATIVE REGISTER INDIRECT)

MOV AX,[SI+6] DATA AL<=[SI+6], AH<=[SI+7]

JMP [DI+6] DATA IP <={[DI+7] [DI+6]}

RELATIVE BASED(RELATIVE REGISTER INDIRECT)

MOV AX,[BP+2] STACK AL<=[BP+2], AH<=[BP+3]

JMP [BX+2] DATA IP <={[BP+3] [BP+2]}

Page 39: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI]

JMP [BX+DI]

INC BYTEPTR[BP+SI]

DEC WORDPTR[BP+DI]

Page 40: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI] DATA

JMP [BX+DI] DATA

INC BYTEPTR[BP+SI] STACK

DEC WORDPTR[BP+DI]

STACK

Page 41: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI] DATA AL<=[BX+SI], AH<=[BX+SI+1]

JMP [BX+DI] DATA

INC BYTEPTR[BP+SI] STACK

DEC WORDPTR[BP+DI]

STACK

Page 42: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI] DATA AL<=[BX+SI], AH<=[BX+SI+1]

JMP [BX+DI] DATA IP <={[BX+DI+1] [BX+DI]}

INC BYTEPTR[BP+SI] STACK

DEC WORDPTR[BP+DI]

STACK

Page 43: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI] DATA AL<=[BX+SI], AH<=[BX+SI+1]

JMP [BX+DI] DATA IP <={[BX+DI+1] [BX+DI]}

INC BYTEPTR[BP+SI] STACK [BP+SI]<=[BP+SI]+1

DEC WORDPTR[BP+DI]

STACK

Page 44: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED

MOV AX,[BX+SI] DATA AL<=[BX+SI], AH<=[BX+SI+1]

JMP [BX+DI] DATA IP <={[BX+DI+1] [BX+DI]}

INC BYTEPTR[BP+SI] STACK [BP+SI]<=[BP+SI]+1

DEC WORDPTR[BP+DI]

STACK {[BP+DI+1][BP+DI]} <={[BP+DI+1][BP+DI]} - 1

Page 45: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5]

JMP [BX+DI+5]

INC BYTEPTR[BP+SI+5]

DEC WORDPTR[BP+DI+5]

Page 46: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5] DATA

JMP [BX+DI+5] DATA

INC BYTEPTR[BP+SI+5]

STACK

DEC WORDPTR[BP+DI+5]

STACK

Page 47: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5] DATA AL<=[BX+SI+5], AH<=[BX+SI+6]

JMP [BX+DI+5] DATA

INC BYTEPTR[BP+SI+5]

STACK

DEC WORDPTR[BP+DI+5]

STACK

Page 48: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5] DATA AL<=[BX+SI+5], AH<=[BX+SI+6]

JMP [BX+DI+5] DATA IP <={[BX+DI+6] [BX+DI+5]}

INC BYTEPTR[BP+SI+5]

STACK

DEC WORDPTR[BP+DI+5]

STACK

Page 49: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5] DATA AL<=[BX+SI+5], AH<=[BX+SI+6]

JMP [BX+DI+5] DATA IP <={[BX+DI+6] [BX+DI+5]}

INC BYTEPTR[BP+SI+5]

STACK [BP+SI+5]<=[BP+SI+5]+1

DEC WORDPTR[BP+DI+5]

STACK

Page 50: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

BASED AND INDEXED WITH DISPLACEMENT (RELATIVE BASED AND INDEXED]

MOV AX,[BX+SI+5] DATA AL<=[BX+SI+5], AH<=[BX+SI+6]

JMP [BX+DI+5] DATA IP <={[BX+DI+6] [BX+DI+5]}

INC BYTEPTR[BP+SI+5]

STACK [BP+SI+5]<=[BP+SI+5]+1

DEC WORDPTR[BP+DI+5]

STACK {[BP+DI+6][BP+DI+5]} <={[BP+DI+6][BP+DI+5]} - 1

Page 51: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

STRING MOVSB

IMPLICIT CLD

Page 52: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

STRING MOVSB EXTRA, DATA

IMPLICIT CLD WITHIN THE CPU

Page 53: 8086 segmentation and addressing modes

Addressing mode Mnemonic Segment for memory access

Symbolic representation

STRING MOVSB EXTRA, DATA ES:[DI]<=DS:[SI]IF DF=0, INCREMENT SI AND DI BY 1IF DF =1, DECREMENT SI AND DI BY 1

IMPLICIT CLD WITHIN THE CPU

DF = 0

Page 54: 8086 segmentation and addressing modes

IDENTIFY THE ADDRESSING MODE

MOV AH,47MOV AH,[BP+2]MOV AL,[BP+SI]STDMOV AH,BLMOV DX,[2002]

Page 55: 8086 segmentation and addressing modes

Problem statement – clear the contents of three memory location

Memory content location62380 0062381 0062382 00

Page 56: 8086 segmentation and addressing modes

8086 Sample programs MOV AX,6000H move 6000h into AX MOV ES,AX move AX contents into ES MOV DI,2380H move 2380H into DI MOV CX,0003H move 0003H into CX MOV AL,00H move 00H into ALAgain MOV [DI],AL AL => ES:[DI} INC DI Increment the contents of DI LOOP AGAIN dec CX, and if CX is NZ go to again HLT Halt

Page 57: 8086 segmentation and addressing modes

8086 Sample programs MOV AX,6000H move 6000h into AX MOV ES,AX move AX contents into ES MOV DI,2380H move 2380H into DI CLD clear the direction flag MOV CX,0003H move 0003H into CX MOV AL,00H move 00H into ALREP STOSB AL => ES:[DI]and increment DI (rep this CX times) HLT Halt

Page 58: 8086 segmentation and addressing modes

(CX=0003h) (AL = 00h)(DI=2380h)(ES=6000h)

• 1st time REP STOSBAL =>ES:[DI] i.e. 00=> [62380]h and DI = 2381h

CX=0002h• 2ND time REP STOSB

AL =>ES:[DI] i.e. 00=> [62381]h and DI = 2382hCX=0001h

• 3RD time REP STOSBAL =>ES:[DI] i.e. 00=> [62382]h and DI = 2383h

CX=0000h• 4TH Time will not happen cos CX = 0000h

Page 59: 8086 segmentation and addressing modes

REP LOOPPREFIX INSTRUCTIONUSED ONLY BEFORE STRING INSTRUCTION

USED ANYWHERE

USED TO REPEAT ONLY THAT STRING INSTRUCTION

USED TO REPEAT SERIES OF INSTRUCTION

Page 60: 8086 segmentation and addressing modes

String instructionsSTOSB AL=>ES:[DI] After string opr, if DF = 0, then DI is incremented by 1and viceversa LODSB AL<=DS:[SI]After string opr, if DF = 0, then SI is incremented by 1and viceversa MOVSB DS:[SI]=>ES:[DI]After string opr, if DF = 0, then SI and DI is incremented by 1and viceversa SCASB AL – ES:[DI]After string opr, if DF = 0, then DI is incremented by 1and viceversa CMPSB DS:[SI] – ES:[DI]After string opr, if DF = 0, then SI and DI is incremented by 1and viceversa

Page 61: 8086 segmentation and addressing modes

Problem statement block transfer

Transfer contents of 52500 to 62500 and 52501 to 62501

Page 62: 8086 segmentation and addressing modes

Block transferMOV AX,5000 HMOV DS,AXMOV SI,2500HMOV AX,6000HMOV DI,2500HCLDMOV CX,0002HREP MOVSB DS:[SI] =>ES:[DI] and increment DI and SI (rep this CX times)

HLT

Page 63: 8086 segmentation and addressing modes

(CX=0002h) (DS=5000h)(SI=2500h)(DI=2500h)(ES=6000h)

• 1st time REP MOVSB DS:[SI] =>ES:[DI] i.e. [52500]=>[62500]

SI =2501 and DI = 2501CX=0001h

• 2ND time REP MOVSBDS:[SI] =>ES:[DI] i.e. [52501]=>[62501]

SI =2502 and DI = 2502CX=0000h

• 3rd Time will not happen cos CX = 0000h

Page 64: 8086 segmentation and addressing modes

8086 sample programs

When both the numbers are positive(+03)h x (+02)h = (+06)hMOV AL,03HMOV BL,02HIMUL BLResult: (+0006)h => AX

Page 65: 8086 segmentation and addressing modes

8086 sample programsWhen both the numbers are not positive(+03)h x (-02)h = (-06)h2’s complement of 02 = 1’s complement of 00000010 + 1=11111110 = FEhMOV AL,03HMOV BL,FEHIMUL BLResult: (FFFA)h => AX(FFFA)h is actually –(0006)h

Page 66: 8086 segmentation and addressing modes

8086 sample programs

(+09)h / (-02)h MOV AX,0009HMOV BL,FEHIDIV BLResult: (01FC)h => AX01 =>AH is the remainderFC =>AL is the quotient (-04)h

Page 67: 8086 segmentation and addressing modes

8086 sample programs

(-09)h / (+02)h MOV AX,FFF7HMOV BL,02HIDIV BLResult: (FFFC)h => AXFF =>AH is the remainder (-01)hFC =>AL is the quotient (-04)h

Page 68: 8086 segmentation and addressing modes

MOV AX,5000 H MOV DS,AXMOV SI,2500HMOV AX,6000HMOV ES,AXMOV DI,2500HCLDMOV CX,0004HREPNE CMPSB DS:[SI] - ES:[DI] and increment DI and SI (REPNE) HLT

MEMORY SOURCE

CONTENT MEMORYDEST

CONTENT

52500 42 62500 98

52501 45 62501 34

52502 34 62502 34

52503 23 62503 23

Page 69: 8086 segmentation and addressing modes

(CX=0004h) (DS=5000h)(SI=2500h)(DI=2500h)(ES=6000h)• 1st time REPNE CMPSB

DS:[SI] - ES:[DI] i.e. [52500]-[62500] i.e. 42-98(NE) SI =2501 and DI = 2501

CX=0003h(this is cos of REP prefix)• 2ND time REP CMPSB DS:[SI] - ES:[DI] i.e. [52501]-[62501] i.e. 45-34(NE) SI =2502 and DI = 2502

CX=0002h(this is cos of REP prefix)• 3rd Time REPNE CMPSBDS:[SI] - ES:[DI] i.e. [52502]-[62502] i.e. 34-34(E) SI =2503 and DI = 2503

CX=0001h(this is cos of REP prefix)• 4TH Time REPNE CMPSB will not happen cos locations are no

longer NE