
#include <stdio.h>
#define BIOS_CMOS_READ 0x1a
void main() {
unsigned char status;
unsigned char value;
unsigned int ax;
// 0x2a is the index of the hardware piece you want to read
// For example, 0x00 is the equipment type, 0x08 is the CPU type
unsigned char index = 0x2a;
// The BIOS interrupt is different on Linux and Windows
#ifdef _WIN32
#ifdef _WIN32
__asm__ __volatile__ ("
mov ax, BIOS_CMOS_READ
mov esi, index
mov edi, value
int 0x15
mov status, al
");
#endif
#else
asm volatile (
"movw %%ax, %%dx\n\t"
"movb %1, %%al\n\t"
"outb %%al, $0x70\n\t"
"inb $0x71, %%al\n\t"
"movb %%al, %2\n\t"
"movb %%dl, %%al\n\t"
: "=a" (ax), "=b" (value)
: "0" (BIOS_CMOS_READ), "c" (index)
: "edx"
);
#endif
// Check the status byte
if ((status & 0x80) == 0) {
printf("Hardware information is not supported.\n");
} else if ((status & 0x80) == 0x80 && (status & 0x40) == 0) {
printf("CMOS battery is dead.\n");
} else {
// The value variable now contains the hardware information
printf("Hardware information: 0x%02x\n", value);
}
}
报错如图片