You are on page 1of 2

CORLANG: Computer Organization and Assembly Language MEMORY SEGMENTS Only four of these segments can be active at any

one time. They are the code segment, stack segment, data segment, and extra segment Types of Segments 1. Code Segment. This contains the program or code. The address of the next instruction executed by the 8086/8088 is generated by adding the contents of IP (offset address) to the contents of CS x 10H. 2. Data Segment. This contains data referenced by almost all instructions and many addressing modes. Data are almost always moved into or out of MM via the data segment. The physical address of the data is generated by adding the contents of one of the index or pointer registers (BX, DI, or SI) to the contents of DS x 10H. 3. Stack Segment. This is for the LIFO stack. The physical address is a combination of the contents stack pointer (SP) plus SS x 10H. 4. Extra Segment. This is normally for string instructions. When a string instruction is executed, the destination location is addressed by the destination index register (DI) plus ES x 10H. 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. - 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). 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 Assume: BX = 1234H SS = 1800H SP = 3A74H Bottom of the Stack = 27FFFH Stack Segment = 18000H up to 27FFFH Top of the Stack = 1BA74H New SP = 3A72H New Top of Stack = 1BA72H 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 Assume: SS = 1234H SP = 281AH Bottom of the Stack = 2433FH Stack Segment = 12340H up to 2433FH Top of the Stack = 14B5AH New SP = 281CH New Top of Stack = 14B5CH Memory Segmentation, Stack and Addressing Page 1 of 2

CORLANG: Computer Organization and Assembly Language ADDRESSING MODES Addressing modes refer to the way in which an operand is specified. Case Study: MOV destination, source Types of Data Addressing Modes: 1. Register Addressing - The operand to be accessed is specified as residing in an internal Examples: MOV AX, CX MOV BX, DX 2. 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 MOV AX, 1A3F 3. Direct Addressing - The location following the instruction op-code 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. Examples: MOV AX, BETA MOV AX, LIST 4. 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. Examples: MOV AX, [BX] MOV AX, [SI] 5. 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. Examples: MOV AX, [BX + 1000H MOV AL, [BX] + BETA 6. 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. Examples: MOV AX, [BX + SI] MOV [BX + DI], SP 7. 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. Examples: MOV AX, [BX + SI + 0100H]; MOV AX, FILE[BX + DI]; Memory Segmentation, Stack and Addressing Page 2 of 2