PDA

View Full Version : [Gas]Problemi


Luc@s
07-07-2005, 17:33
#include <iostream>
#include <string>

std::string name;

char eax, ebx, ecx, edx, res;

void CpuInfo()
{
// BASIC INFO
__asm ("xor %0, %0 ; cpuid" : "=r"(res) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx));
name = eax;
name += ebx;
name += ecx;
name += edx;
std::cout << name.c_str() << "\n";

}

int main()
{
CpuInfo();
std::cin.get();
return 0;
}
// :~


Non mi stampa nulla....
Eppure la sintassi del comando asm inline mi sembra giusta(il cod asm lo sarebbe normalmente in fasm/nasm)

Tnks

ilsensine
07-07-2005, 17:45
Scritto in fretta; mi perdonerai la scarsa fantasia nei nomi.

#include <iostream>
#include <string>

unsigned eax, ebx, ecx, edx;
std::string name;

std::string RegToStr(unsigned _r)
{
union {
unsigned r;
char s[5];
} __r;
__r.r = _r;
__r.s[4] = '\0';
return std::string(__r.s);
}

void CpuInfo()
{
__asm ("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : );
name =RegToStr(ebx);
name += RegToStr(edx);
name += RegToStr(ecx);
std::cout << name.c_str() << "\n";

}

int main()
{
CpuInfo();
std::cin.get();
return 0;
}

ilsensine
07-07-2005, 18:09
:muro:
Ovviamente la riga asm deve essere questa...

__asm ("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a"(0) );

DanieleC88
08-07-2005, 09:05
Infatti, Luc@s, ilsensine ha ragione: io per il cpuid utilizzo questa istruzione:
uint32_t regs[4];

__asm__ __volatile__
(
"movl %%ebx, %%esi \n"
"cpuid \n"
"xchgl %%esi, %%ebx \n"
: "=a" (regs[0]), "=S" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
: "0" (0)
);

ilsensine
08-07-2005, 09:09
Perché vuoi preservare ebx?

DanieleC88
08-07-2005, 09:32
Perché vuoi preservare ebx?
Sai, ad essere sincero non ricordo più perché ho scelto di preservare %ebx. Quella istruzione devo averla scritta mesi fa, se ce l'ho messa un motivo deve pur esserci, ma al momento non ricordo. :D

ilsensine
08-07-2005, 09:33
Non c'è alcun motivo, puoi utilizzarlo come tutti gli altri ;)