DAT x86 “Real” Memory Addressing © Alan T. Pinck / Algonquin College; 2003
“Real” Memory Space In Intel/Microsoft terminology, “real” memory is the first 1 Megabyte of memory (memory beyond this is “protected” or “extended” memory and will not be discussed in this course). “Real” memory requires a 20-bit address (5 hex digits)
Addresses and Words A Intel 8086 word : 16 bits (2 bytes) Addresses are specified using word values (often contained in 16-bit/word registers) Problem: how to create a 20-bit address when only 16-bit (word) values are available.
Offset Addresses: Accessibility with a Word Address Assuming some (20-bit) base location, a 16- bit (word) address could be used to measure a distance or “offset” from that base location to any location between 0 and 64K bytes beyond that base location. Example (assuming a base location of 2A340 hex) a 16-bit offset value 47E2 (hex) would provide the address for a “real” memory location 2EB22 (hex).
Segment Addresses A “segment” is the maximum amount of “real” memory which can be addressed using a 16-bit offset from some “base location”. The “base location” for a segment is specified as a 16-bit value, called a “segment address”, which is the number of pages (1 page = 10 hex / 16 dec bytes) from the beginning of memory.
Combining Segment and Offset Addresses A segment address can be converted from a 16-bit page number into a 20-bit “real” memory (byte) value by multiplying it by 10 hex (since there are 10 hex bytes per page). Segment and Offset combinations are usually written as: segment:offset As an example 2A34:47E2, which can be converted into a “real” (byte) address as 2A34 * 10 h = 2A340 plus 47E2 = 2EB22
The Segment Registers In the Intel 8086 : 4 Registers used for Segment Addresses CSbeginning of the current code (instruction) segment area DSbeginning of the main (default) data segment area ESbeginning of a secondary data segment area SSbeginning of an area use for the “stack” (mainly used to hold function return addresses and temporary local variables)
The Offset Registers In the Intel 8086: 6 Registers use for Offsets IPinstruction pointer: (with CS) offset to next instruction to be executed BXbase index: (default, with DS) offset to a data value SIsource index: (default, with DS) offset to a data value (often the “source” of a “source-destination” pair DIdestination index: (default, with ES or DS depending on instruction) offset to a data value SPstack pointer: (with SS) offset to last value stored on the stack BPbase pointer: (default, with SS) offset to data value in the stack to permit access/manipulation of value in the stack without “losing” track of the top of the stack.
Real Memory Address Calculation Examples (1) MOV [BX],0Dh ;location of memory ; specified by the value in BX By default, BX combines with DS Suppose DS = 1380 and BX=0100 (all values in hex) Then the real memory address into which the value 0Dh is to be moved would be: = (hex)
Real Memory Address Calculation Examples (2) MOV [ES:BX],0Dh ;location of memory ; specified by the values in ES and BX The default has been overridden so ES is used for the segment portion of the address Suppose ES = 26BE and BX=0100 (all values in hex) Then the real memory address into which the value 0Dh is to be moved would be: 26BE = 26CE0 (hex)
Real Memory Address Calculation Examples (3) MOV [0200h],0Dh ;location of memory ; specified immediate offset value 0200h Since no segment override has been coded (and this is an instruction which involves data), the DS register will be used for the segment address. Suppose DS contains 278C (all values in hex) Then the real memory address into which the value 0Dh is to be moved would be: 278C = 27AC0 (hex)
Real Memory Address Calculation Examples (4) JMP 2AC4 ;location of memory containing ; next instruction specified as an ; immediate value The default has not been overridden and since this instruction deals with the address of another instruction (not data), the CS register will be used for the segment address. Suppose CS = 1E02 (all values in hex) Then the real memory address of the instruction being “jumped” to would be: 1E AC4 = 20AE4 (hex)
Real Memory Address Calculation Examples (5) JMP 4001:2AC4 ;location of memory containing ; next instruction specified as a pair ; of immediate value The default has been overridden with an immediate value which will be used for the segment address. Then the real memory address of the instruction being “jumped” to would be: AC4 = 42AD4 (hex)
Real Memory Address Calculation Examples (6) PUSH AX ; stores (2-byte) value in AX ; on stack The PUSH instruction automatically uses the SS:SP pair; however, the value in the SP points to the last value stored on the stack, so it must be decremented by 2 before these 2 bytes can be stored. Suppose SS = 12D3 and SP=04E6 (all values in hex) Then the real memory address when the value in AX would be stored would be 12D30 + (04E6 – 2) = (hex)
End of Lecture