inline assembly code in c++???

Started by
15 comments, last by avianRR 22 years, 8 months ago
quote:Original post by Martee
You can''t directly use variables in inline ASM. I think this might do what you''re looking for:

int info = 0;
__asm__(
"mov $0x01,%eax\n\t"
"cpuid\n\t"
:"=a"(info)
);



~~~~~~~~~~
Martee


Tryed that, it generates parse errors (as does any of the input output syntexing stuff) I can''t even get the sample code from linuxassembly.org to compile with out the same errors. However they do also say that the way I have it should work and at least it compiles, but it then just can''t resolve the variables in the linker


------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
main() {    int info = 0;     __asm__ (        "mov $0x01, %%eax        cpuid"        : "=edx" (info)    );     printf("cpuid=%d\n", info);     if (info & 0x00800000) printf("MMX supported\n");    if (info & 0x00200000) printf("SSE supported\n");    if (info & 0x00400000) printf("SSE2 supported\n");     return 1;} 


compiles (note the double % on eax in the instructions. that's needed when you have an input/output/modifier).

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

Edited by - Godfree^ on July 21, 2001 8:52:43 AM

Edited by - Godfree^ on July 21, 2001 8:54:45 AM

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

Thanks Godfree^, That''s it! MY PROGRAM WORKS! That''s what I missed. When I went back and looked at linux assembly.org again I realized that I must have missed that part.
Thanks to everyone that helped! And happy coding...
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Well, not entirly...
I went back through all the code cleaning up my comments and getting rid of all the commented out test lines of code and found that I still had one section commented out becuase it had anotherer error, the following is copyed from a previous post of mine...

I have to push and pop the eflags register (pushfd, popfd) I can''t however find the equivelant operation under linux and they come up with the warning "no such 386 instruction"

example...
"pushfd\n\t"
produces the error "/tmp/ccjs1zp.s: 305: no such 386 instruction: ''pushfd''"

I''ve searched Sandpile.org and can''t find any info there eather.
thanks,
Rob

------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Well, I found it...
pushfd in msvc is pushf in gas.
I figured it out by looking at the disasembly of my win32 version to get the opcode then looked up the opcode at sandpile.org to get the mnemonic.

Again, thanks for the help everyone.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Why don''t you just read out /proc/cpuinfo for CPUID on Linux?

Of course this thread was worth it for the sake of learning ASM, but the /proc/cpuinfo can give you other details (esp. on SMP systems).

cu,
Prefect

Resist Windows XP''s Invasive Production Activation Technology!
One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy
Prefect, parsing /proc/cpuinfo can be quite a hefty chunk of code, where cpuid is a lot quicker, and you get a nice value which you can check bits on.

It''s more efficient to use cpuid....

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

This topic is closed to new replies.

Advertisement