the way to declare local variables in macro asm of nasm is like:%local old_ax:word,and the way to declare local variables in macro asm of masm is like:local old_ax:WORD,so what's the way to declare local variables in macro asm of gas?
Asked
Active
Viewed 1,370 times
-4
-
1Read the [manual](https://sourceware.org/binutils/docs/as/Altmacro.html). `.altmacro` and `LOCAL`. – Jester Jan 12 '16 at 17:19
-
Thanks a lot anyway! But your answer to my question isn't what I want. Maybe I haven't state the question clearly. The "local variables" stated above is allocated in the stack;the meaning of "local variables" is just like it in C language. – linkerrors Jan 13 '16 at 02:08
1 Answers
1
gas
is primarily intended as a compiler backend, not for human use. As such, it's lacking some features, among others this one. You can of course try to make a macro to do this, something along these lines:
.intel_syntax noprefix
.globl main
.macro local head, tail:vararg
# assume dwords for simplicity
.set localsize, localsize + 4
.set \head, -localsize
.ifnb \tail
local \tail
.endif
.endm
main:
.set localsize, 0
local old_ax, old_dx
enter localsize, 0
mov [ebp+old_ax], ax
mov [ebp+old_dx], dx
leave
ret
But in general you can just use the equates for stack offsets directly, such as:
main:
.set old_ax, 4
.set old_dx, 0
sub esp, 8
mov [esp+old_ax], ax
mov [esp+old_dx], dx
add esp, 8
ret

Jester
- 56,577
- 4
- 81
- 125
-
So,I would allocate local variables manually,unwilling,because the gas hasn't helped me do that! Thanks a lot! – linkerrors Jan 13 '16 at 03:00