460 likes | 1.25k Views
Addressing Mode. Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB. Addressing Mode.
E N D
Addressing Mode Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB.
Addressing Mode ในการพัฒนาโปรแกรมต่าง ๆ มีการอ้างถึงตำแหน่งของข้อมูล ตามที่มีในคำสั่งของไมโครโพรเซสเซอร์ ซึ่งมีหลายวิธีในการติดต่อ ดังนั้นสิ่งที่จะต้องเรียนรู้คือ Addressing Modeหรือวิธีการอ้างตำแหน่ง • วิธีการอ้างตำแหน่งแบ่งได้ 3 แบบคือ • Data Addressing Mode • Program Memory Addressing Mode • Stack Memory Addressing Mode
Data 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
Data Addressing Mode • Register Addressing • Transfer byte or word from source register or memory location to destination register or memory location
Data Addressing Mode MOV BX,CX
Data Addressing Mode • Immediate Addressing • Transfer source immediate byte or word of data into the destination register or memory location
Data Addressing Mode MOV EAX,13456H
Data Addressing Mode • Direct Addressing • Moves 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 Mode MOV AL,[1234H]
Data Addressing Mode • Register Indirect Addressing • Transfer byte or word between register and memory location address by index or base register
Data Addressing Mode MOV AX,[BX]
Data Addressing Mode • Base-Plus-Index Addressing • Transfer byte or word between register and memory location address by base register (BX or BP) plus index register (DI or SI)
Data Addressing Mode MOV DX,[BX+DI]
Data Addressing Mode • Register-Relative Addressing • Moves byte or word between register and memory location address by index or base register plus displacement
Data Addressing Mode MOV AX,[BX+1000H]
Data Addressing Mode • Base Relative-Plus-Index Addressing • Transfer byte or word between register and memory location address by base register and index register plus displacement
Data Addressing Mode MOV AX,[BX+SI+1000H]
Data Addressing Mode • Scale-Index Addressing • Available 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
Program Memory Addressing Mode • Used with the JMP and CALL instruction • มีใช้งาน 3 แบบคือ • Direct Program Memory Addressing • Relative Program Memory Addressing • Indirect Program Memory Addressing
Opcode Offset(low) Offset(High) Segment(low) Segment(high) E A 0 0 0 0 0 0 1 0 Direct Program Memory Addressing What many early microprocessors used for all jumps and calls and also used in high-level languages. For example, JMP [10000H] Used in intersegment jumps or often called far jump
Relative 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 jump or call (+127 and -128 byte from next instruction) and near jump or call (64K bytes)
Indirect Program Memory Addressing Allows several forms of program indirect memory addressing for JMP and CALL. This type of jump is sometimes called indirect-indirector double-indirect jump • Examples of indirect program memory addressing • JMP AX • JMP CX • JMP NEAR PTR [BX] • JMP TABLE [BX] • JMP ECX
Stack Memory Addressing Mode • The stack plays an importance role in all microprocessor. It holds data temporarily and stores return address of procedures. Used by PUSH and POP that maintained by two register • Stack Pointer register (SP or ESP) • Stack Segment register (SS)
Stack Memory Addressing Mode PUSH and POP a) PUSH BX b) POP CX
Instruction Set เป็นกลุ่มคำสั่งที่ไมโครโพรเซสเซอร์รู้จักและเข้าใจ ซึ่งสามารถแบ่งเป็นกลุ่มต่าง ๆ ได้ดังนี้ • Data Movement Instructions • Arithmetic and Logic Instructions • Program Control Instructions
Data Movement Instructions MOV Instruction Opcode 1-2 bytes MOD-REG-R/M 0-1 bytes Displacement 0-1 bytes Immediate 0-2 bytes 16 bits Instruction mode Address size 0-1 bytes Operand size 0-1 bytes Opcode 1-2 bytes MOD-REG-R/M 0-1 bytes Scaled-index 0-1 bytes Displacement 0-4 bytes Immediate 0-4 bytes 32 bits Instruction mode (80386,80486 and Pentium)
Data Movement Instructions • PUSH and POP • Load-Effective Address LEA LDS LES LFS LGS LSS • String Data Transfer LODS STOS MOVS INS OUTS • XCHG • LAHF and SAHF • XLAT • IN and OUT
Data Movement Instructions • MOVSX and MOVZX • BSWAP • CMOV • Segment Override Prefix
Arithmetic and Logic Instructions Addition • Register Addition • Immediate Addition • Memory to Register Addition • Array Addition • Increment Addition • Addition with Carry
Arithmetic and Logic Instructions Subtraction • Register Subtraction • Immediate Subtraction • Decrement Subtraction • Subtract with Borrow
Arithmetic and Logic Instructions Comparison • CMP (Compare) • CMPXCHG (Compare and Exchange) used in 80486 - Pentium
Arithmetic and Logic Instructions Multiplication • 8 bit Multiplication • 16 bit Multiplication • Special Immediate 16 bit Multiplication • 32 bit Multiplication
Arithmetic and Logic Instructions Division • 8 bit Division • 16 bit Division • 32 bit Division
Arithmetic and Logic Instructions BCD and ASCII • BCD Arithmetic • DAA • DAS • ASCII Arithmetic • AAA • AAD • AAM • AAS
Arithmetic and Logic Instructions Basic Logic • AND • OR • XOR • TEST and Bit Test • NOT and NEG
Arithmetic and Logic Instructions Shift • SHL • SHR • SAR • SAL • SHLD • SHRD
Arithmetic and Logic Instructions Rotate • ROL • ROR • RCL • RCR
Arithmetic and Logic Instructions Bit Scan Instruction • BSF • BSR StringComparisons • SCAS • CMPS
Program Comtrol Instructions Jump Group • Unconditional Jump (JMP) • Short Jump • Near Jump • Far Jump • Jumps with Register Operands • Indirect Jumps Using Index
Program Comtrol Instructions Jump Group • Conditional Jump and Condition Sets JA JAE JB JBE JC JE or JZ JG JGE JL JLE JNC JNE or JNZ JNO JNS JNP or JPO JO JP or JPE JS JCXZ JECXZ LOOP Condition LOOPs
Program Comtrol Instructions Procedures • CALL • Near CALL • Far CALL • CALL with Register Operands • CALL with Indirect Memory Address • RET
Program Comtrol Instructions Other Instructions • Interrupt Instructions • INT X • IRET/IRETD • WAIT • HLT • NOP
Program Comtrol Instructions Other Instructions • LOCK Prefix • ESC • BOUND • ENTER and LEAVE