25
© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved. Brey: The Intel Microprocessors, 7e Chapter 3 Chapter 3  Addressing Modes  Addressing Modes Barry B. Brey Barry B. Brey [email protected] [email protected]

brey_ch3

Embed Size (px)

Citation preview

Page 1: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 1/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Chapter 3Chapter 3

 Addressing Modes Addressing Modes

Barry B. BreyBarry B. [email protected]@ee.net

Page 2: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 2/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

 Addressing Modes Addressing Modes

In order to write a program addressing modesIn order to write a program addressing modes

must be thoroughly understood.must be thoroughly understood.

There are many addressing modes, but the mostThere are many addressing modes, but the most

common are easy to master and represent mostcommon are easy to master and represent most

instructions in most programs.instructions in most programs.

Register addressing, immediate addressing,Register addressing, immediate addressing,

direct addressing, and simple forms of indirectdirect addressing, and simple forms of indirectaddressing are the most common addressingaddressing are the most common addressing

modes.modes.

Page 3: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 3/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Stack addressing is also used with theStack addressing is also used with the

PUSH and POP instructions and as a wayPUSH and POP instructions and as a wayto link a program to its procedures or to link a program to its procedures or 

functions.functions.

Program flow instructions are either Program flow instructions are either 

unconditional or conditional.unconditional or conditional.

Conditional program flow instructions areConditional program flow instructions are

the ³if´ statements of assembly language.the ³if´ statements of assembly language.

Page 4: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 4/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Data Addressing ModesData Addressing Modes

Data addressing modes are presents withData addressing modes are presents with

the MOV instruction because it is by far the MOV instruction because it is by far 

the most common instruction in a program.the most common instruction in a program. MOV really moves nothing. MOV copiesMOV really moves nothing. MOV copies

the source into the destination. It probablythe source into the destination. It probably

should be named COP for copy, but it isshould be named COP for copy, but it is

not.not.

Page 5: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 5/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 6: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 6/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 7: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 7/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Register Register 

MOV EAX,EBXMOV EAX,EBX

MOV CX,DXMOV CX,DX

MOV AH,ALMOV AH,AL MOV AX,DSMOV AX,DS

MOV ES,CXMOV ES,CX

 ADD AL,CL (most instructions use it) ADD AL,CL (most instructions use it) OR AX,DXOR AX,DX

Page 8: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 8/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 9: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 9/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

ImmediateImmediate

MOV EAX,234HMOV EAX,234H

MOV CX,2MOV CX,2

MOV AL,34HMOV AL,34H ADD AL,3 ADD AL,3

SUB CL,4SUB CL,4

 AND EAX,1 AND EAX,1

Page 10: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 10/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 11: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 11/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

DirectDirect

MOV BOB,EAXMOV BOB,EAX

MOV FRED,CXMOV FRED,CX

MOV BILLY,ALMOV BILLY,AL MOV EDI,RALPHMOV EDI,RALPH

MOV AX,STEVEMOV AX,STEVE

MOV DS,BARNEYMOV DS,BARNEY MOV AL,DS:[1000H]MOV AL,DS:[1000H]

Page 12: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 12/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 13: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 13/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Register IndirectRegister Indirect

MOV AL,[BX]MOV AL,[BX]

MOV AX[EBX]MOV AX[EBX]

MOV [EDI],EAXMOV [EDI],EAX MOV [EAX],EDXMOV [EAX],EDX

MOV BYTE PTR [EAX],6MOV BYTE PTR [EAX],6

MOV WORD PTR [ECX],12MOV WORD PTR [ECX],12 MOV DWORD PTR [ESI],2345HMOV DWORD PTR [ESI],2345H

Page 14: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 14/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 15: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 15/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Base Plus IndexBase Plus Index

MOV AL,[BX+SI]MOV AL,[BX+SI]

MOV [BX+DI],AXMOV [BX+DI],AX

MOV [BP+SI],EAXMOV [BP+SI],EAX MOV AL,[BP+DI]MOV AL,[BP+DI]

MOV WORD PTR [BX+SI],5MOV WORD PTR [BX+SI],5

 ADD AL,[BX+DI] ADD AL,[BX+DI]

Page 16: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 16/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 17: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 17/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Register RelativeRegister Relative

MOV AL,[BX+3]MOV AL,[BX+3]

MOV AX,[DI+20H]MOV AX,[DI+20H]

MOV [EDI+200H],EAXMOV [EDI+200H],EAX MOV [BXMOV [BX--33],ECX33],ECX

 ADD BYTE PTR [BX+2],5 ADD BYTE PTR [BX+2],5

Page 18: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 18/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 19: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 19/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Relative Plus IndexRelative Plus Index

MOV AL,[BX+SI+22]MOV AL,[BX+SI+22]

MOV [BX+DIMOV [BX+DI--22],AX22],AX

MOV EAX,[EBX+EDI+100H]MOV EAX,[EBX+EDI+100H]

Page 20: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 20/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Page 21: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 21/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Scaled IndexScaled Index

MOV EAX,[EBX+ 4*ECX]MOV EAX,[EBX+ 4*ECX]

MOV AX,[EDI+2*EBX]MOV AX,[EDI+2*EBX]

MOV [EAX+2*EBX],DXMOV [EAX+2*EBX],DX MOV [4*ECX],EBXMOV [4*ECX],EBX

 ADD AL,[ECX+EBX] ADD AL,[ECX+EBX]

Page 22: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 22/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

Program FlowProgram Flow

Program flow instruction are unconditionalProgram flow instruction are unconditional

(JMP) or conditional (JNZ).(JMP) or conditional (JNZ).

Flow instructions are short (Flow instructions are short (+127,+127, --128),128),near (near (±±32K), or far (anywhere in the32K), or far (anywhere in the

memory).memory).

Conditionals do not contain the far type.Conditionals do not contain the far type.

Labels are followed by a colon if they areLabels are followed by a colon if they are

 jumped to in a program. jumped to in a program.

Page 23: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 23/25

Page 24: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 24/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e

PUSH AXPUSH AX

PUSH EAXPUSH EAX POP AXPOP AX

POP EAXPOP EAX

PUSH BOBPUSH BOB POP BOBPOP BOB

PUSHFPUSHF

POPFPOPF

Page 25: brey_ch3

8/8/2019 brey_ch3

http://slidepdf.com/reader/full/breych3 25/25

© 2006 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved.Brey: The Intel Microprocessors, 7e