--0__=EqZBLaddljbyJWNzmTzNMdPOXgAaNnfbqTwEXDeGbGDjKXsRcKVppOrW Content-type: text/plain; charset=us-ascii Content-Disposition: inline [I thought I sent this a long time ago, but today my email program claims I never sent this. Let's send it again just to make sure.] Dear ``Anbar System'', Anbar System on 2001-05-21 01:54:12 PM >I didn't understude very well yet. >Could you give some detail of this fcall macro. > >for example: >fcall macro subroutine_name ;this will assume for all my fcall ? > local here ;.... > lcall subroutine_name ;.... > pagesel here ;.... >here: ;.... > endm ;..... It's pretty easy to use this macro. First you just copy-and-paste it near the top of a ``.asm'' file (or put it in a ``.inc'' file and stick the appropriate ``include'' statement near the top of that ``.asm'' file). You don't need to make any modifications. Then you use it to call subroutines. Check out the example I've appended to this message. It should compile and run. >I didn't find "Help | MPLAB Assembler help, >just "Help | MPLAB help. >My corrent version is 5.11.00 Would you like to download MPLAB --0__=EqZBLaddljbyJWNzmTzNMdPOXgAaNnfbqTwEXDeGbGDjKXsRcKVppOrW Content-type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-transfer-encoding: quoted-printable =AE Version 5.30 http://www.microchip.com/10/tools/picmicro/devenv/mplabi/index.htm ? Luis Fernando, AKA antoniasse on 2001-05-22 = 09:53:18 AM asked: ... >the fcall macro in my program ... >works perfectly ... >Have I set the PCLTAH bits back to the value of the >"fcall" page on a return? Yes. OK, I'll try to explain what's going on here. If you really want to see= what the linker does to your own code, I recommend looking at the ``.lst'' file = generated by the linker. (If you're an assembly language programmer, sometimes yo= u learn some clever tricks by looking at the code generated by optimizing C com= pilers). The macro preprocessor expands the
     fcall sub4
     GOTO main
into this:
     pagesel sub4
     call sub4
     pagesel _4here
_4here:
     GOTO main
. Then the compiler and linker expand that into 6 instructions. The exa= ct 6 instructions are listed in the ".lst" file generated by the linker. (As= opposed to the ".lst" file generated by the assembler). I've added my comments = to that ".lst" file: ; ; first set the PCLATH bits in preparation for the call: ; pagesel sub4 000021 158a BSF 0xa,0x3 = =20 000022 120a BCF 0xa,0x4 = =20 ; call sub4 000023 2006 CALL 0x6 = =20 ; ; reset the PCLATH bits to "here", which is necessary for the lo= cal GOTO. ; pagesel _4here 000024 118a BCF 0xa,0x3 = =20 000025 120a BCF 0xa,0x4 = =20 ; ; do the GOTO 000026 2812 GOTO 0x12 GOTO main I'm hoping that the ``pagesel'' logic in future versions of the compile= r will reduce this to 5 (maybe even 4 ?) instructions the next time I compile,= without any changes in my source code. -- David Cary -------------------------------------------- ; Originally by Luis Fernando; ; modified by David Cary. ;Here, a simple example fcall macro subroutine_name local here lcall subroutine_name pagesel here here: endm ; normally I don't specify a particular address; the linker handles it automatically. mainloop CODE 0x0012 ;PAGE0 main: fcall sub1 fcall sub2 ; simple ``call'' would save a few bytes here. fcall sub3 fcall sub4 ; if ``call'' or ``lcall'' were used here, this GOTO wo= uldn't work right. GOTO main sub2: ; ... RETURN sub3: ; ... RETURN ;------------------------------------------------------------------- ; normally I don't specify a particular address; the linker handles it automatically. a_few_subs CODE 0x800 ;PAGE1 sub1: ; ... fcall sub2 RETURN sub4: ; ... fcall sub1 ; simple ``call'' would save a few bytes here. fcall sub3 RETURN ; Luis Fernando END ; end main.asm = --0__=EqZBLaddljbyJWNzmTzNMdPOXgAaNnfbqTwEXDeGbGDjKXsRcKVppOrW-- -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.