Jump to content
Mac

Macro: rom strings inline with my code

Recommended Posts

Is there a way to duplicate an assembly language macro that I use to store constant strings inline with my code?  The putstr() function pulls the return address (the string address in this case) from top-of-stack, sends the string while updating TOS, and returns to the instruction immediately following the inline string.  Here's the assembly language version I'm trying to duplicate;

putstrg macro   string          ; in-line rom string
        call    putstr          ; inline string print function
        dt      string,0        ; inline string
        endm                    ;
	

Here's the inline print string function...

  /********************************************************************
   *                                                                  *
   ********************************************************************/
    void putstr()               // in-line strings (14 words)
    { strloop:                  // bank 31 (inserted by compiler) |31
      asm movf   _tosl,W        // copy return address to FSR1    |31
      asm movwf  _fsr1l         //  "                             |31
      asm movf   _tosh,W        //  "                             |31
      asm movwf  _fsr1h         //  "                             |31
      asm bsf    _fsr1h,7       // set b7 for access to flash     |31
      asm incf   _tosl,F        // bump return/string address     |31
      asm btfsc  _status,Z      //  "                             |31
      asm incf   _tosh,F        //  "                             |31
      asm movf   _indf1,W       // end-of-string (0x00)?          |31
      asm btfsc  _status,Z      // no, skip (send char), else     |31
      asm return                // exit (end-of-string)           |31
      asm call   putwreg()      // data passed in wreg            |31
      asm bra    strloop        //                                |31
    }

 

Thank you all for your time and kind consideration.

Cheerful regards, Mike, K8LH

 

Edited by Mac

Share this post


Link to post
Share on other sites

Hi

 

I missed this topic in due time,so I don't know if this repply is usefull, but here it goes.

 

That is a nice ASM trick, but I think its uneeded in 'C' and also undesired.

Its not a good idea to directly manipulate the stack when using a compiled language, because you don't control how the compiler handles the stack.

Also bear in mind that due to the limited stack size and specific stack access instructions of the 8 bit PICs, BoostC and other compilers implement a so called "software stack" to handle parameters and automatica variables. The hardware stack is used only for return addresses.

 

To store strings in the program memory you can use the "rom" qualifier (page 47 of the Boost C manual) and then the usual 'C' tools to work with them.

 

HIH

 

Best regards

Jorge

 

 

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum 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...

×