THE PENTIUM AND PENTIUM PRO MICROPROCESSORS:NEW PENTIUM INSTRUCTIONS.

NEW PENTIUM INSTRUCTIONS

The Pentium contains only one new instruction that functions with normal system software; the remainder of the new instructions are added to control the memory-management mode feature and serializing instructions. Table 18–3 lists the new instructions added to the Pentium instruction set.

The CMPXCHG8B instruction is an extension of the CMPXCHG instruction added to the 80486 instruction set. The CMPXCHG8B instruction compares the 64-bit number stored in EDX and EAX with the contents of a 64-bit memory location or register pair. For example, the CMPXCHG8B DATA2 instruction compared the eight bytes stored in memory location DATA2 with the 64-bit number in EDX and EAX. If DATA2 equals EDX:EAX, the 64-bit number stored in ECX:EBX is stored in memory location DATA2. If they are not equal, the contents of DATA2 are stored into EDX:EAX. Note that the zero flag bit indicates that the contents of EDX:EAX were equal or not equal to DATA2.

The CPUID instruction reads the CPU identification code and other information from the Pentium. Table 18–4 shows different information returned from the CPUID instruction for various input values for EAX. To use the CPUID instruction, first load EAX with the input value and then execute CPUID. The information is returned in the registers indicated in the table.

The Pentium and Pentium Pro Microprocessors-0475

If a 0 is placed in EAX before executing the CPUID instruction, the microprocessor returns the vendor identification in EBX, EDX, and EBX. For example, the Intel Pentium returns “GenuineIntel” in ASCII code with the “Genu” in the EBX, “ineI’ in EDX, and “ntel” in ECX. The EDX register returns information if EAX is loaded with a 1 before executing the CPUID instruction.

Example 18-1 illustrates a short program that reads the vendor information with the CPUID instruction. This software was placed into the TODO: section of the OnInitDialog function of a simple dialog application. It then displays it on the video screen in an ActiveX label as illustrated in Figure 18–11. The CPUID instruction functions in both the real and protected mode and can be used in any Windows application.

The Pentium and Pentium Pro Microprocessors-0476The Pentium and Pentium Pro Microprocessors-0477

The RDTSC instruction reads the time-stamp counter into EDX:EAX. The time-stamp counter counts CPU clocks from the time the microprocessor is reset, where the time-stamp counter is initialized to an unknown count. Because this is a 64-bit count, a 1GHz microproces- sor can accumulate a count of over 580 years before the time-stamp counter rolls over. This instruction functions only in real mode or privilege level 0 in protected mode.

Example 18-2 shows a class written for Windows that provides member functions for accurate time delays and also member functions to measure software execution times. This class is added by right-clicking on the project name and inserting an MFC generic class named TimeD. It contains three member functions called Start, Stop, and Delay.The Start( ) function is used to start a measurement and Stop( ) is used to end a time measurement. The Stop( ) function returns a double floating-point value that is the amount of time in microseconds between Start( ) and Stop( ).

The Delay function causes a precision time delay based on the time-stamp counter. The parameter transferred to the Delay function is in milliseconds. This means that a Delay(1000) causes exactly 1000 ms of delay.

When TimeD is initialized in a program, it reads the microprocessor frequency in MHz from the Windows registry file using the RegQueryValueEx function after opening it with the RegOpenKeyEx function. The microprocessor clock frequency is returned in the MicroFrequency class variable.

The Pentium and Pentium Pro Microprocessors-0478

If an additional Delay is needed, it could be added to the class to cause delays in microseconds, but a restriction should be made so it is no less than about 2 or 3 microseconds, because of the time that it takes to add the time to the count from the time-stamp counter.

Example 18-3 shows a sample dialog application that used Delay( ) to wait for a second after clicking the button before changing the foreground color of an ActiveX Label. What does not appear in the example is that at the beginning of the dialog class an #include “TimeD.h” statement appears. The software itself is in the TODO: section of the OnInitDialog function.

The RDMSR and WRMSR instructions allow the model-specific registers to be read or written. The model-specific registers are unique to the Pentium and are used to trace, check performance, test, and check for machine errors. Both instructions use ECX to convey the register number to the microprocessor and use EDX:EAX for the 64-bit-wide read or write. Note that the register addresses are 0H–13H. See Table 18–5 for a list of the Pentium model-specific registers and their contents. As with the RDTSC instruction, these model-specific registers operate in the real or privilege level 0 of protected mode.

Never use an undefined value in ECX before using the RDMSR or WRMSR instructions. If ECX = 0 before the read or write machine-specific register instruction, the value returned, EDX:EAX, is the machine check exception address. (EDX:EAX is where all data reside when written or read from the model-specific registers.) If ECX = 1, the value is the machine check exception type; if ECX = 0EH, the test register 12 (TR12) is accessed. Note that these are internal registers designed for in-house testing. The contents of these registers are proprietary to Intel and should not be used during normal programming.

The Pentium and Pentium Pro Microprocessors-0479

Leave a comment

Your email address will not be published. Required fields are marked *