Friday, November 23, 2012


Addressing Modes of Pentium Processor
Addressing mode indicates a way of locating data or operands. Depending upon the data types used in the instruction and the memory addressing modes, any instruction may belong to one or more addressing modes, or some instruction may not belong to any of the addressing modes. Thus the addressing modes describe the types of operands and the way they are accessed for executing an instruction. Here, we will present the addressing modes of the instructions depending upon their types.
         Pentium supports three fundamental addressing modes:
*        Register mode
*        Immediate mode
*        Memory mode
         Specification of operands located in memory can be done in a variety of ways
*        Mainly to support high-level language constructs and data structures
Pentium Addressing Modes (32-bit Addresses)
Addressing Modes:
1.  Immediate Addressing Modes
2.  Register Addressing Modes
3.  Memory Addressing Modes
a.  Direct(Displacement) Addressing Modes
b.  Indirect Addressing Modes
·      Register Indirect[ Base]
·      Based[Base+Displacement]
·      Indexed[(Index*Scale)+Displacement]
·      Based Indexed
1.      Based-indexed with no scale factor [Base+Index+Disp]
2.      Based-indexed with scale factor
3.      [Base+(Index*scale)+Disp]
 
Differences between 16- and 32-bit Modes
16-bit addressing
32-bit addressing
Base register
BX, BP
EAX, EBX, ECX,
EDX, ESI, EDI,
EBP, ESP
Index register       
SI, DI
EAX, EBX, ECX,EDX, ESI, EDI,
EBP
Scale factor
None
1, 2, 4, 8
Displacement
0, 8, 16 bits
0, 8, 32 bits
Immediate Mode In this type of addressing, immediate data is a part of instruction, and appears in the form of successive byte or bytes.
§         mov eax,567
§         mov ah, 09h
§         mov dx, offset Prompt
Register Addressing mode: In register addressing mode, the data is stored in a register and it is referred using the particular register. All the registers, except IP, may be used in this mode.
Example: MOV BX, AX.
Memory Addressing mode
·        Direct Addressing mode
·        Indirect Addressing mode
Direct Addressing mode: In the direct addressing mode, a 16-bit memory address (offset) is directly specified in the instruction as a part of it.
Example: MOV AX, [5000H]
Here, data resides in a memory location in the data segment, whose effective address may be computed using 5000H as the offset address and content of DS as segment address. The effective address, here, is 10H*DS+5000H.
Example: add eax, [value]
Indirect Addressing mode
1.Register Indirect: often used for addressing data arrays inside programming loops,Sometimes, the address of the memory location, which contains data or operand, is determined in an indirect way, using the offset registers. This mode of addressing is known as register indirect mode. In this addressing mode, the offset address of data is in either BX or SI or DI registers. The default segment is either DS or ES. The data is supposed to be available at the address pointed to by the content of any of the above registers in the default data segment.
Example: MOV AX, [BX]
Here, data is present in a memory location in DS whose offset address is in BX. The effective address of the data is given as 10H*DS+ [BX].
Effective address of operand contained in a register.
For 32-bit addressing, all 32-bit registers can be used.
For 16-bit addressing, the offset value can be in one of the three registers: BX, SI, or DI:  
Example:add ax, [bx] ; Register indirect addressing
    • Square brackets [ BX ] indicate that BX is holding a memory offset.
    • Operand [ BX ] serves as a pointer to data in memory.
    • Register indirect can be used to implement arrays.
2.Indexed: In this addressing mode, offset of the operand is stored in one of the index registers.
constant base + register.
    • Fixed Base (address) + Variable Register Offset (operand field contains a constant base)
    • Effective address is obtained by adding value of operand field to contents of register.
This is known as array type addressing, also called displacement addressing.
 mov eax, [ ebx + 5 ]
mov eax, [ ebx + esi + 5 ]
There are restrictions on the combinations of registers allowed within the brackets: you can have ESI or EDI, but not both, and you can have EBX or EBP, but not both.
Indexing With Scaling: Base + Register Offset * Scaling Factor
    • Operand field contains base address.
    • Useful for array calculations where size of component is multiple bytes long.
  • Stack Addressing: PUSH and POP, a variant of register indirect with auto-increment/decrement using the ESP register implicitly.
  • Jump relative addressing, EIP + offset
    • Operand field contains a displacement.
    • Used by near and short jump instructions
Based Indexed:
Based Indexed is of two types
1.      Based-indexed addressing with no scale factor
2.      Based-indexed addressing with scale factor
Based-indexed addressing with no scale factor
         Effective address is computed as
                        Base + Index + signed displacement
         Useful in accessing two-dimensional arrays
»         Displacement ==> points to the beginning of the array
»         Base and index registers point to a row and an element within that row
         Useful in accessing arrays of records
»         Displacement ==> represents the offset of a field in a record
»         Base and index registers hold a pointer to the base of the array and the offset of an element relative to the base of the array
         Useful in accessing arrays passed on to a procedure
»         Base register ==> points to the beginning of the array
»         Index register ==> represents the offset of an element relative to the base of the array
Example
            Assuming EBX points to table1
                        mov  EAX,[EBX+ESI]
                        cmp      EAX,[EBX+ESI+4]
Based-indexed addressing with scale factor
         Effective address is computed as
                        Base + (Index * scale factor) + signed displacement
         Useful in accessing two-dimensional arrays when the element size is 2, 4, or 8 bytes
»         Displacement ==> points to the beginning of the array
»         Base register ==> holds offset to a row (relative to start of array)
»         Index register ==> selects an element of the row
»         Scaling factor ==> size of the array element
            compares two successive elements of table1 

0 comments:

Post a Comment