44
Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB.

Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

Embed Size (px)

Citation preview

Page 1: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

Addressing Mode

Wannachai WannasawadeDepartment of Computer Education

Faculty of Technical Education, KMITNB.

Page 2: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

2

ในการพั�ฒนาโปรแกรมต่�าง ๆ ม�การอ้�าง ถึ�งต่�าแหน�งขอ้งข�อ้ม�ล ต่ามที่��ม�ในคำ�าสั่��งขอ้ง

ไมโคำรโพัรเซสั่เซอ้ร" ซ��งม�หลายวิ%ธี� ในการต่%ดต่�อ้ ด�งน�(นสั่%�งที่��จะต่�อ้งเร�ยนร� �คำ+อ้

Addressing ModeAddressing Mode หร+อ้วิ%ธี�การวิ%ธี�การอ้�างต่�าแหน�งอ้�างต่�าแหน�ง

วิ%ธี�การอ้�างต่�าแหน�งแบ่�งได� วิ%ธี�การอ้�างต่�าแหน�งแบ่�งได� 3 3 แบ่บ่คำ+อ้แบ่บ่คำ+อ้ Data Addressing ModeData Addressing Mode Program Memory Addressing ModeProgram Memory Addressing Mode Stack Memory Addressing ModeStack Memory Addressing Mode

Page 3: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

3Data Addressing ModeData Addressing Mode Register addressing Immediate addressing Direct addressing Register indirect address Base-plus-index addressing Register relative addressing Base relative-plus-index addressing Scaled-index address

Page 4: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

4

Register AddressingRegister AddressingTransfer byte or word from source register or memory location to destination register or memory location

Data Addressing ModeData Addressing Mode

Page 5: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

5Data Addressing ModeData Addressing ModeMOV BX,CX

Page 6: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

6

Immediate AddressingImmediate AddressingTransfer source immediate byte or word of data into the destination register or memory location

Data Addressing ModeData Addressing Mode

Page 7: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

7Data Addressing ModeData Addressing ModeMOV EAX,13456H

Page 8: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

8

Direct AddressingDirect AddressingMoves byte or word between a memory location and register

Direct Addressing move between memory location and AL,AX or EAX Displacement Addressing applies to almost any instruction in the instruction set

Data Addressing ModeData Addressing Mode

Page 9: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

9Data Addressing ModeData Addressing Mode

Page 10: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

10Data Addressing ModeData Addressing ModeMOV AL,[1234H]

Page 11: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

11

Register Indirect AddressingRegister Indirect AddressingTransfer byte or word between register and memory location address by index or base register

Data Addressing ModeData Addressing Mode

Page 12: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

12Data Addressing ModeData Addressing ModeMOV AX,[BX]

Page 13: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

13

Base-Plus-Index AddressingBase-Plus-Index AddressingTransfer byte or word between register and memory location address by base register (BX or BP) plus index register (DI or SI)

Data Addressing ModeData Addressing Mode

Page 14: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

14Data Addressing ModeData Addressing ModeMOV DX,[BX+DI]

Page 15: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

15

Register-Relative AddressingRegister-Relative AddressingMoves byte or word between register and memory location address by index or base register plus displacement

Data Addressing ModeData Addressing Mode

Page 16: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

16Data Addressing ModeData Addressing ModeMOV AX,[BX+1000H]

Page 17: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

17

Base Relative-Plus-Index AddressingBase Relative-Plus-Index AddressingTransfer byte or word between register and memory location address by base register and index register plus displacement

Data Addressing ModeData Addressing Mode

Page 18: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

18Data Addressing ModeData Addressing ModeMOV AX,[BX+SI+1000H]

Page 19: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

19

Scale-Index AddressingScale-Index AddressingAvailable 80386-Pentium used second register of pair of register is modified by the scale factor of 2X, 4X or 8X to generate the operand memory address

Data Addressing ModeData Addressing Mode

Page 20: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

20Program Memory Program Memory Addressing ModeAddressing ModeUsed with the JMP and CALL

instruction

ม�ใช้�งาน 3 แบ่บ่คำ+อ้

Direct Program Memory Direct Program Memory

AddressingAddressing

Relative Program Relative Program

Memory AddressingMemory Addressing

Indirect Program Indirect Program

Memory AddressingMemory Addressing

Page 21: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

21

OpcodeOffset(low)Offset(High) Segment(high)Segment(low)

E A 0 0

0 0

0 0

1 0

Direct Program Memory AddressingDirect Program Memory AddressingWhat many early microprocessors

used for all jumps and calls and also

used in high-level languages. For

example, JMP [10000H]

Used in intersegment jumpsintersegment jumps or often called ffar jumpar jump

Page 22: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

22Relative Program Memory AddressingRelative Program Memory Addressing

Not available in all early

microprocessors, but available to

some family of microprocessors.

Relative means relative to

instruction Pointer (IP) used in

short jumpshort jump or call (+127 and -

128 byte from next instruction)

and near jumpnear jump or call (64K bytes)

Page 23: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

23Indirect Program Memory AddressingIndirect Program Memory AddressingAllows several forms of program indirect memory addressing for JMP and CALL. This type of jump is sometimes called indirect-indirectindirect-indirect or double-indirect jumpdouble-indirect jumpExamples of indirect program memory addressing

JMP AXJMP CXJMP NEAR PTR [BX]JMP TABLE [BX]JMP ECX

Page 24: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

24Stack Memory Addressing ModeStack Memory Addressing Mode

The stack plays an importance

role in all microprocessor. It

holds data temporarily and

stores return address of

procedures. Used by PUSHPUSH and

POPPOP that maintained by two

register

Stack Pointer register (SP

or ESP)

Stack Segment register

(SS)

Page 25: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

25Stack Memory Addressing ModeStack Memory Addressing ModePUSH and POP a) PUSH BXPUSH BX b) POP CXPOP CX

Page 26: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

26

เป.นกล/�มคำ�าสั่��งที่��ไมโคำรโพัรเซสั่เซอ้ร"ร� �จ�ก และเข�าใจ ซ��งสั่ามารถึแบ่�งเป.นกล/�มต่�าง ๆ

ได�ด�งน�( Data Movement

Instructions

Arithmetic and Logic

Instructions

Program Control

Instructions

Page 27: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

27

Opcode 1-2 bytesMOD-REG-R/M

0-1 bytesDisplacement

0-1 bytesImmediate0-2 bytes

16 bits Instruction mode

Opcode 1-2 bytes

MOD-REG-R/M0-1 bytes

Displacement0-4 bytes

Immediate0-4 bytes

Scaled-index0-1 bytes

Operand size0-1 bytes

Address size0-1 bytes

32 bits Instruction mode(80386,80486 and Pentium)

MOV InstructionMOV Instruction

Page 28: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

28

PUSH and POP Load-Effective Address

LEA LDS LESLFS LGS LSS

String Data TransferLODS STOS MOVSINS OUTS

XCHG LAHF and SAHF XLAT IN and OUT

Page 29: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

29

MOVSX and MOVZX

BSWAP

CMOV

Segment Override Prefix

Page 30: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

30

AdditionAddition Register Addition Immediate Addition Memory to Register Addition Array Addition Increment Addition Addition with Carry

Page 31: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

31

SubtractionSubtraction Register Subtraction Immediate Subtraction Decrement Subtraction Subtract with Borrow

Page 32: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

32

ComparisonComparison CMP (Compare) CMPXCHG (Compare and Exchange) used in 80486 - Pentium

Page 33: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

33

MultiplicationMultiplication 8 bit Multiplication 16 bit Multiplication Special Immediate 16 bit Multiplication 32 bit Multiplication

Page 34: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

34

DivisionDivision 8 bit Division 16 bit Division 32 bit Division

Page 35: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

35

BCD and ASCIIBCD and ASCII BCD Arithmetic

DAA DAS

ASCII Arithmetic AAA AAD AAM AAS

Page 36: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

36

Basic LogicBasic Logic AND OR XOR TEST and Bit Test NOT and NEG

Page 37: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

37

Shift Shift SHL SHR SAR SAL SHLD SHRD

Page 38: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

38

RotateRotate ROL ROR RCL RCR

Page 39: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

39

Bit Scan InstructionBit Scan Instruction BSF BSR

StringString ComparisonsComparisons SCAS CMPS

Page 40: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

40

Jump GroupJump Group Unconditional Jump (JMP)

Short Jump Near Jump Far Jump Jumps with Register Operands Indirect Jumps Using Index

Page 41: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

41

Jump GroupJump Group Conditional Jump and Condition SetsJA JAE JB JBEJC JE or JZ JG JGEJL JLE JNC JNE or JNZJNO JNS JNP or JPO JOJP or JPE JS JCXZJECXZLOOP Condition LOOPs

Page 42: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

42

ProceduresProcedures CALL

Near CALL Far CALL CALL with Register Operands CALL with Indirect Memory Address

RET

Page 43: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

43

Other InstructionsOther Instructions Interrupt Instructions

INT X IRET/IRETD

WAIT HLT NOP

Page 44: Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB

44

Other InstructionsOther Instructions LOCK Prefix ESC BOUND ENTER and LEAVE