gcc - ASM : too many memory references for `mov'

标签 gcc assembly x86 osdev intel-syntax

又是我,我的 idt.S 文件(用 gcc 编译的 Intel 语法)出现新问题。当我尝试编译以下代码时:

load_idt:
        mov edx, (esp + 4) ; On this line
        lidt (edx)
        sti
        ret

我收到一个错误,我真的不知道如何解决:
Error: too many memory references for `mov'

最佳答案

如果您使用 GCC 进行组装,例如:

gcc -c -m32 -masm=intel idt.S -o idt.o

问题是:
  • 您需要添加指令 .intel_syntax noprefix到文件的顶部。默认情况下 GCC 组装 .s.S假设 Intel 语法的文件需要 %所有寄存器的前缀。该指令消除了该要求。
  • 在 Intel 语法内存操作数中使用方括号 []而不是括号 () .
  • 评论以 # 开头而不是 ; .

  • 代码应如下所示:
    .intel_syntax noprefix
    
    load_idt:
            mov edx, [esp + 4] # On this line
            lidt [edx]
            sti
            ret
    

    关于gcc - ASM : too many memory references for `mov' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54970389/

    相关文章:

    c - 编译时指针指向的类型如typeof

    Linux:可执行文件找不到共享库

    assembly - 对 X86 分段感到困惑

    c++11 - C11 和 C++11 原子 : acquire-release semantics and memory barriers

    assembly - 使用 x86 计算 32 位相对跳转偏移量

    c++ - 循环遍历一系列字符并在汇编中交换它们

    gcc - CLion + MinGW 测试 CMake 运行完成但出现错误

    c++ - 使用多个源文件时,GDB 不会中断某些代码行

    windows - Windows 8 x64 上的汇编代码

    x86 - (写内核)如何修改中断描述符表?