We help IT Professionals succeed at work.

__Asm and CPUID

laeuchli asked
Medium Priority
Last Modified: 2013-12-03
HI! I am useing Visual C++ 5.0 to write a MMX CPU emulater. It's just a test and I don't know that it will every get any where, however, here is my question. I have a __asm block in one program that writes to the cpu register that tells the computer it is mmx. In another program I use the CPUID to find out if the computer is mmx or not. the test fails. Whats wrong? jesse.laeuchli@usa.net
Watch Question

By the "test fails" do you mean that the test does not work to indicate if MMX is there or not?  Or do you mean a different type of failure (crash etc).

How are you doing the CPUID test?  I don't know how to do the test as it is not in my (regular i.e. non-mmx) pentium manual.  However in general you must make sure that the chip supports the test you are doing.  (The tests are numbered from zero and each chips supports tests up to a specific number.)  That is, that it was designed to handle the number you specify to the CPUID instruction.  If not, then you can assume the feature is not available.

If this doesn't help, (it would be suprised if it did) please post the code of the test.  

The CPUID instruction sets the register(s) you just modified to
the appropriate value for this instruction. There is NO WAY of
getting a non-MMX processor to respond as a MMX processor via
CPUID instruction.

BTW, take a look at http://developer.intel.com

Is don't think Lasuchli is try to get

"a non-MMX processor to respond as a MMX processor via CPUID instruction."

He's just trying to determine if the processor is an MMX processor.  I assume that is one of the capabilities returned by the CPUID instruction  (I don't know since it is not documented in my regular pentium manual)  Presumably, an mmx processor will allow a higher value in EAX (pentium allows 0 or 1) or it will return with some additional bits sets in EDX on the EAX=1 sub-function.

Quoting laeuchli: "I have a __asm block in one program that writes to the cpu register that tells the computer it is mmx. In another program I use the CPUID to find out if the computer is mmx or not. the test fails."

So why would he(laeuchli) set the CPU register(s) BEFORE he does a CPUID?

We should probably be talking to laeuchli instead of debating with each other about he meant, but to continue the debate. . .

I interpreted that to mean that one program (the second one) looks for an MMX chip.  If it is found, fine.  If not, it loads a different program that acks as an emmulator.

You;ve heard of creative writing?  Well, you might have just witnessed creative reading.  But then again, maybe not.  When laeuchli responds, we'll find out.


Here is the program that tests for mmx . It is run while program 2 is runing.
#include <stdio.h>
void main (void) { int ISON;

_asm {
mov      EAX, 1                  
_emit 0x0f            
_emit 0xa2  

test      EDX,00800000h      ; Is IA MMX technology bit (Bit 23 of EDX) in feature flags set?
jnz      MMX_Technology_Found
jmp MMX_Not
mov ISON,1
jmp Exit
mov ISON,0
cout<<"MMX FOUND";
cout<<"MMX NOT FOUND";

Here is program 2
void main()
      cout<<"Emulater for MMX";

sub EDX,EDX ;Startup make sure EDX is  empty
mov EDX,00800000h ;Fib to the CPU that it's MMX when it's only a 75MHz
jmp Emulate_MMX

As to the debate tigo is right about what I am trying to do.

You are doing things the wrong way.

First: the two programs are running as different processes. Setting registers on one process will not cause any change on the other process.

Second: You will never get CPUID respondin' "MMX processor" if it's not.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

I'm not sure what tiago means in his second point.  But his first point is certainly correct.  Your second program is caught in an endless loop setting the EDX to 0 and then to 800000H.  While that process is running, EDX will be one of those values.  While another process is running it will be something else.  When processes are changed the registers are saved and restored.  Otherwise there would be chaos.

What is it that you are trying to do?

If you are trying to fool you own program into believing its on an MMX chip, that is possible.  If you are trying to fool another program, that will be (practically) impossible.  You cannot tell when another program will run the CPUID instruction.   You cannot modify the value the other program will get from the CPUID instruction.

Maybe it is possible to catch the "Invalid Opcode" exception if the processor doesn't have the CPUID/MMX extensions and do the appropriate "emulation".

No, the CPUID is available on pentium and later processors.  Pentium processors that are not MMX will not cause the invalid opcode exception and will not have MMX.

In addition, I suspect laeuchli is not really tring to emmulate MMX.  He's trying to fool a program into thinking it is there. That's likely to be a mistake.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.