Jump to content

Mix Assembler and C?


 Share

Recommended Posts

Hi,

I managed to get my own C program running on MIOS, based on the sdcc_skeleton files. Now I want to integrate TKs random function into my program:

;; --------------------------------------------------------------------------

;;  This function generates a new random number

;;  OUT: new random number in SEQ_RANDOM_SEED_[LH]

;; --------------------------------------------------------------------------

SEQ_CORE_GenRandomNumber

  SET_BSR  SEQ_BASE

  movf  SEQ_RANDOM_SEED_L, W, BANKED

  mulwf  SEQ_RANDOM_SEED_H, BANKED

  movf  TMR0L, W

  addwf  PRODL, W

  movwf  SEQ_RANDOM_SEED_L, BANKED

  movlw  0x69

  addwfc  PRODH, W

  movwf  SEQ_RANDOM_SEED_H, BANKED

  return

How do I define this as an assembler function that I can reference in C? I could not find a mixed C/Assembler example project.

Many thanks, ALEXander.

Link to comment
Share on other sites

Hi Alexander,

did you really search for examples?

Here you will find a lot of examples for accessing assembler code from C with a wrapper:

http://svnmios.midibox.org/listing.php?repname=svn.mios&path=%2Ftrunk%2Fmodules%2F

This example is a bit more simple, only one file which references (and contains) the assembly code:

http://svnmios.midibox.org/listing.php?repname=svn.mios&path=%2Ftrunk%2Fapps%2Fexamples%2Fsm_c_example1%2F

The mclock.c file of this application demonstrates, how to use inline assembly code:

http://svnmios.midibox.org/listing.php?repname=svn.mios&path=%2Ftrunk%2Fapps%2Fclockbox%2Fenhanced%2F

Best Regards, Thorsten.

Link to comment
Share on other sites

OK, I got it working. I generated a simple application sceleton which uses a c and an asm part, and links them both together. so far, only one byte is supported for parameters or return values. anybody care? I will extend it soon.

Best, ALEXander.

BTW: is SET_BSR "Set the Bank Select Register"? Took me a while to figure that one out. But now it works.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...
 Share

×
×
  • Create New...