Lec 03 ia32 architecture


Published on

lec 3 in progress

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lec 03 ia32 architecture

  1. 1. IA-32 Architecture COAL Computer Organization and Assembly Language
  2. 2. Next ... <ul><li>Intel Microprocessors </li></ul><ul><li>IA-32 Registers </li></ul><ul><li>Instruction Execution Cycle </li></ul><ul><li>IA-32 Memory Management </li></ul>
  3. 3. Intel Microprocessors <ul><li>Intel introduced the 8086 microprocessor in 1979 </li></ul><ul><li>8086, 8087, 8088, and 80186 processors </li></ul><ul><ul><li>16-bit processors with 16-bit registers </li></ul></ul><ul><ul><li>16-bit data bus and 20-bit address bus </li></ul></ul><ul><ul><ul><li>Physical address space = 2 20 bytes = 1 MB </li></ul></ul></ul><ul><ul><li>8087 Floating-Point co-processor </li></ul></ul><ul><ul><li>Uses segmentation and real-address mode to address memory </li></ul></ul><ul><ul><ul><li>Each segment can address 2 16 bytes = 64 KB </li></ul></ul></ul><ul><ul><li>8088 is a less expensive version of 8086 </li></ul></ul><ul><ul><ul><li>Uses an 8-bit data bus </li></ul></ul></ul><ul><ul><li>80186 is a faster version of 8086 </li></ul></ul>
  4. 4. Intel 80286 and 80386 Processors <ul><li>80286 was introduced in 1982 </li></ul><ul><ul><li>24-bit address bus  2 24 bytes = 16 MB address space </li></ul></ul><ul><ul><li>Introduced protected mode </li></ul></ul><ul><ul><ul><li>Segmentation in protected mode is different from the real mode </li></ul></ul></ul><ul><li>80386 was introduced in 1985 </li></ul><ul><ul><li>First 32-bit processor with 32-bit general-purpose registers </li></ul></ul><ul><ul><li>First processor to define the IA-32 architecture </li></ul></ul><ul><ul><li>32-bit data bus and 32-bit address bus </li></ul></ul><ul><ul><li>2 32 bytes  4 GB address space </li></ul></ul><ul><ul><li>Introduced paging , virtual memory , and the flat memory model </li></ul></ul><ul><ul><ul><li>Segmentation can be turned off </li></ul></ul></ul>
  5. 5. Intel 80486 and Pentium Processors <ul><li>80486 was introduced 1989 </li></ul><ul><ul><li>Improved version of Intel 80386 </li></ul></ul><ul><ul><li>On-chip Floating-Point unit (DX versions) </li></ul></ul><ul><ul><li>On-chip unified Instruction/Data Cache (8 KB) </li></ul></ul><ul><ul><li>Uses Pipelining : can execute up to 1 instruction per clock cycle </li></ul></ul><ul><li>Pentium (80586) was introduced in 1993 </li></ul><ul><ul><li>Wider 64-bit data bus, but address bus is still 32 bits </li></ul></ul><ul><ul><li>Two execution pipelines: U-pipe and V-pipe </li></ul></ul><ul><ul><ul><li>Superscalar performance: can execute 2 instructions per clock cycle </li></ul></ul></ul><ul><ul><li>Separate 8 KB instruction and 8 KB data caches </li></ul></ul><ul><ul><li>MMX instructions (later models) for multimedia applications </li></ul></ul>
  6. 6. Intel P6 Processor Family <ul><li>P6 Processor Family: Pentium Pro, Pentium II and III </li></ul><ul><li>Pentium Pro was introduced in 1995 </li></ul><ul><ul><li>Three-way superscalar : can execute 3 instructions per clock cycle </li></ul></ul><ul><ul><li>second Die of L2 Memory Cache </li></ul></ul><ul><ul><li>36-bit address bus  up to 64 GB of physical address space </li></ul></ul><ul><ul><li>Introduced dynamic execution </li></ul></ul><ul><ul><ul><li>Out-of-order and speculative execution </li></ul></ul></ul><ul><ul><li>Integrates a 256 KB second level L2 cache on-chip </li></ul></ul><ul><li>Pentium II (Pentium Pro + P5) was introduced in 1997 </li></ul><ul><ul><li>Added MMX instructions (already introduced on Pentium MMX) </li></ul></ul><ul><li>Pentium III was introduced in 1999 </li></ul><ul><ul><li>Added SSE instructions and eight new 128-bit XMM registers </li></ul></ul><ul><ul><li>Streaming SIMD Extensions (SSE)---70 new instructions working on single precision Floating Point Data </li></ul></ul><ul><ul><li>Increase performance when same instruction is to be applied on multiple data objects (Graphics processing) </li></ul></ul>
  7. 7. Pentium 4 and Xeon Family <ul><li>Pentium 4 is a seventh-generation x86 architecture </li></ul><ul><ul><li>Introduced in 2000, running at 2GHz (crossing 1GHz barrier) </li></ul></ul><ul><ul><li>New micro-architecture design called Intel Netburst </li></ul></ul><ul><ul><li>Very deep instruction pipeline, scaling to very high frequencies </li></ul></ul><ul><ul><li>Introduced the SSE2 instruction set (extension to SSE) </li></ul></ul><ul><ul><ul><li>Tuned for multimedia and operating on the separate 128-bit XMM registers </li></ul></ul></ul><ul><li>In 2002, Pentium 4 version running at 3.06GHz, the first PC processor to break the 3GHz barrier </li></ul><ul><ul><ul><li>Intel introduced Hyper-Threading technology </li></ul></ul></ul><ul><ul><ul><ul><li>Allowed 2 programs to run simultaneously, sharing resources </li></ul></ul></ul></ul><ul><li>Xeon is Intel's name for its server-class microprocessors </li></ul><ul><ul><li>Xeon chips generally have more cache </li></ul></ul><ul><ul><li>Support larger multiprocessor configurations </li></ul></ul>
  8. 8. HiperThreading <ul><li>Intel Technology  emulation of two processors on one processor core (multi-threaded applications) </li></ul><ul><li>BUT OS must be able to utilize it </li></ul><ul><li>Good Article on Hiper-Threading http://ixbtlabs.com/articles2/pentium43ghzht/index.html </li></ul><ul><li>Pentium 4 Extreme  L3 Cache </li></ul><ul><li>In 2004  x86-64 extensions added to P4 </li></ul><ul><li>Good article on x86-64 bit extensions </li></ul><ul><li>http:// www.informit.com/articles/article.aspx?p =366538 </li></ul>
  9. 9. Pentium-M and EM64T <ul><li>Pentium M ( Mobile ) was introduced in 2003 </li></ul><ul><ul><li>Designed for low-power laptop computers </li></ul></ul><ul><ul><li>Modified version of Pentium III, optimized for power efficiency </li></ul></ul><ul><ul><li>Large second-level cache (2 MB on later models) </li></ul></ul><ul><ul><li>Runs at lower clock than Pentium 4, but with better performance </li></ul></ul><ul><li>Extended Memory 64-bit Technology (EM64T) </li></ul><ul><ul><li>Introduced in 2004 </li></ul></ul><ul><ul><li>64-bit superset of the IA-32 processor architecture </li></ul></ul><ul><ul><li>64-bit general-purpose registers and integer support </li></ul></ul><ul><ul><li>Number of general-purpose registers increased from 8 to 16 </li></ul></ul><ul><ul><li>64-bit pointers and flat virtual address space </li></ul></ul><ul><ul><li>Large physical address space: up to 2 40 = 1 Terabytes </li></ul></ul>
  10. 10. Core Processors <ul><li>Intel Dual Core processor  2005 </li></ul><ul><ul><li>Two processors in single chip </li></ul></ul><ul><li>Core 2  new processor family  2006 </li></ul><ul><ul><li>Dual core version  Quad core version (two dual-core Die in single package) </li></ul></ul><ul><li>Core i Series  2008 </li></ul><ul><ul><li>Single Die Quad Core Chips with HT (Appearing 8 cores to OS) </li></ul></ul><ul><ul><li>Integrated memory controllers </li></ul></ul><ul><li>Core i Series 2nd Generation  2011 </li></ul><ul><ul><li>Six core + HT (Supporting 12 execution threads) </li></ul></ul><ul><li>From 386, Intel developed Mobile versions as well </li></ul>
  11. 11. IA-16 vs. IA-32 vs. IA-64 (IA-32e) <ul><li>286  16-bit internal architecture </li></ul><ul><li>386  32-bit (Intel Calls IA-32 till 1985) </li></ul><ul><ul><li>Windows XP and NT are true 32-bit OS </li></ul></ul><ul><li>Now 64-bit architecture in form of Intel Itanium </li></ul>
  12. 12. Processor Evolvements Facets <ul><li>Increasing the transistor count and density </li></ul><ul><ul><li>1993, P5 Family-Pentium (3.1millions transistors) </li></ul></ul><ul><ul><li>In 1993, P6 Family started with Pentium Pro (5 millions), L2 Cache on second Die </li></ul></ul><ul><ul><li>In 1997, Pentium II processor (7 millions) </li></ul></ul><ul><ul><ul><li>1998 ,Pentium II Celeron and Xeon </li></ul></ul></ul><ul><ul><li>In 1999, Pentium II with Streaming SIMD Extensions (SSE) = Pentium III </li></ul></ul><ul><ul><ul><li>SSE= 70 new instructions--SIMD instructions can greatly increase performance when exactly the same operations are to be performed on multiple data objects </li></ul></ul></ul><ul><li>Increasing the clock cycling speeds </li></ul><ul><ul><li>In 2001, Pentium 4 version running at 2GHz (Crossing 1GHz barrier) </li></ul></ul><ul><ul><li>In 2002, Pentium 4 version running at 3.06GHz, the first PC breaking 3GHz barrier, and the first to feature Intel’s Hyper-Threading (HT) Technology, which turns the processor into a virtual dual-processor configuration  This encouraged programmers to write multithreaded applications, which would prepare them for when true multicore processors would be released a few years later. </li></ul></ul>
  13. 13. Processor Evolvements Facets <ul><li>Increasing the number of cores in a single chip </li></ul><ul><ul><li>In 2005, Intel released their first dual-core processors (integrating two processors into a single chip) </li></ul></ul><ul><ul><li>In 2006, Intel released a new processor family called the Core 2- --same architecture as Mobile Processors ( released in a dual-core version first, followed by a quad-core version (combining two dual-core die in a single package)) </li></ul></ul><ul><ul><li>In 2008, Intel released the Core i Series processors, which are single-die quad-core chips with HT (appearing as eight cores to the OS) + integrated memory controller </li></ul></ul><ul><ul><li>In 2011, Intel released the second generation of Core i-series processors, including four-core and six-core processors with HT Technology, supporting up to 12 execution threads </li></ul></ul><ul><li>Increasing the size of internal registers (bits) </li></ul>
  14. 14. Integrated Memory Controller <ul><li>The  memory controller  is a digital circuit which manages the flow of data going to and from the  main memory . It can be a separate chip or integrated into another chip, such as on the  die  of a  microprocessor . This is also called a Memory Chip Controller (MCC) </li></ul><ul><li>Computers using  Intel  microprocessors have traditionally had a memory controller implemented on their motherboard's  northbridge , but many modern  microprocessors , more recently  Intel 's  Core i7  have an integrated memory controller (IMC) on the microprocessor in order to reduce  memory latency . While this has the potential to increase the system's performance, it locks the microprocessor to a specific type (or types) of memory, forcing a redesign in order to support newer memory technologies. When the memory controller is not on-die, the same CPU may be installed on a new motherboard, with an updated  northbridge . </li></ul>
  15. 15. 16-bit  64-bit Architectural Evolution <ul><li>16-bit Internal Architecture of 286  32-bit Internal architecture of 386 (Intel calls it IA-32 (Intel Architecture, 32-bit). </li></ul><ul><ul><li>Windows 95 – Partial 32-bit OS in 10 years </li></ul></ul><ul><ul><li>Windows XP –Fully 32-bit OS + Drivers (Evolved from Windows 95 (Partial 32-bit) in 6 years) </li></ul></ul><ul><ul><li>Windows NT (Full 32-bit OS also came after 10 years) </li></ul></ul><ul><li>Near 32-bit to 64-bit Architectural Jump </li></ul><ul><ul><li>Intel and Microsoft almost completely shifted </li></ul></ul><ul><ul><li>In 2001, Intel had introduced the IA-64 (Intel Architecture, 64-bit) in the form of the Itanium and Itanium 2 processors, but this standard was something completely new and not an extension of the existing 32-bit technology  not backward compatible </li></ul></ul><ul><ul><li>AMD seized this opportunity to develop 64-bit extensions to IA-32, which it calls AMD64 (originally known as x86-64). Intel eventually released its own set of 64-bit extensions, which it calls EM64T or IA-32e mode  32-bit OS can run on 64-Bit architectural CPUs </li></ul></ul><ul><ul><li>Windows Vista x64 in 2007 --< truly utilizing 64-bit architecture but lack of 64-bit drivers for all components </li></ul></ul><ul><ul><li>Windows 7 x64 in 2009, most device manufacturers were providing both 32-bit and 64-bit drivers for virtually all new devices </li></ul></ul>
  16. 16. Processor Specifications <ul><li>Speed (How fast CPU is?) </li></ul><ul><li>Width </li></ul><ul><ul><li>Internal Registers </li></ul></ul><ul><ul><ul><li>Usually 32-bits so we say 32-bit CPUs </li></ul></ul></ul><ul><ul><ul><li>386 through the Pentium 4 all 32-bits </li></ul></ul></ul><ul><ul><ul><li>Processors since the Intel Core 2 series are considered 64-bit processors because their internal registers are 64 bits wide. </li></ul></ul></ul><ul><ul><li>Data (I/O) Bus  called Front Side Bus (FSB), Processor Side Bus (PSB) or CPU Bus </li></ul></ul><ul><ul><ul><li>Bus between CPU and main chipset component (Memory Controller Hub, North Bridge) usually 64-bit for Modern CPUs </li></ul></ul></ul><ul><ul><li>Address Bus </li></ul></ul><ul><ul><ul><li>36-bits for Pentium 4 </li></ul></ul></ul>
  17. 17. Data I/O Bus <ul><li>Speed at which data can be moved in/out of processor </li></ul><ul><li>Bandwidth=amount of data being sent </li></ul><ul><li>Bandwidth can be increased by increasing </li></ul><ul><ul><li>Either cycling times </li></ul></ul><ul><ul><li>Or No of bits being sent </li></ul></ul><ul><ul><li>Or both </li></ul></ul><ul><li>64-bits highway </li></ul><ul><ul><li>Difficult to expand more as too hard to synchronize all 64-bits so increase peed even less lines </li></ul></ul><ul><ul><li>Separate buses  another idea </li></ul></ul><ul><ul><ul><li>Separate buses for data in/out of memory, chipsets, and graphics card slot </li></ul></ul></ul>
  18. 18. Address Bus <ul><li>Carries addressing info </li></ul><ul><li>Width of address bus  max amount of RAM, a chip can address </li></ul><ul><li>8088 and 8086 have 20-bit ->1MB address locations </li></ul><ul><li>386, 486, Pentium  32-bit </li></ul><ul><li>Pentium with PAE (physical address extension—supported by server OS only)  36-bit </li></ul>
  19. 19. Internal Registers <ul><li>How much info , processor can operate at a time (register size) and </li></ul><ul><li>How it moves data internally within the chip (Internal Data Bus) </li></ul><ul><li>Register size  also specifies types of instructions (software) a chip can run </li></ul><ul><ul><li>32-bit processor can run 32-bit instructions that are processing 32-bit chunks of data BUT </li></ul></ul><ul><ul><li>Processor with 16-bit registers can not run 32-bit instructions </li></ul></ul><ul><ul><li>Processors from the 386 to the Pentium 4 use 32-bit internal registers and can run essentially the same 32-bit OSs and software. </li></ul></ul><ul><ul><li>The Core 2 and newer processors have both 32-bit and 64-bit internal registers, which can run existing 32-bit OSs and applications as well as newer 64-bit versions. </li></ul></ul>
  20. 20. Processors Modes <ul><li>All Intel processors can run in several modes (operating environments) </li></ul><ul><li>Mode controls how processor sees and manage system memory </li></ul><ul><ul><li>Effects capability and instructions of the chip </li></ul></ul>
  21. 21. Real Mode <ul><li>8086 mode because based on 8088 and 8086 CPUs </li></ul><ul><li>Execution of 16-bit instructions with 16-bit Internal register with 1MB memory addressable (all DOS and up-to Windows 1.x to 3.x Software) </li></ul><ul><li>Later 286 CPU can run same software but faster </li></ul><ul><li>16-bit instruction mode of 8086 and 286  called Real Mode </li></ul><ul><li>Software of this type usually single tasking (one program at a time) and no built-in protection of application or OS code </li></ul>
  22. 22. IA-32 Mode (32-bit) <ul><li>386 was first 32-bit CPU </li></ul><ul><li>Can run entirely new 32-bit instruction set </li></ul><ul><li>To take full advantage </li></ul><ul><ul><li>32-bit OS and 32-bit applications (called protected mode---software running are protected from another software's) </li></ul></ul><ul><ul><li>Errant program can or damage other program’s memory area or OS </li></ul></ul><ul><ul><li>Crashed program can be terminated while system continues working </li></ul></ul><ul><ul><li>Intel knew that newly 32-bit OS and Applications would take time to emerge so Intel made Backward compatible mode in 386  possible to run 16-bit OS and applications </li></ul></ul><ul><ul><li>So 386 running DOS works like Turbo/Fast 8088 accessing 1MB memory </li></ul></ul><ul><ul><ul><li>Windows XP was fist true 32-bit OS </li></ul></ul></ul>
  23. 23. IA-32 Virtual Real Mode <ul><li>Backward compatibility mode of 32-bit environments like windows </li></ul><ul><li>Virtual real mode 16-bit environment running inside 32-bit protected mode (DOS prompt inside windows is creation of virtual real mode session) </li></ul><ul><li>Protected mode enable multitasking  several real mode sessions running (each software running on virtual PC) </li></ul><ul><ul><li>virtual real window fully emulates an 8088 environment, so that aside from speed, the software runs as if it were on an original real mode–only PC. </li></ul></ul><ul><ul><li>Each virtual machine gets its own 1MB address space, an image of the real hardware basic input/output system (BIOS) routines, and emulation of all other registers and features found in real mode. </li></ul></ul><ul><li>Note: all Intel processors power up in real mode and 32-bit OS loading converts it to protected mode </li></ul>
  24. 24. IA-32e 64-bit Extension Mode(X64, X86-64,EM64T) <ul><li>Processors with 64-bit extension technology can run in </li></ul><ul><ul><li>real (8086) mode, </li></ul></ul><ul><ul><li>IA-32 mode, or </li></ul></ul><ul><ul><ul><li>IA-32 mode enables the processor to run in protected mode and virtual real mode </li></ul></ul></ul><ul><ul><li>IA-32e mode </li></ul></ul><ul><ul><ul><li>IA-32e mode allows the processor to run in </li></ul></ul></ul><ul><ul><ul><ul><li>64-bit mode and compatibility mode </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>can run both 64-bit and 32-bit applications simultaneously </li></ul></ul></ul></ul></ul><ul><ul><ul><li>64-bit mode  Enables a 64-bit OS to run 64-bit applications </li></ul></ul></ul><ul><ul><ul><li>compatibility mode  Enables a 64-bit OS to run most existing 32-bit software </li></ul></ul></ul>
  25. 25. New features in 64-bit mode <ul><li>64-bit linear memory addressing </li></ul><ul><li>Physical memory support beyond 4GB (limited by the specific processor) </li></ul><ul><li>Eight new general-purpose registers (GPRs) </li></ul><ul><li>Eight new registers for streaming SIMD extensions (MMX, SSE, SSE2, and SSE3) </li></ul><ul><li>64-bit-wide GPRs and instruction pointers </li></ul>
  26. 26. Compatibility Mode <ul><li>IE-32e compatibility mode enables 32-bit and 16-bit applications to run under a 64-bit OS But </li></ul><ul><ul><li>legacy 16-bit programs that run in virtual real mode (that is, DOS programs) are not supported and will not run, </li></ul></ul>
  27. 27. 32-bit vs. 64-bit Windows <ul><li>Memory support is different </li></ul><ul><ul><li>32-bit version  4GB with max 2GB for 32bit process </li></ul></ul><ul><ul><li>64-bit version  4GB for each 32-bit process and 8GB for each 64-bit process </li></ul></ul><ul><li>32-version can support 4GB but applications can not access > 3.25GB of RAM </li></ul>
  28. 28. 64-bit windows problems <ul><li>Does not support virtual real mode applications </li></ul><ul><li>32-bit processes can not load 64-bit DLLs (drivers) and vice versa so both types of drivers be installed </li></ul>
  29. 29. CISC and RISC <ul><li>CISC – Complex Instruction Set Computer </li></ul><ul><ul><li>Large and complex instruction set </li></ul></ul><ul><ul><li>Variable width instructions </li></ul></ul><ul><ul><li>Requires microcode interpreter </li></ul></ul><ul><ul><ul><li>Each instruction is decoded into a sequence of micro-operations </li></ul></ul></ul><ul><ul><li>Example: Intel x86 family </li></ul></ul><ul><li>RISC – Reduced Instruction Set Computer </li></ul><ul><ul><li>Small and simple instruction set </li></ul></ul><ul><ul><li>All instructions have the same width </li></ul></ul><ul><ul><li>Simpler instruction formats and addressing modes </li></ul></ul><ul><ul><li>Decoded and executed directly by hardware </li></ul></ul><ul><ul><li>Examples: ARM, MIPS, PowerPC, SPARC, etc. </li></ul></ul>
  30. 30. Next ... <ul><li>Intel Microprocessors </li></ul><ul><li>IA-32 Registers </li></ul><ul><li>Instruction Execution Cycle </li></ul><ul><li>IA-32 Memory Management </li></ul>
  31. 31. Basic Program Execution Registers <ul><li>Registers are high speed memory inside the CPU </li></ul><ul><ul><li>Eight 32-bit general-purpose registers </li></ul></ul><ul><ul><li>Six 16-bit segment registers </li></ul></ul><ul><ul><li>Processor Status Flags (EFLAGS) and Instruction Pointer (EIP) </li></ul></ul>CS SS DS ES EIP EFLAGS 16-bit Segment Registers EAX EBX ECX EDX 32-bit General-Purpose Registers FS GS EBP ESP ESI EDI
  32. 32. General-Purpose Registers <ul><li>Used primarily for arithmetic and data movement </li></ul><ul><ul><li>mov eax, 10 move constant 10 into register eax </li></ul></ul><ul><li>Specialized uses of Registers </li></ul><ul><ul><li>EAX – Accumulator register </li></ul></ul><ul><ul><ul><li>Automatically used by multiplication and division instructions </li></ul></ul></ul><ul><ul><li>ECX – Counter register </li></ul></ul><ul><ul><ul><li>Automatically used by LOOP instructions </li></ul></ul></ul><ul><ul><li>ESP – Stack Pointer register </li></ul></ul><ul><ul><ul><li>Used by PUSH and POP instructions, points to top of stack </li></ul></ul></ul><ul><ul><li>ESI and EDI – Source Index and Destination Index register </li></ul></ul><ul><ul><ul><li>Used by string instructions </li></ul></ul></ul><ul><ul><li>EBP – Base Pointer register </li></ul></ul><ul><ul><ul><li>Used to reference parameters and local variables on the stack </li></ul></ul></ul>
  33. 33. Accessing Parts of Registers <ul><li>EAX, EBX, ECX, and EDX are 32-bit Extended registers </li></ul><ul><ul><li>Programmers can access their 16-bit and 8-bit parts </li></ul></ul><ul><ul><li>Lower 16-bit of EAX is named AX </li></ul></ul><ul><ul><li>AX is further divided into </li></ul></ul><ul><ul><ul><li>AL = lower 8 bits </li></ul></ul></ul><ul><ul><ul><li>AH = upper 8 bits </li></ul></ul></ul><ul><li>ESI, EDI, EBP, ESP have only </li></ul><ul><li>16-bit names for lower half </li></ul>
  34. 34. Special-Purpose & Segment Registers <ul><li>EIP = Extended Instruction Pointer </li></ul><ul><ul><li>Contains address of next instruction to be executed </li></ul></ul><ul><li>EFLAGS = Extended Flags Register </li></ul><ul><ul><li>Contains status and control flags </li></ul></ul><ul><ul><li>Each flag is a single binary bit </li></ul></ul><ul><li>Six 16-bit Segment Registers </li></ul><ul><ul><li>Support segmented memory </li></ul></ul><ul><ul><li>Six segments accessible at a time </li></ul></ul><ul><ul><li>Segments contain distinct contents </li></ul></ul><ul><ul><ul><li>Code </li></ul></ul></ul><ul><ul><ul><li>Data </li></ul></ul></ul><ul><ul><ul><li>Stack </li></ul></ul></ul>
  35. 35. EFLAGS Register <ul><li>Status Flags </li></ul><ul><ul><li>Status of arithmetic and logical operations </li></ul></ul><ul><li>Control and System flags </li></ul><ul><ul><li>Control the CPU operation </li></ul></ul><ul><li>Programs can set and clear individual bits in the EFLAGS register </li></ul>
  36. 36. Status Flags <ul><li>Carry Flag </li></ul><ul><ul><li>Set when unsigned arithmetic result is out of range </li></ul></ul><ul><li>Overflow Flag </li></ul><ul><ul><li>Set when signed arithmetic result is out of range </li></ul></ul><ul><li>Sign Flag </li></ul><ul><ul><li>Copy of sign bit , set when result is negative </li></ul></ul><ul><li>Zero Flag </li></ul><ul><ul><li>Set when result is zero </li></ul></ul><ul><li>Auxiliary Carry Flag </li></ul><ul><ul><li>Set when there is a carry from bit 3 to bit 4 </li></ul></ul><ul><li>Parity Flag </li></ul><ul><ul><li>Set when parity is even </li></ul></ul><ul><ul><li>Least-significant byte in result contains even number of 1s </li></ul></ul>
  37. 37. Floating-Point, MMX, XMM Registers <ul><li>Floating-point unit performs high speed FP operations </li></ul><ul><li>Eight 80-bit floating-point data registers </li></ul><ul><ul><li>ST(0), ST(1), . . . , ST(7) </li></ul></ul><ul><ul><li>Arranged as a stack </li></ul></ul><ul><ul><li>Used for floating-point arithmetic </li></ul></ul><ul><li>Eight 64-bit MMX registers </li></ul><ul><ul><li>Used with MMX instructions </li></ul></ul><ul><li>Eight 128-bit XMM registers </li></ul><ul><ul><li>Used with SSE instructions </li></ul></ul>
  38. 38. Next ... <ul><li>Intel Microprocessors </li></ul><ul><li>IA-32 Registers </li></ul><ul><li>Instruction Execution Cycle </li></ul><ul><li>IA-32 Memory Management </li></ul>
  39. 39. Fetch-Execute Cycle <ul><li>Each machine language instruction is first fetched from the memory and stored in an Instruction Register ( IR ). </li></ul><ul><li>The address of the instruction to be fetched is stored in a register called Program Counter or simply PC . In some computers this register is called the Instruction Pointer or IP . </li></ul><ul><li>After the instruction is fetched, the PC (or IP ) is incremented to point to the address of the next instruction. </li></ul><ul><li>The fetched instruction is decoded (to determine what needs to be done) and executed by the CPU. </li></ul>
  40. 40. Instruction Execute Cycle Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value and status Deposit results in storage for later use Instruction Decode Instruction Fetch Operand Fetch Execute Writeback Result Infinite Cycle
  41. 41. Instruction Execution Cycle – cont'd <ul><li>Instruction Fetch </li></ul><ul><li>Instruction Decode </li></ul><ul><li>Operand Fetch </li></ul><ul><li>Execute </li></ul><ul><li>Result Writeback </li></ul>I2 I3 I4 PC program I1 instruction register op1 op2 memory fetch ALU registers write decode execute read write (output) registers flags . . . I1
  42. 42. Pipelined Execution <ul><li>Instruction execution can be divided into stages </li></ul><ul><li>Pipelining makes it possible to start an instruction before completing the execution of previous one </li></ul>Non-pipelined execution Wasted clock cycles Pipelined Execution For k stages and n instructions, the number of required cycles is: k + n – 1 S1 S2 S3 S4 S5 1 Cycles Stages S6 2 3 4 5 6 7 8 9 10 11 12 I-1 I-2 I-1 I-2 I-1 I-2 I-1 I-2 I-1 I-2 I-1 I-2
  43. 43. Wasted Cycles (pipelined) <ul><li>When one of the stages requires two or more clock cycles to complete, clock cycles are again wasted </li></ul><ul><ul><li>Assume that stage S4 is the execute stage </li></ul></ul><ul><ul><li>Assume also that S4 requires 2 clock cycles to complete </li></ul></ul><ul><ul><li>As more instructions enter the pipeline, wasted cycles occur </li></ul></ul><ul><ul><li>For k stages, where one stage requires 2 cycles, n instructions require k + 2 n – 1 cycles </li></ul></ul>S1 S2 S3 S4 S5 1 Cycles Stages S6 2 3 4 5 6 7 I-1 I-2 I-3 I-1 I-2 I-3 I-1 I-2 I-3 I-1 I-2 I-1 I-1 8 9 I-3 I-2 I-2 exe 10 11 I-3 I-3 I-1 I-2 I-3
  44. 44. Superscalar Architecture <ul><li>A superscalar processor has multiple execution pipelines </li></ul><ul><li>The Pentium processor has two execution pipelines </li></ul><ul><ul><li>Called U and V pipes </li></ul></ul><ul><li>In the following, stage </li></ul><ul><li>S4 has 2 pipelines </li></ul><ul><ul><li>Each pipeline still </li></ul></ul><ul><ul><li>requires 2 cycles </li></ul></ul><ul><ul><li>Second pipeline </li></ul></ul><ul><ul><li>eliminates wasted cycles </li></ul></ul><ul><ul><li>For k stages and n </li></ul></ul><ul><ul><li>instructions, number of </li></ul></ul><ul><ul><li>cycles = k + n </li></ul></ul>
  45. 45. Next ... <ul><li>Intel Microprocessors </li></ul><ul><li>IA-32 Registers </li></ul><ul><li>Instruction Execution Cycle </li></ul><ul><li>IA-32 Memory Management </li></ul>
  46. 46. Modes of Operation <ul><li>Real-Address mode (original mode provided by 8086) </li></ul><ul><ul><li>Only 1 MB of memory can be addressed, from 0 to FFFFF (hex) </li></ul></ul><ul><ul><li>Programs can access any part of main memory </li></ul></ul><ul><ul><li>MS-DOS runs in real-address mode </li></ul></ul><ul><li>Protected mode (introduced with the 80386 processor) </li></ul><ul><ul><li>Each program can address a maximum of 4 GB of memory </li></ul></ul><ul><ul><li>The operating system assigns memory to each running program </li></ul></ul><ul><ul><li>Programs are prevented from accessing each other’s memory </li></ul></ul><ul><ul><li>Native mode used by Windows NT, 2000, XP, and Linux </li></ul></ul><ul><li>Virtual 8086 mode </li></ul><ul><ul><li>Processor runs in protected mode, and creates a virtual 8086 machine with 1 MB of address space for each running program </li></ul></ul>
  47. 47. Real Address Mode <ul><li>A program can access up to six segments at any time </li></ul><ul><ul><li>Code segment </li></ul></ul><ul><ul><li>Stack segment </li></ul></ul><ul><ul><li>Data segment </li></ul></ul><ul><ul><li>Extra segments (up to 3) </li></ul></ul><ul><li>Each segment is 64 KB </li></ul><ul><li>Logical address </li></ul><ul><ul><li>Segment = 16 bits </li></ul></ul><ul><ul><li>Offset = 16 bits </li></ul></ul><ul><li>Linear (physical) address = 20 bits </li></ul>
  48. 48. Logical to Linear Address Translation <ul><li>Linear address = Segment × 10 (hex) + Offset </li></ul><ul><li>Example: </li></ul><ul><li>segment = A1F0 (hex) </li></ul><ul><li>offset = 04C0 (hex) </li></ul><ul><li>logical address = A1F0:04C0 (hex) </li></ul><ul><li>what is the linear address? </li></ul><ul><li>Solution: </li></ul><ul><li>A1F0 0 (add 0 to segment in hex) </li></ul><ul><li>+ 04C0 (offset in hex) </li></ul><ul><li>A23C0 (20-bit linear address in hex) </li></ul>
  49. 49. Your turn . . . What linear address corresponds to logical address 028F:0030? Solution: 028F0 + 0030 = 02920 (hex) Always use hexadecimal notation for addresses What logical address corresponds to the linear address 28F30h? Many different segment:offset (logical) addresses can produce the same linear address 28F30h. Examples: 28F3:0000, 28F2:0010, 28F0:0030, 28B0:0430, . . .
  50. 50. Flat Memory Model <ul><li>Modern operating systems turn segmentation off </li></ul><ul><li>Each program uses one 32-bit linear address space </li></ul><ul><ul><li>Up to 2 32 = 4 GB of memory can be addressed </li></ul></ul><ul><ul><li>Segment registers are defined by the operating system </li></ul></ul><ul><ul><li>All segments are mapped to the same linear address space </li></ul></ul><ul><li>In assembly language, we use .MODEL flat directive </li></ul><ul><ul><li>To indicate the Flat memory model </li></ul></ul><ul><li>A linear address is also called a virtual address </li></ul><ul><ul><li>Operating system maps virtual address onto physical addresses </li></ul></ul><ul><ul><li>Using a technique called paging </li></ul></ul>
  51. 51. Programmer View of Flat Memory <ul><li>Same base address for all segments </li></ul><ul><ul><li>All segments are mapped to the same linear address space </li></ul></ul><ul><li>EIP Register </li></ul><ul><ul><li>Points at next instruction </li></ul></ul><ul><li>ESI and EDI Registers </li></ul><ul><ul><li>Contain data addresses </li></ul></ul><ul><ul><li>Used also to index arrays </li></ul></ul><ul><li>ESP and EBP Registers </li></ul><ul><ul><li>ESP points at top of stack </li></ul></ul><ul><ul><li>EBP is used to address parameters and variables on the stack </li></ul></ul>32-bit address 32-bit address 32-bit address Unused STACK DATA CODE EIP ESI EDI EBP ESP Linear address space of a program (up to 4 GB) CS DS SS ES base address = 0 for all segments
  52. 52. Protected Mode Architecture <ul><li>Logical address consists of </li></ul><ul><ul><li>16-bit segment selector (CS, SS, DS, ES, FS, GS) </li></ul></ul><ul><ul><li>32-bit offset (EIP, ESP, EBP, ESI ,EDI, EAX, EBX, ECX, EDX) </li></ul></ul><ul><li>Segment unit translates logical address to linear address </li></ul><ul><ul><li>Using a segment descriptor table </li></ul></ul><ul><ul><li>Linear address is 32 bits (called also a virtual address ) </li></ul></ul><ul><li>Paging unit translates linear address to physical address </li></ul><ul><ul><li>Using a page directory and a page table </li></ul></ul>
  53. 53. Logical to Linear Address Translation Upper 13 bits of segment selector are used to index the descriptor table TI = Table Indicator Select the descriptor table 0 = Global Descriptor Table 1 = Local Descriptor Table GDTR, LDTR
  54. 54. Segment Descriptor Tables <ul><li>Global descriptor table (GDT) </li></ul><ul><ul><li>Only one GDT table is provided by the operating system </li></ul></ul><ul><ul><li>GDT table contains segment descriptors for all programs </li></ul></ul><ul><ul><li>Also used by the operating system itself </li></ul></ul><ul><ul><li>Table is initialized during boot up </li></ul></ul><ul><ul><li>GDT table address is stored in the GDTR register </li></ul></ul><ul><ul><li>Modern operating systems (Windows-XP) use one GDT table </li></ul></ul><ul><li>Local descriptor table (LDT) </li></ul><ul><ul><li>Another choice is to have a unique LDT table for each program </li></ul></ul><ul><ul><li>LDT table contains segment descriptors for only one program </li></ul></ul><ul><ul><li>LDT table address is stored in the LDTR register </li></ul></ul>
  55. 55. Segment Descriptor Details <ul><li>Base Address </li></ul><ul><ul><li>32-bit number that defines the starting location of the segment </li></ul></ul><ul><ul><li>32-bit Base Address + 32-bit Offset = 32-bit Linear Address </li></ul></ul><ul><li>Segment Limit </li></ul><ul><ul><li>20-bit number that specifies the size of the segment </li></ul></ul><ul><ul><li>The size is specified either in bytes or multiple of 4 KB pages </li></ul></ul><ul><ul><li>Using 4 KB pages, segment size can range from 4 KB to 4 GB </li></ul></ul><ul><li>Access Rights </li></ul><ul><ul><li>Whether the segment contains code or data </li></ul></ul><ul><ul><li>Whether the data can be read-only or read & written </li></ul></ul><ul><ul><li>Privilege level of the segment to protect its access </li></ul></ul>
  56. 56. Segment Visible and Invisible Parts <ul><li>Visible part = 16-bit Segment Register </li></ul><ul><ul><li>CS, SS, DS, ES, FS, and GS are visible to the programmer </li></ul></ul><ul><li>Invisible Part = Segment Descriptor (64 bits) </li></ul><ul><ul><li>Automatically loaded from the descriptor table </li></ul></ul>
  57. 57. Paging <ul><li>Paging divides the linear address space into … </li></ul><ul><ul><li>Fixed-sized blocks called pages , Intel IA-32 uses 4 KB pages </li></ul></ul><ul><li>Operating system allocates main memory for pages </li></ul><ul><ul><li>Pages can be spread all over main memory </li></ul></ul><ul><ul><li>Pages in main memory can belong to different programs </li></ul></ul><ul><ul><li>If main memory is full then pages are stored on the hard disk </li></ul></ul><ul><li>OS has a Virtual Memory Manager (VMM) </li></ul><ul><ul><li>Uses page tables to map the pages of each running program </li></ul></ul><ul><ul><li>Manages the loading and unloading of pages </li></ul></ul><ul><li>As a program is running, CPU does address translation </li></ul><ul><li>Page fault : issued by CPU when page is not in memory </li></ul>
  58. 58. Paging – cont’d linear virtual address space of Program 1 Hard Disk Main Memory Pages that cannot fit in main memory are stored on the hard disk Each running program has its own page table The operating system uses page tables to map the pages in the linear virtual address space onto main memory As a program is running, the processor translates the linear virtual addresses onto real memory (called also physical ) addresses The operating system swaps pages between memory and the hard disk linear virtual address space of Program 2 Page 0 Page 1 Page 2 . . . Page n Page 0 Page 1 Page 2 . . . Page m . . .