tschak909 Posted August 16, 2014 Share Posted August 16, 2014 Hi, is the http://www.cc65.org/doc/internal.txt document sufficient enough to learn how to pass data to and from assembler snippets to and from C? I need to replace the serial code with some assembler, so that I have finer grained control over the serial port in my BBS project. -Thom Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted August 17, 2014 Share Posted August 17, 2014 (edited) Hi, is the http://www.cc65.org/doc/internal.txt document sufficient enough to learn how to pass data to and from assembler snippets to and from C? Yes. Try to use the 'fastcall' convention to save some cycles (prototype for the function needed then). And if you have to supply multiple parameters, passing a pointer via fastcall to a struct is more effective than supplying them via stack. If you encounter problems, inspect the C-library source code. Edited August 17, 2014 by Irgendwer Quote Link to comment Share on other sites More sharing options...
danwinslow Posted August 17, 2014 Share Posted August 17, 2014 (edited) You can use the parameter stack as cc65 itself does by calling the code that cc65 uses. jsr popax for instance will pop the top 2 bytes of the parameter stack into the a and x register. Note that parameters are on the stack with the rightmost first. If you use the fastcall convention you will arrive with the rightmost parameter already in a and x, as irgenwer mentioned. Return value is held in ax. You can also just drop into embedded assembler with the asm() command within a c function. Its often easier to access a global of some sort in assemb;er. Just remember that C will preprend a underscore for the link name, so that foo becomes _foo. You can jsr to a void parameterless c function just as you can to any assembler label. Edited August 17, 2014 by danwinslow Quote Link to comment Share on other sites More sharing options...
Shawn Jefferson Posted August 17, 2014 Share Posted August 17, 2014 Keep in mind also that the optimizer will even try to optimize asm() code inside your C functions. It won't touch pure assembly files (.s) though. There are pragmas you can use to turn it off and back on if it becomes a problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.