Docsity

Data Addressing Mode - Microprocessors and Computer Systems - Lecture Slides, Slides of Microprocessors

Partial preview of the text

Download Data Addressing Mode - Microprocessors and Computer Systems - Lecture Slides and more Slides Microprocessors in PDF only on Docsity!

Data Addressing Mode

Outline^ aIntroduces various data addressing modes of the8088 for memory retrieval and storage.^ Register addressing mode,^Immediate addressing mode,^ Direct addressing mode,^register indirect addressing mode,^ Based addressing mode,^Indexed addressing mode,^ Based indexed addressing mode,^String addressing mode, and^ `Port addressing mode.

a^ Instruction gets its source data from a register. a^ Data can be either 8 or 16 bits in length a^ Data resulting from the operation is stored in another register.^ Examples:^ MOV AX, BX

; copy the 16-bit content of BX to AXMOV AL, BL ; copy the 8-bit content of BL to ALMOV SI, DI ; copy DI into SIMOV DS, AX^ ; copy AX into DS Note: The following register to register transfers are not permitted:MOV BL, BX

; Not permitted (mixed sizes)MOV CS, AX^ ; Not permitted (CS cannot be the destination) (?)MOV ES, DS^ ; Not allowed (segment register to segment register forbidden)

1. Register Addressing Mode^ Destination

Source

2. Immediate Addressing Mode^ a^ Immediate data is coded directly in the instruction’s machine code.^ a^ The data is put in the operand field as a content.^ a^ The constant in the operand field may be of byte or word length.^ a^ Some assemblers need a “#” symbol before the constant (Not needed inMASM nor Turbo Assembler). The constant may be in hexadecimal,decimal, binary or even text. The default format is decimal.^ ^ Hexadecimal numbers are usually denoted by appending an H (or h) andpreceded by 0 if they start with a letter e.g. 0Fh, 0A8h, 0F34Bh^^ Binary numbers are usually denoted by appending a B (or b).^ `^ Text characters (their ASCII code) are enclosed by apostrophe(‘).

MOV AL, 0Ah

; load 0Ah into AL

3. Direct Addressing ModeMOV [1234h], AL a The operand is stored in a MEMORY location, usually in the Data Segment. a A 16-bit offset address is coded directly in the instruction. The offset and DS(DS: Data Segment Register in CPU) form the 20-bit address where theoperand is located. The 20-bit address is calculated by multiplying DS by 16(or equivalently appending a 0) and adding to the offset. a Usually the 16-bit offset used in direct addressing is written as a label in anassembly language program. Or the offset is enclosed in [ ] to indicate that it isan address (not immediate data). a The default segment register is assumed to be the DS unless explicitly over-ridden using a colon, e.g. ES:[0001h].

; copies AL to 11234h; Assume DS=1000h

3. Direct Addressing Mode (cont.) Examples:^ (Assume DS=1000h, ES=2000h, FRED=4567h)MOV AX, [20h]

; load the contents at address 10020h and 10021h; into AL and AH, respectively MOV [1234h], AL

; copy AL to address 11234h MOV ES:[1234h], AL

; copy AL to address 21234h MOV FRED, AL

; copy AL to address14567h (offset is calculated by the; assembler)

4. Register Indirect Addressing Mode(cont.)^ a^ Registers indirect addressing is commonly used to access a table of datain memory.^ Examples

(with BX=0222h, DS=1000h, SS=2000h, BP=0111h)MOV CX, [BX]^

; copy a word from address 10222h and 10223h to CX MOV [BP], DL

; copy a byte from register DL to address 20111h Note : BP defaults to SS

5. Based Addressing Mode a^ The operand is located at the address given by (i) adding an 8- or 16-bitdisplacement to either BX or BP and (ii) combining the result with a segmentregister. a^ The 8- or 16-bit displacement must be specified in the operand field and isinterpreted as a signed 2’s complement value. For the 8-bit case, thedisplacement must be in the range -128 to +127; and for the 16-bit case, thedisplacement must be in the range -32768 to 32767.^ Examples

(with DS=1000h, SS=2000h, BP=0222h, BX=0111h)MOV AX, [BP-2]^

; copy the content of 20220h and 20221h to AX MOV [BX+777h], AX

; copy AL to 10888h and AH to 10889h

6. Indexed Addressing (cont.)^ a^ Based addressing and Indexed addressing are also known as REGISTERRELATIVE addressing as defined in Brey’s.^ a^ Other syntax may be permitted to indicate the displacement.^ a^ Note: The following examples are all equivalent. And they all result in thesame assembled binary code. (Assume FRED is a label which isassigned by the assembler a constant value -- an address.)^ Examples:^ MOV [DI+FRED], BL

; This syntax is used above MOV [DI]+FRED, BLMOV FRED[DI], BL

7. Based Index Addressing (withdisplacement)^ a^ The base and index registers are added to give the segment offset ofwhere the operand is located.^ a^ The base register (either BX or BP) is added to an index register (eitherDI or SI) as POSITIVE integers only (each register lies in the range 0 to65535).^

Q: what if the resultant offset >65535? a^ By default, the segment address is derived from DS, except the BPregister, which is derived from SS. a^ A signed displacement may also be included to calculate the offset.^ Example

(assumes SS=1000h, SI=3333h, BP=2222h)MOV AX, [SI+BP]^ ; load the content of 15555h and 15556h to; AL and AH respectivelyMOV AX, [SI+BP+1111h]; load the contents of 16666H and; 16667h to AL and AH respectivelyNote: This addressing mode includes the base-plus-index and base-relative-plus-index addressing modes defined in Brey’s.

9. Port Addressing Mode^ a^ The Intel 8088 has separate memory and input/output space.^ a^ Up to 65536 I/O ports are available^ a^ The I/O ports may be addressed by a byte sized constant (limited to I/Oports in the range 0 to 255)^ Example:^ IN AL, 40h

; put the content of I/O port 40H into ALOUT 80h, AL^ ; send the contents of AL to I/O port 80h a^ The I/O ports may be addressed using the register DX (full range of65536 ports are accessible)^ Examples:^ IN AL, DX

; Load AL with the byte from port address given by DXOUT DX, AX^ ; Send the word in AX to port address given by DXQ: Is the instruction “MOV AL, DX;” valid?

Summary of Addressing Modes^ Operand needed for an instruction may be located :^ a^ immediately in the operand field.

e.g. MOV AX, 1234h a^ in a register (register addressing).

e.g. MOV DS, AX;

a^ in memory at a specified offset. The offset may be specified by one of thefollowing (displacement is a constant or label expression):^ ‹^ [displacement]^ ‹^ [BP]

‹[BP+displacement] ‹^ [BX]^

‹[BX+displacement] ‹^ [SI]^

‹[SI+displacement] ‹^ [DI]^

‹[DI+displacement] ‹^ [BX+SI]^

‹[BX+SI+displacement] ‹^ [BX+DI]^

‹[BX+DI+displacement] ‹^ [BP+SI]^

‹[BP+SI+displacement] ‹^ [BP+DI]^

‹[BP+DI+displacement]

  • The segment address is in DS

(by default, except when BP is used)

a^ in memory locations given implicitly by string instructions. a^ at input/output ports specified by a register or a constant.

See Brey’s Table 3-12for more examples

Other Addressing Modes a^ Programming memory-addressing mode states how to modify the flow ofthe program using Jump and Call instruction. a^ See Jump and Call instruction for more information.Example:JMP CX

; Jump to the current code segment location addressed by; the content of CX. a^ Stack addressing mode uses the PUSH and POP instruction to transferdata between the stack memory and registers or direct data.Example:POPF

; Remove a word from stack and place it into the flagPUSH DS^ ; Copy DS to the stackPUSH 1234h^ ; Copy a 1234h to the stack

Pros and Cons of Different DataAddressing Modes Mode^

Algorithm

PrincipalAdvantage

PrincipalDisadvantage

Register^

EA = R^

No memoryreference

Limited addressspace

Immediate^

Operand = A

No memoryreference

Limited operandmagnitude

Direct^

EA = A^

Simple^

Less flexible

Registerindirect

EA = (R)^

Large addressspace

Extra memoryreference

Base-IndexRelative

EA = A + (R)

Flexibility^

Complexity

Stack^

EA = top ofstack

No memoryreference

LimitedapplicabilityEA: effective addressR: RegisterA: a constant

Example MOV AX,BXMOV CH, 3AhMOV [123h], AXMOV [BX], CLMOV [BX+SI+30h], DXPOP^ DX