Help with macro parameters + asm

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
jonny
Posts: 351
Joined: Thu Sep 22, 2005 5:46 pm
Contact:

Help with macro parameters + asm

Post by jonny »

how can i make something like this to work?

Code: Select all

#define mtest(val0) \
"sb $24, val0($3)\n"
mtest(10) expand to: sb $24, val0($3), not sb $24, 10($3)

thanks
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

This is basic C preprocessor stuff. You need to "stringify" the macro argument:

Code: Select all

#define mtest(val0) "sb $24, " # val0 "\n"
You get this one for free, but the next time I'm going to point you to a compiler manual or C tutorial :).
jonny
Posts: 351
Joined: Thu Sep 22, 2005 5:46 pm
Contact:

Post by jonny »

lol thanks :D
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

jonny wrote:"sb $24, val0($3)\n"
But also, using literal register numbers in an asm probably isn't going to do what you want (the compiler is free to use any registers it wants, and its free to move your asm around as much as it wants if you don't give it a reason not to). You should look at how to pass parameters into an asm, and set constraints.
jonny
Posts: 351
Joined: Thu Sep 22, 2005 5:46 pm
Contact:

Post by jonny »

yep i know the basics about register literals ( found this useful thread :) http://forums.ps2dev.org/viewtopic.php?t=3558 ), i need macro+parameters because i was experimenting with loop unrolling, macros are good to fix a couple of offsets and don't get mad with copy/paste/modify.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Register literals are only needed if a specific register really needs to be set (like for calling a syscall). Otherwise its better to let the compiler choose all your registers for you.
Post Reply