macro's and local variables

Mischa Baars mjbaars1977@gmail.com
Thu Oct 18 08:52:00 GMT 2012


On 10/18/2012 10:30 AM, Jan Beulich wrote:
>>>> On 17.10.12 at 20:49, Mischa Baars <mjbaars1977@gmail.com> wrote:
>> Now try to uncomment the '.altmacro' directive if you like.
> You _again_ did not read the documentation carefully enough:
> Angle brackets (which is what C shift operators are made of)
> can't be used verbatim in alternate macro mode.
>
> Simply using
>
> #define N (1 shl n)
>
> instead makes the file assemble fine with .altmacro enabled.
>
> Jan
>

Since I would like to interface with C, you would get as demonstrated in 
the attachments. I didn't know that 'shl' is accepted by the C compiler. 
Seems to work for now though.

Mischa.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: common.h
Type: text/x-chdr
Size: 116 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20121018/c0e99773/attachment.bin>
-------------- next part --------------
#include	"common.h"

		.intel_syntax	noprefix

		.code32

		.global		function

		.altmacro

.macro		A		arg1, arg2

		.set		k, 2

.rept		\arg2 - \arg1 - 2

		.set		k, k + 1

.endr

.endm

function:

		.set		j, 0

.rept		N

		.set		i, 0

.rept		N

		A		i + j, j > 0 ? N + j + 1 : i + 2

		.set		i, i + 1

.endr

		.set		j, j + 1

.endr

		ret


-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 74 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20121018/c0e99773/attachment-0001.bin>
-------------- next part --------------
all:
	gcc -g -c ./function.S
	gcc -g ./main.c ./function.o -o ./main



More information about the Binutils mailing list