19
* Property of STI Page 1 of 19 Memory Segmentation, Stacks and Addressing Modes Computer Organization and Assembly Language Memory Segments Code Segment Stack Segment Data Segment Extra Segment CS SS DS ES Segment Registers

MELJUN CORTES Memory segmentation, stacks and addressing modes

Embed Size (px)

Citation preview

Page 1: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 1 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Memory Segments

CodeSegment

StackSegment

DataSegment

ExtraSegment

CSSSDSES

SegmentRegisters

Page 2: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 2 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Types of Segments

Ø Code Segment. This contains the program or code.

Ø Data Segment. This contains data referenced by almost all instructions and many addressing modes.

Ø Stack Segment. This is for the LIFO stack.

Ø Extra Segment. This is normally for string instructions.

Page 3: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 3 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Stack

Ø The stack is implemented in MM of the 8086/8088. It is 64KB long and is organized from a software point of view as 32K words.

Ø The lowest-addressed byte in the current stack is pointed to by the base address in the SS register.

Page 4: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 4 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Stack

Ø The SP contains an offset from the value in SS. The address obtained in the SS and SP is the physical address of the top of the stack or TOS (the last storage location in the stack to which data were pushed).

Ø The value of SP is initialized to FFFFH upon start-up of the microcomputer.

Page 5: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 5 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Pushing a Data onto the Stack

Ø Whenever a word of data is pushed onto the stack, the high-order 8 bits are placed in the location addressed by SP - 1, and the low-order 8 bits are placed in the location addressed by SP - 2.

Ø SP is then decremented by 2 so that the next word of data is stored in the next available memory location.

Ø Example:PUSH BX

Page 6: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 6 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Example 1

Ø Assume the following register contents:

AX =4A30H BP =0008H CS =8000HBX =0010H SP =0040H DS =8000HCX =1800H DI =0006H SS =8002HDX =1234H SI =0040H ES =9000H

Ø After the PUSH BP instruction is executed, what will be the contents of BP, SS, and SP?

Page 7: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 7 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Popping a Data onto the Stack

Ø Whenever a word of data is popped from the stack, the low-order 8 bits are removed from the location addressed by SP, and the high-order 8 bits are removed from the location addressed by SP + 1.

Ø SP is then incremented by 2.

Ø Example:POP CX

Page 8: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 8 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Example 2

Ø Assume the following register contents:

AX =4A30H BP =0008H CS =8000HBX =0010H SP =0040H DS =8000HCX =1800H DI =0006H SS =8002HDX =1234H SI =0040H ES =9000H

Ø After the PUSH AX instruction is executed, what will be the contents of BP, SS, and SP?

Page 9: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 9 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Exercise 1

Ø Assume the following register contents:

AX =4A30H BP =0008H CS =8000HBX =0010H SP =0040H DS =8000HCX =1800H DI =0006H SS =8002HDX =1234H SI =0040H ES =9000H

Ø Given the following program segment:PUSH CXPUSH BXPUSH DL

Ø Assume that instructions are dependent on one another.

Page 10: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 10 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Exercise 2

Ø Assume the following register contents:

AX =4A30H BP =0008H CS =8000HBX =0010H SP =0040H DS =8000HCX =1800H DI =0006H SS =8002HDX =1234H SI =0040H ES =9000H

Ø Given the following program segment:POP BXPOP BPPOP SI

Ø Assume that instructions are dependent on one another.

Page 11: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 11 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Addressing Modes

Ø Addressing modes refer to the way in which an operand is specified.

Ø Types of Data Addressing Modes:v Register Addressing v Immediate Addressingv Direct Addressingv Register Indirect Addressingv Register Relative Addressing or Base

Addressingv Base-Plus-Index Addressingv Base-Relative-Plus-Index Addressing

Page 12: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 12 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Register Addressing

Ø The operand to be accessed is specified as residing in an internal register of the 8086/8088.

Ø Examples:

MOV AX, CX; AX [CX]MOV BX, DX; BX [DX]

Page 13: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 13 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Immediate Addressing

Ø The source operand is part of the instruction instead of the contents of a register. Typically, immediate operands represent constant data.

Ø Examples:

MOV AL, 15H; AL 15HMOV AX, 1A3F; AX 1A3FH

Page 14: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 14 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Direct Addressing

Ø The location following the instruction opcode holds an effective memory address (EA) instead of data. This EA is the 16-bit offset of the storage location specified by the current value of the DS register.

Example 1:

MOV AX, BETA

Example 2:

MOV AX, LIST

Page 15: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 15 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Register Indirect Addressing

Ø Similar to direct addressing but this time, the EA resides in either a base register (BX, BP) or index register (SI, DI) within the 8086/8088.

Example 1:

MOV AX, [BX]

Example 2:

MOV AX, [SI]

Example 3:

MOV CX, [BP]

Page 16: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 16 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Register Relative Addressing or Base Addressing

Ø The physical address of the operand is obtained by adding a direct or indirect displacement to the contents of either BX or BP and the current value in DS or SS, respectively.

Example 1:

MOV AX, [BX + 1000H]

Example 2:

MOV AL, [BX] + BETA

Example 3:

MOV DI, SET[BX]

Page 17: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 17 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Base-Plus-Index Addressing

Ø This is used to transfer a byte or word between a register and the memory location indicated by the sum of a base register and an index register.

Example 1:

MOV AX, [BX + SI]

Example 2:

MOV [BX + DI], SP

Page 18: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 18 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Base-Relative-Plus-Index Addressing

Ø This is used to transfer a byte or word between a register and the memory location addressed by a base register and an index register plus a displacement.

Example 1:

MOV AX, [BX + SI + 0100H];

Example 2:

MOV AX, FILE[BX + DI];

Page 19: MELJUN CORTES Memory segmentation, stacks and addressing modes

* Property of STIPage 19 of 19

Memory Segmentation, Stacks and Addressing Modes

Computer Organization and Assembly Language

Exercise

Ø Identify the addressing mode of the following instructions:

1. ADD AX, FADEH2. CMP FADE, AX3. INC DH4. ADC [BP+1800H], BX5. AND AGAIN[BP+SI], DS6. OR DX, [DI]7. ADC AX, [BP+SI]