Скачать презентацию Microprocessors Sunday Mar 23 Dr Asmaa Farouk Faculty Скачать презентацию Microprocessors Sunday Mar 23 Dr Asmaa Farouk Faculty

928b6a1cdc6cd07937f50f1051b57fbf.ppt

  • Количество слайдов: 96

Microprocessors Sunday, Mar. 23 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University Microprocessors Sunday, Mar. 23 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University

Topics of Today • Reading: – Brey: • Section 1. 2: The Memory. • Topics of Today • Reading: – Brey: • Section 1. 2: The Memory. • Section 2. 2: Real Mode Memory Addressing. – Mazidi: • Section 1. 4: Introduction to Program Segments. • Section 1. 5: More about Segments in the 80 x 86.

Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Segments. More about Segments in the 80 x 86.

The Memory • Memory structure of all Intel-based personal computers is similar. • Figure The Memory • Memory structure of all Intel-based personal computers is similar. • Figure (1 -7) illustrates memory map of a personal computer system.

The Memory • This map applies to any IBM personal computer. – Also any The Memory • This map applies to any IBM personal computer. – Also any IBM -compatible clones in existence.

The Memory • Main memory system divided into three parts: – TPA (Transient Program The Memory • Main memory system divided into three parts: – TPA (Transient Program Area). – System Area. – XMS (e. Xtended Memory System). • The type of the microprocessor determines whether an extended memory system exists. – For 8086 / 8088 PC, the TPA and system area exist, but there is no extended memory area.

The Memory • First 1 M byte of memory (TPA & System Area) often The Memory • First 1 M byte of memory (TPA & System Area) often called the real or conventional memory system.

The Memory • First 1 M byte of memory (TPA & System Area) often The Memory • First 1 M byte of memory (TPA & System Area) often called the real or conventional memory system. The TPA: – Its length is 640 K bytes. – Holds the DOS (Disk Operating System) and other programs that control the computer system. • The TPA is a DOS concept and not really applicable in Windows. • Also stores any currently active or inactive DOS application programs.

The Memory • The TPA: (Cont. ) – DOS memory map (figure 1 -8) The Memory • The TPA: (Cont. ) – DOS memory map (figure 1 -8) shows how areas of TPA are used for system programs, data and drivers. • Hexadecimal number to left of each area represents the memory addresses that begin and each data area.

The Memory • The TPA: (Cont. ) – Interrupt vectors access various features of The Memory • The TPA: (Cont. ) – Interrupt vectors access various features of DOS, BIOS (Basic I/O System), and applications. • System BIOS is a collection of programs always stored in the ROM or flash memory. • Has important information for the I/O devices to the PC to start up.

The Memory • The TPA: (Cont. ) – BIOS & DOS communications areas contain The Memory • The TPA: (Cont. ) – BIOS & DOS communications areas contain transient data used by programs to access I/O devices and internal features of the system. • These are stored in the TPA so they can be changed as DOS operates.

The Memory • The TPA: (Cont. ) – IO. SYS Program: • Loads into The Memory • The TPA: (Cont. ) – IO. SYS Program: • Loads into the TPA from the disk whenever an MSDOS system is started. – MSDOS (Microsoft DOS). • Allows DOS to use keyboard, video display, printer, and other I/O devices often found in computers. • IO. SYS program links DOS system to the programs stored on the system BIOS ROM.

The Memory • The TPA: (Cont. ) – Drivers: are programs that control installable The Memory • The TPA: (Cont. ) – Drivers: are programs that control installable I/O devices. • Mouse, disk cache, hand scanner, CDROM memory (Compact Disk Read. Only Memory), DVD (Digital Versatile Disk), as well as programs.

The Memory • The TPA: (Cont. ) – Drivers: are programs that control installable The Memory • The TPA: (Cont. ) – Drivers: are programs that control installable I/O devices. • DOS drivers normally have an extension of. SYS, e. g. MOUSE. SYS. – DOS version 3. 2 and later files have an extension of. EXE; EMM 386. EXE. • Even though these files are not used by Windows, they are still used to execute DOS applications.

The Memory • The TPA: (Cont. ) – COMMAND. COM program (command processor): controls The Memory • The TPA: (Cont. ) – COMMAND. COM program (command processor): controls the operation of the computer from the keyboard when operated in the DOS mode. • Processes the DOS commands as they are typed from the keyboard. – For example, if DIR is typed, the program displays a directory of the disk files in the current disk directory.

The Memory • First 1 M byte of memory (TPA & System Area) often The Memory • First 1 M byte of memory (TPA & System Area) often called the real or conventional memory system. The System Area: – Smaller than the TPA. • Its length is 384 K bytes. – Contains programs on ROM or flash memory, and areas of RAM memory for data storage.

The Memory • The System Area: (Cont. ) – Figure (1 -9) shows the The Memory • The System Area: (Cont. ) – Figure (1 -9) shows the system area of a typical personal computer system. • The map also includes the hexadecimal memory addresses of the various areas.

The Memory • The System Area: (Cont. ) – First area: contains video display The Memory • The System Area: (Cont. ) – First area: contains video display RAM and video control programs on ROM or flash memory. • Area starts at location A 0000 H and extends to C 7 FFFH. • Size/amount of memory depends on type of video display adapter attached.

The Memory • The System Area: (Cont. ) – Area at locations C 8000 The Memory • The System Area: (Cont. ) – Area at locations C 8000 H– DFFFFH is often open or free. • Its use depends on the system and its configuration.

The Memory • The System Area: (Cont. ) – Memory locations E 0000 H– The Memory • The System Area: (Cont. ) – Memory locations E 0000 H– EFFFFH contain the cassette BASIC language on ROM found in early IBM personal computer systems. • This area is often open or free in newer computer systems.

The Memory • The System Area: (Cont. ) – The BIOS system ROM is The Memory • The System Area: (Cont. ) – The BIOS system ROM is located in the top 64 K bytes of the system area (F 0000 H – FFFFFH). • Controls the operation of the basic I/O devices connected to the computer system.

The Memory • Windows Systems: – Modern computers use a different memory map with The Memory • Windows Systems: – Modern computers use a different memory map with Windows than DOS memory maps. • It has two main areas; a TPA and system area. • The difference between this map and the DOS memory map are sizes and locations of these areas. – Figure (1 -10) shows Windows XP memory map.

The Memory • Windows Systems: (Cont. ) – TPA is first 2 G bytes The Memory • Windows Systems: (Cont. ) – TPA is first 2 G bytes from locations 0000 H to 7 FFFFFFFH. • Every program written for Windows can use only up to 2 G bytes of memory (even in a 64 -bit system). – System area is the last 2 G bytes from 80000000 H to FFFFH.

Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Segments. More about Segments in the 80 x 86.

Real Mode Memory Addressing • 80286 and above operate in either the real or Real Mode Memory Addressing • 80286 and above operate in either the real or protected mode. • Only the 8086 and 8088 operate exclusively in the real mode. • Real mode operation: allows addressing of only the first 1 M byte of memory space - even in Pentium 4 or Core 2 microprocessors. – Remember: first 1 M byte of memory is called the real memory, conventional memory, or DOS memory system.

Real Mode Memory Addressing • Segments and Offsets: – All real mode memory addresses Real Mode Memory Addressing • Segments and Offsets: – All real mode memory addresses must consist of a segment address plus an offset address. – Segment address: • Defines the beginning address of any 64 K-byte memory segment. • Located within one of the segment registers. • Real mode segments can begin only at a 16 -byte boundary in the memory system (called a paragraph). – Offset address: • Selects any location within the 64 K-byte memory segment.

Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Figure (2 -3) Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Figure (2 -3) shows: • A memory segment beginning at 10000 H, ending at location 1 FFFFH. – 64 K-bytes in length.

Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Figure (2 -3) Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Figure (2 -3) shows: • A memory segment beginning at 10000 H, ending at location 1 FFFFH. – 64 K-bytes in length. • An offset address, sometimes called a displacement, of F 000 H selects location 1 F 000 H in the memory segment (10000 H + F 000 H).

Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Once the beginning Real Mode Memory Addressing • Segments and Offsets: (Cont. ) – Once the beginning address is known, the ending address is found by adding FFFFH. • Because a real mode segment of memory size 64 K length. – The offset address is always added to the segment’s starting address to locate the data. – Segment and offset address are sometimes written as 1000: 2000. • A segment address of 1000 H; an offset of 2000 H.

Real Mode Memory Addressing • Default Segment and Offset Registers: – The microprocessor has Real Mode Memory Addressing • Default Segment and Offset Registers: – The microprocessor has rules that apply to segments whenever memory is addressed. • Define the segment and offset register combination. – Example: the Code Segment (CS) register with The Instruction Pointer (IP) : • CS defines the start of the code segment. • IP locates the next instruction within the code segment. • This combination is CS: IP or CS: EIP, depending on the microprocessor’s mode of operation.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Another Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Another default combination is the stack. • Stack data are referenced through the Stack Segment (SS) register with offset addressed by either the Stack Pointer (SP/ESP) or the base pointer (BP/EBP). – Other defaults are shown in table (2 -3):

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – 8086 Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – 8086 allows four memory segments. – Figure (2 -4) shows a system that contains four memory segments.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – A Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – A memory segment can touch or overlap if 64 K-bytes of memory are not required for a segment. – A program can have more than four or six segments, but only access four or six segments at a time.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: A program placed in memory by DOS is loaded in the TPA at the first available area of memory above drivers and other TPA programs. • This area is indicated by a free-pointer maintained by DOS.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: • Program loading is handled automatically by the program loader within DOS.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: • The side view of the segments shows an overlap because the amount of data in them does not require 64 K bytes of memory.

Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: Real Mode Memory Addressing • Default Segment and Offset Registers: (Cont. ) – Example: • Memory segments can be moved to any place in the memory system without changing any of the offset addresses. – Only by changing the segment starting address. – The DOS program loader calculates and assigns segment starting addresses.

Real Mode Memory Addressing • Segment and Offset Addressing Scheme Allows Relocation: – Segment Real Mode Memory Addressing • Segment and Offset Addressing Scheme Allows Relocation: – Segment plus offset addressing allows DOS programs to be relocated in memory. – A relocatable program: is one that can be placed into any area of memory and executed without change. – Relocatable data: are data that can be placed in any area of memory and used without any change to the program.

Real Mode Memory Addressing • Segment and Offset Addressing Scheme Allows Relocation: (Cont. ) Real Mode Memory Addressing • Segment and Offset Addressing Scheme Allows Relocation: (Cont. ) – Because memory is addressed within a segment by an offset address, the memory segment can be moved to any place in the memory system without changing any of the offset addresses. • Only the contents of the segment register must be changed to address the program in the new area of memory. – Windows programs are written assuming that the first 2 G of memory are available for code and data.

Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Segments. More about Segments in the 80 x 86.

Introduction to Program Segments • A typical Assembly language program consists of at least Introduction to Program Segments • A typical Assembly language program consists of at least three segments: – A code segment: which contains the assembly language instructions that perform the tasks that the program was designed to accomplish. – A data segment: used to store information (data) to be processed by the instructions in the code segment. – A stack segment: used by the CPU to store information temporarily.

Introduction to Program Segments • Origin and Definition of the Segment: – A segment: Introduction to Program Segments • Origin and Definition of the Segment: – A segment: is an area of memory that includes up to 64 K-bytes, and begins on an address evenly divisible by 16 (such an address ends in 0 H). – In 8085 there was 64 K-bytes of memory for all code, data, and stack information. • It had only 16 pins for address lines (216 = 64 K). – In 8088/86 there can be up to 64 K-bytes in each category. – The code segment, data segment, and stack segment.

Introduction to Program Segments • Logical Address and Physical Address: – In 8086, there Introduction to Program Segments • Logical Address and Physical Address: – In 8086, there are three types of addresses: • Physical address: 20 -bit address actually on the address pins of the processor, decoded by the memory interfacing circuitry. – An actual physical location in RAM or ROM within the 1 MB memory range. – This address can have a range of 00000 H to FFFFFH. • Offset address: a location in a 64 K-byte segment which can range from 0000 H to FFFFH. • Logical address: which consists of a segment address and an offset address.

Introduction to Program Segments • Code Segment: – To execute a program, 8086 fetches Introduction to Program Segments • Code Segment: – To execute a program, 8086 fetches the instructions (opcodes and operands) from the code segment. • The logical address of an instruction always consists of a CS (code segment) and an IP (instruction pointer), shown in CS: IP format. • The physical address for the location of the instruction is generated by shifting the CS left one hex digit, then adding it to the IP. – IP contains the offset address. – The resulting 20 -bit address is the physical address since it is put on the external physical address bus pins.

Introduction to Program Segments • Code Segment: (Cont. ) – Assume values in CS Introduction to Program Segments • Code Segment: (Cont. ) – Assume values in CS & IP as shown below: • The offset address: contained in IP, is 95 F 3 H. • The logical address: is CS: IP, or 2500: 95 F 3 H. • The physical address: will be 25000 + 95 F 3 = 2 E 5 F 3 H.

Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical address of an instruction: • The microprocessor will retrieve the instruction from memory locations starting at 2 E 5 F 3 H.

Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical address of an instruction: • Since IP can have a minimum value of 0000 H and a maximum of FFFFH, the logical address range in this example is 2500: 0000 to 2500: FFFF.

Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical Introduction to Program Segments • Code Segment: (Cont. ) – Calculation of the physical address of an instruction: • This means that the lowest memory location of the code segment above will be 25000 H (25000 + 0000) and the highest memory location will be 34 FFFH (25000 + FFFF).

Introduction to Program Segments • Code Segment: (Cont. ) – What happens if the Introduction to Program Segments • Code Segment: (Cont. ) – What happens if the desired instructions are located beyond these two limits? • The value of CS must be changed to access those instructions.

Introduction to Program Segments • Code Segment: (Cont. ) – Example: Introduction to Program Segments • Code Segment: (Cont. ) – Example:

Introduction to Program Segments • The following Assembly language instructions • Logical vs. Physical Introduction to Program Segments • The following Assembly language instructions • Logical vs. Physical Address in the Code machine have been assembled (translated into Segment: language) and stored in memory.

Introduction to Program Segments • The logical address of Physical Address in the Code Introduction to Program Segments • The logical address of Physical Address in the Code • The corresponding • Logical vs. • The machine code CS: IP. stored at that address. Assembly language code. Segment:

Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. ) • Instruction "MOV AL, 57" has a machine code of B 057. – B 0 is the opcode and 57 is the operand.

Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. ) • The byte at address 1132: 0100 contains B 0, the opcode for moving a value into register AL.

Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Code Segment: (Cont. ) • Address 1132: 0101 contains 57, the operand to be moved to AL.

Introduction to Program Segments • Data Segment: – Assume a program to add 5 Introduction to Program Segments • Data Segment: – Assume a program to add 5 bytes of data, such as 25 H, 12 H, 15 H, 1 FH, and 2 BH. • One way to add them is as follows: • In this program, the data & code are mixed together in the instructions. – If the data changes, the code must be searched for every place it is included, and the data retyped.

Introduction to Program Segments • Data Segment: (Cont. ) – In x 86 microprocessors, Introduction to Program Segments • Data Segment: (Cont. ) – In x 86 microprocessors, the area of memory set for data is called the data segment. • It uses the register DS and an offset value. – The next program demonstrates how data can be stored in the data segment and the program rewritten so that it can be used for any set of data.

Introduction to Program Segments • Data Segment: (Cont. ) – Assume data segment offset Introduction to Program Segments • Data Segment: (Cont. ) – Assume data segment offset begins at 200 H. • The data is placed in memory locations: • The program can be rewritten as follows:

Introduction to Program Segments • Data Segment: (Cont. ) – The offset address is Introduction to Program Segments • Data Segment: (Cont. ) – The offset address is enclosed in brackets, which indicate that the operand represents the address of the data and not the data itself. – If the brackets were not included, as in "MOV AL, 0200", the CPU would attempt to move 200 into AL instead of the contents of offset address 200. • This program will run with any set of data. • Changing the data has no effect on the code.

Introduction to Program Segments • Data Segment: (Cont. ) – If the data had Introduction to Program Segments • Data Segment: (Cont. ) – If the data had to be stored at a different offset address the program would have to be rewritten. • A way to solve this problem is to use a register to hold the offset address, and before each ADD, increment the register to access the next byte. – 8088/86 allows only the use of registers BX, SI, and DI as offset registers for the data segment. • The term pointer is often used for a register holding an offset address.

Introduction to Program Segments • Data Segment: (Cont. ) – In the following example, Introduction to Program Segments • Data Segment: (Cont. ) – In the following example, BX is used as a pointer: • The INC instruction adds 1 to its operand (increments). • "INC BX" achieves the same result as "ADD BX, 1“

Introduction to Program Segments • Data Segment: (Cont. ) – In the following example, Introduction to Program Segments • Data Segment: (Cont. ) – In the following example, BX is used as a pointer: • The INC instruction adds 1 to its operand (increments). • "INC BX" achieves the same result as "ADD BX, 1“ • If the offset address where data is located is changed, only one instruction will need to be modified.

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: – Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: – The physical address for data is calculated using the same rules as for the code segment. • The physical address of data is calculated by shifting DS left one hex digit and adding the offset value.

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (1):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (2):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (2):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (2):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (2):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (2):

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (3): • Lower range = 578 C 0 + 0000 = 578 C 0 H. • Higher range = 578 C 0 + FFFF = 678 BFH.

Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. Introduction to Program Segments • Logical vs. Physical Address in the Data Segment: (Cont. ) – Example (3):

Introduction to Program Segments • Little Endian Convention: – Previous examples used 8 -bit Introduction to Program Segments • Little Endian Convention: – Previous examples used 8 -bit or 1 -byte data. • What happens when 16 -bit data is used? – The low byte goes to the low memory location and the high byte goes to the high memory address. • Memory location DS: 1500 contains F 3 H. • Memory location DS: 1501 contains 35 H. – (DS: 1500 = F 3 DS: 1501 = 35). • This convention is called little endian vs. big endian.

Introduction to Program Segments • Little Endian Convention: (Cont. ) – In the big Introduction to Program Segments • Little Endian Convention: (Cont. ) – In the big endian method, the high byte goes to the low address. • In the little endian method, the high byte goes to the high address and the low byte to the low address. – Example:

Introduction to Program Segments • Extra Segment (ES): – ES is a segment register Introduction to Program Segments • Extra Segment (ES): – ES is a segment register used as an extra data segment. • In many normal programs this segment is not used. • Using it is essential for string operations.

Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Topics of Today • • The Memory. Real Mode Memory Addressing. Introduction to Program Segments. More about Segments in the 80 x 86.

More about Segments in the 80 x 86 • What is the Stack? Why More about Segments in the 80 x 86 • What is the Stack? Why is it Needed? – The stack is a section of read/write memory (RAM) used by the CPU to store information temporarily. – The CPU needs this storage area since there are only a limited number of registers. – Main disadvantage of the stack is the access time. • Since the stack is in RAM, it takes much longer to access compared to the access time of registers. – Some very powerful (expensive) computers do not have a stack. • The CPU has a large number of registers to work with.

More about Segments in the 80 x 86 • How Stacks are Accessed: – More about Segments in the 80 x 86 • How Stacks are Accessed: – The stack is a section of RAM, so there must be registers inside the CPU to point to it. • The SS (stack segment) register. • The SP (stack pointer) register. – These registers must be loaded before any instructions accessing the stack are used.

More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. ) – Every register inside the x 86 can be stored in the stack, and brought back into the CPU from the stack, except segment registers and SP. • Storing a CPU register in the stack is called a PUSH. • Loading the contents of the stack into the CPU register is called a POP.

More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. ) – The stack pointer register (SP) points to the current memory location used as the top of the stack. • As data is pushed onto the stack it is decremented. • As data is popped off the stack into the CPU, it is incremented. – When an instruction pushes or pops a generalpurpose register, it must be the entire 16 -bit register. • One must code "PUSH AX". – There are no instructions such as "PUSH AL" or "PUSH AH".

More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. More about Segments in the 80 x 86 • How Stacks are Accessed: (Cont. ) – The SP is decremented after the push is to make sure the stack is growing downward from upper addresses to lower addresses. • The opposite of the IP (instruction pointer). – To ensure the code section & stack section of the program never write over each other, they are located at opposite ends of the RAM set aside for the program. • They grow toward each other but must not meet. • If they meet, the program will crash.

More about Segments in the 80 x 86 • Pushing Onto the Stack: – More about Segments in the 80 x 86 • Pushing Onto the Stack: – As each PUSH is executed, the register contents are saved on the stack and SP is decremented by 2. • For every byte of data saved on the stack, SP is decremented once. • Since the PUSH is saving the contents of a 16 -bit register, it decrements twice.

More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. ) – Example:

More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. ) – Example: – In the x 86, the lower byte is always stored in the memory location with the lower address. • 24 H, the content of AH, is saved in the memory location with the address 1235. • AL is stored in location 1234.

More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. More about Segments in the 80 x 86 • Pushing Onto the Stack: (Cont. ) – Example:

More about Segments in the 80 x 86 • Popping the Stack: – With More about Segments in the 80 x 86 • Popping the Stack: – With every POP, the top 2 bytes of the stack are copied to the x 86 CPU register specified by the instruction and SP is incremented twice.

More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) – Example:

More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) – Example: – Note that, While the data actually remains in memory, it is not accessible, since the stack pointer, SP is beyond that point.

More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) More about Segments in the 80 x 86 • Popping the Stack: (Cont. ) – Example:

More about Segments in the 80 x 86 • Logical vs. Physical Address for More about Segments in the 80 x 86 • Logical vs. Physical Address for the Stack: – The exact physical location of the stack depends on the value of the stack segment (SS) register and the stack pointer (SP). • To compute physical addresses for the stack, shift left SS, then add offset SP. • The operating system assigns values for the SP and SS. – Example:

More about Segments in the 80 x 86 • A few more Words about More about Segments in the 80 x 86 • A few more Words about Segments in 80 x 86: 1. Can a single physical address belong to many different logical addresses? • Yes, many possible logical addresses can represent a single physical address. • This shows the dynamic behavior of the segment and offset concept in the 8086 CPU.

More about Segments in the 80 x 86 • A few more Words about More about Segments in the 80 x 86 • A few more Words about Segments in 80 x 86: 2. When adding the offset to the shifted segment register that results in an address beyond the maximum allowed range of FFFFFH, wrap-around will occur.

More about Segments in the 80 x 86 • A few more Words about More about Segments in the 80 x 86 • A few more Words about Segments in 80 x 86: – Example:

More about Segments in the 80 x 86 • A few more Words about More about Segments in the 80 x 86 • A few more Words about Segments in 80 x 86: – Example: The higher range = FF 590 + FFFF = 10 F 58 FH.

More about Segments in the 80 x 86 • A few more Words about More about Segments in the 80 x 86 • A few more Words about Segments in 80 x 86: – Example:

More about Segments in the 80 x 86 • Overlapping: – In calculating the More about Segments in the 80 x 86 • Overlapping: – In calculating the physical address, it is possible that two segments can overlap.

Questions? Questions?