forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with macro parameters + asm

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Mon Oct 24, 2005 4:56 am    Post subject: Help with macro parameters + asm Reply with quote

how can i make something like this to work?

Code:

#define mtest(val0) \
"sb $24, val0($3)\n"


mtest(10) expand to: sb $24, val0($3), not sb $24, 10($3)

thanks
Back to top
View user's profile Send private message Visit poster's website
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Mon Oct 24, 2005 5:53 am    Post subject: Reply with quote

This is basic C preprocessor stuff. You need to "stringify" the macro argument:
Code:
#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 :).
Back to top
View user's profile Send private message
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Mon Oct 24, 2005 6:37 am    Post subject: Reply with quote

lol thanks :D
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Mon Oct 24, 2005 8:33 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Mon Oct 24, 2005 8:57 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
jsgf



Joined: 12 Jul 2005
Posts: 254

PostPosted: Mon Oct 24, 2005 9:00 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group