【问题标题】:How to concatenate GNU GAS macro arguments with other tokens to make single label?如何将 GNU GAS 宏参数与其他标记连接以制作单个标签?
【发布时间】:2011-02-28 17:51:54
【问题描述】:

我想使用气体宏在汇编函数中动态创建一组标签。我想做这样的事情:

.macro set_up_jumptab_entry 前缀,从=0,到=10 .quad \prefix_\item .if \to-\from set_up_jumptab_entry \prefix,"(\from+1)",\to 。万一 .endm set_up_jumptab_entry myfunc 0 10

这里的 \prefix_\item 类似于 myfunction_7。现在,我可以找到很多递归调用的示例,但我还没有找到涉及传入宏参数的标签连接之一。气体的记录很差,所以对我来说很难回答这个问题。

  1. 能否将宏的参数与其他标记连接起来以生成单个标记?
  2. 您最喜欢的气体组装器参考是什么?

【问题讨论】:

    标签: assembly gnu-assembler


    【解决方案1】:

    类似的东西

    \argA\()\argB :

    应该创建一个由 argA 和 argB 组成的标签。

    编辑

    测试,\() 好像没必要;测试代码是:

        .file   "test.c"
    
    .macro prova argA, argB
    \argA\argB :
     .endm
        .text
    .globl main
        .type   main, @function
    main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        movl    $0, %eax
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
            prova abc, def
            jmp  abcdef
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.3.2"
        .section    .note.GNU-stack,"",@progbits
    

    这只是最小 C 代码的gcc -S test.c 输出(惰性:D)。 (prova 在意大利语中的意思是test

    【讨论】:

    • 当然会永远循环,所以不要执行最终代码!
    【解决方案2】:

    你最喜欢的气体组装参考是什么?

    文档很好地涵盖了这一点 https://sourceware.org/binutils/docs/as/Macro.html

    字符串 `()' 可用于将宏参数的结尾与以下文本分开。例如:

    .macro opcode base length
        \base\().\length
    .endm
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 2019-08-09
      相关资源
      最近更新 更多