Page 1 of 1

how to use a macro's parameter in GAS

Posted: Sat Feb 16, 2013 9:14 am
by lcjuanpa
Hi everybody
I have a problem related with the use of parameters in a macro. The code listed below works perfectly in NASM, but I'm working with GAS and I can't get the correct value of those parameters, code in GAS is listed below.

----------------------------------------------------------------------------
NASM
----------------------------------------------------------------------------
IRQ 0, 32
IRQ 1, 33
IRQ 2, 34

%macro IRQ 2
global irq%1
irq%1:
cli ; Disable interrupts firstly.
push byte 0 ; Push a dummy error code.
push byte %2 ; Push the interrupt number.
jmp irq_common_stub ; Go to our common handler code.
%endmacro


----------------------------------------------------------------------------
GAS
----------------------------------------------------------------------------
IRQ 0, 32
IRQ 1, 33
IRQ 2, 34

.macro IRQ int_nro, int_mask
.global irq\int_nro
irq\int_nro:
cli # Disable interrupts firstly.
pushl $0 # Push a dummy error code.
pushl \int_mask # Push the interrupt number.
jmp irq_common_stub # Go to our common handler code.
.endm


The symbol of tables is generated correctly:
irq32, irq33, irq34
and link correctly but when the program writed in GAS is running I can't get the value 32, 33, 34 of those parameters to pass to my handler, I get values such as: 4026597029 instead of 32.

Is possible write the same code as NASM in GAS or I have to write the 32 macros in GAS?
I was looking in the forum and in book suggested in other topic but I can't get the solution.
Thanks.

Re: how to use a macro's parameter in GAS

Posted: Sat Feb 16, 2013 10:47 am
by DLBuunk
Hmm, let's see what your macro expands to, take for example "IRQ 0, 32" :

Code: Select all

	.global irq0
irq0:
	cli
	pushl	$0
	pushl	32
	jmp irq_common_stub
So you end up with what is at memory adress 32, rather than the immediate value 32.

Re: how to use a macro's parameter in GAS

Posted: Sat Feb 16, 2013 11:48 am
by lcjuanpa
DLBuunk wrote:Hmm, let's see what your macro expands to, take for example "IRQ 0, 32" :

Code: Select all

	.global irq0
irq0:
	cli
	pushl	$0
	pushl	32
	jmp irq_common_stub
So you end up with what is at memory adress 32, rather than the immediate value 32.
Thanks man
Your macro expand give me the solution. It needs '$' before the parameter.
The solution was:
irq0:
cli
pushl $0
pushl $32
jmp irq_common_stub

so my new macro is:

.macro IRQ int_nro, int_mask
.global irq\int_nro
irq\int_nro:
cli
pushl $0
pushl $\int_mask
jmp irq_common_stub
.endm

Now all is working perfectly, at momment :)
Thanks.