代码之家  ›  专栏  ›  技术社区  ›  Increasingly Idiotic

使用gnu汇编宏的“垃圾表达式”

  •  0
  • Increasingly Idiotic  · 技术社区  · 7 年前

    我大概是在跟踪 this guide 建立一个简单的操作系统。它提供了一些用于nasm的程序集,但我使用的是gnu汇编程序。

    在程序集文件的顶部,我正在使用

    .intel_syntax noprefix
    

    我定义了一个这样的宏

    .macro no_error_code_handler num
    .global interrupt_handler_\num
    .type interrupt_handler_\num, @function
    interrupt_handler_\num:
        push dword 0
        push dword \num
        jmp common_int_handler
    .endm
    

    如果重要的话, common_int_handler 被定义为

    common_int_handler:
        pushad
        call int_handler # This is a C function
        popad
        add esp, 8
        iret
    

    最后我有了电话

    no_error_code_handler 0
    

    我希望扩展到

    .global interrupt_handler_0
    .type interrupt_handler_0, @function
    interrupt_handler_0:
        push dword 0
        push dword 0
        jmp common_int_handler
    

    编译时,我从 no_error_code_handler 0 台词

    Assembler messages:
    Error: junk `0' after expression
    Error: junk `0' after expression
    

    它是否与将类型定义为函数有关,即使它的行为不像普通函数?我应该用 .exitm 从我离开后的某个地方 iret 指示?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Community CDub    6 年前

    以下几行是导致错误的原因

    push dword 0
    push dword \num
    

    dword 在此上下文中无效。

    push 0
    push \num
    

    删除dword解决了这个问题