首页 > 技术知识 > 正文

int get_cpu_id_by_asm(char* cpu_id)

{

bzero(cpu_id, strlen(cpu_id)); unsigned int s1 = 0; unsigned int s2 = 0; __asm__ __volatile__ ( “movl $0x01, %%eax; \n\t” “xorl %%edx, %%edx; \n\t” “cpuid; \n\t” “movl %%edx, %0; \n\t” “movl %%eax, %1; \n\t” : “=m”(s1), “=m”(s2) ); if (0 == s1 && 0 == s2) { return -1; } char cpu[32] = { 0 }; snprintf(cpu, sizeof(cpu), “%08X%08X”, htonl(s2), htonl(s1)); memcpy(cpu_id, cpu, 128); return 0;

}

这个纯c函数在linux 与osx下都可以获取到cpuid,hi3518V100 编译报错

/tmp/ccpeXN1e.s: Assembler messages:

/tmp/ccpeXN1e.s:32: Error: bad instruction movl $0x01,%eax /tmp/ccpeXN1e.s:33: Error: bad instructionxorl %edx,%edx

/tmp/ccpeXN1e.s:34: Error: bad instruction cpuid /tmp/ccpeXN1e.s:35: Error: bad instructionmovl %edx,[sp,#8]

/tmp/ccpeXN1e.s:36: Error: bad instruction `movl %eax,[sp,#12]

请问是不支持汇编指令,还是需要在编译的时候加什么参数。请大神帮忙解答一下

或者也可以提供一下其他可以获取到海思芯片唯一特征码的方法,感激不尽

猜你喜欢