Archived

This topic is now archived and is closed to further replies.

ranxact

ASM functions in VC++

Recommended Posts

Hello all, I need to write a function entirely in ASM. int function() { <- but there are ASM instructions here... _asm{ ASM instuctions... } } the function calling it needs to have certain regesters retained, however, I call it often enough to not want to push them and pop them everytime i call it. (i don''t need to use them in the function) would making the function inline work? maybe i should use a macro? but i call it alot...

Share this post


Link to post
Share on other sites
Yes, preserving the registers that are being used is happening before your ASM statement that you can''t really see, so what you need to do is make your function entirely in ASM, and then compile the code to an OBJ file, and link it to your VC program. declare the function as a extern "C" void MyFunction(int blah);

etc...

Hope this helps!

------------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
You can declare the function as ''naked'' (see MSDN library for details). That keyword does exactly what you want: It tells the
compiler not to write its own into/extro code and gives you the full control. However you will have to watch for destroyed register contents and correct stack handling.
The ''naked'' keyword is intended to be used esp. for driver development etc.

HTH,
Alex



Alexander Stockinger
Programmer

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
wow, i didn''t know about naked!
it''s perfect for something that gets called thousands of times a second and needs all the speed it can get

Share this post


Link to post
Share on other sites


DaJudge you are DaMan... Thanx for the help. ''NaKed''... i would have never tried that on my own... Although i think i will remember it

RanXacT

(and Gladiator, that was my alternative, but i am actually switching from MASM to VC++ for the better Debugging ....)

Share this post


Link to post
Share on other sites