wackazong Posted August 25, 2008 Report Share Posted August 25, 2008 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 returnHow 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. Quote Link to comment Share on other sites More sharing options...
TK. Posted August 25, 2008 Report Share Posted August 25, 2008 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%2FThis 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%2FThe 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%2FBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
wackazong Posted August 25, 2008 Author Report Share Posted August 25, 2008 Thanks, I only looked in the base package and did not find an app where I could really understand what was going on. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 25, 2008 Report Share Posted August 25, 2008 Don't forget the wiki - there is a whole section devoted to this subject at http://www.midibox.org/dokuwiki/how_to_mix_c_and_asm. At the moment, it's very bare, although it links to a very informative forum post. Perhaps you'll flesh it out a little when you finish your work? :) Quote Link to comment Share on other sites More sharing options...
wackazong Posted September 1, 2008 Author Report Share Posted September 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
TK. Posted September 2, 2008 Report Share Posted September 2, 2008 yes, SET_BSR is a macro which simplifies the usage of movlb, see also:http://svnmios.midibox.org/filedetails.php?repname=svn.mios&path=%2Ftrunk%2Finclude%2Fasm%2Fmacros.hBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted September 13, 2008 Report Share Posted September 13, 2008 I generated a simple application sceleton which uses a c and an asm part, and links them both together.Would be cool if you could show the various ways of doing it... Functions, variables, inline, included, via modules, etc 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.