wmdlinuxshell 2024-03-18 20:03 采纳率: 1.6%
浏览 113

missing terminating " character

img



#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);
    }
}

报错如图片

  • 写回答

2条回答 默认 最新

  • 码农阿豪@新空间 优质创作者: Java、后端开发技术领域 2024-03-18 20:04
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    根据图片提示信息,代码中缺少了一个宏定义的头文件,需要添加:
    #include <asm/io.h>
    

    在代码开头添加上述头文件即可解决报错。完整代码如下:

    #include <stdio.h>
    #include <asm/io.h>  // 添加该头文件
    #define BIOS_CMOS_READ 0x1a
    void main()
    {
        unsigned char status;
        unsigned char value;
        unsigned int ax;
        unsigned char index = 0x2a;
    #ifdef _WIN32
    #ifdef _WIN32
        __asm__ __volatile__ (
            "mov ax, BIOS_CMOS_READ \n"
            "mov esi, index \n"
            "mov edi, value \n"
            "int 0x15 \n"
            "mov status, al \n"
        );
    #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)
            : "0" (BIOS_CMOS_READ), "c" (index), "b" (value)
            : "edx"
        );
    #endif
        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 {
            printf("Hardware information: 0x%02x\n", value);
        }
    }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 3月18日