Jump to content
IGNORED

cc65: passing to and from C code


Recommended Posts

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 by Irgendwer
Link to comment
Share on other sites

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 by danwinslow
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...