FromNandの日記

自分的備忘録

【アセンブラ】GASでのマクロ関数の書き方

基本的にはつぎのように書けばいいらしい。

.macro <マクロの名前> <可変の名前>
           ~処理~
           call \<可変の名前>  //\<可変の名前>で参照することができる。あとcall以外もOK
           ~処理~
.endm

 

実際の例で確認しておきたい。

.globl asm_inthandler21, asm_inthandler2c
.extern inthandler21, inthandler2c

#マクロを定義している
.macro asm_inthandler   c_inthandler
    pushw %es
    pushw %ds
    pushal
    movl %esp, %eax
    pushl %eax
    movw %ss, %ax
    movw %ax, %ds
    movw %ax, %es
    call \c_inthandler
    popl %eax
    popal
    popw %ds
    popw %es
    iret
.endm

asm_inthandler21:
    asm_inthandler inthandler21

asm_inthandler2c:
    asm_inthandler inthandler2c