Embedded Strings in your Code Space


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    While I don't see any advantages over the previous examples, it does present a few problems that weren't there before.

    They are the same problems I came across when writing the strings program I pointed out in the 2nd post of this thread.

    By using the "dt" directive, it uses twice as much code space by only storing 1 byte per word. The "da" directive is much more efficient. It packs two 7-bit characters in each word.

    Also, when using the MOVE?CW macro inside another macro, it makes it so that all string data has to be placed at the beginning of the program. If you place the string data after the SendString command that's trying to use it, you will get a "Address label duplicate or defferent in second pass" error.

    John Barrat figured out how to get around that problem with this macro. It compiles to the exact same thing as the MOVE?CW, but because of which "Pass" it gets compiled on, it can find an address either before or after the code that uses it.

    Code:
    '------------GetAddress Macro - Location insensitive -------------------------
    ASM
    GetAddress macro Label, Wout       ; Returns the Address of a Label as a Word
        CHK?RP Wout
        movlw low Label
        movwf Wout
        movlw High Label
        movwf Wout + 1
        endm
    ENDASM
    I think, once you fix those 2 things, you'll have something that looks just like my Strings prog. See second post.
    <hr>
    I do like this though
    Code:
        @ errorlevel 0,-207 ' avoid anoying MPASM error message 
                            ' -- found label after column 1 --
    Sure makes things look better when you can indent labels.
    <br>
    DT

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yep i understand it... the only thing... HOW TO use DA to send numeric Value, say 13,10 or else 8 bits value with the string???

    I tried the \ option... doesn't seems to work as i want. well i can miss something really stupid/easy... once again.

    BUT it works with dt. BUT i agree with you, i take 2 time the needed space.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    "DA" works fine with anything under 128, so 10,13 isn't a problem.
    Code:
       da  "Danger Will Robinson",13,10,0
    But you're right. Unless you are using an 18F part, if you want 8-bit data, it will take 2x the code space.
    Last edited by Darrel Taylor; - 27th August 2005 at 21:45.
    DT

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm i already tried the above... MIIIIIIIIP doesn't work. GOT YA... for the first time in my life... probably the last too

    We must send a 14 bit pack stuff... as it's suppose to!

    So i just found that
    Code:
    @ da "This is a string....",0x068a,0
    the above will send cr+lf.

    Sounds like
    Code:
    CR con 13
    LF con 10
    CRLF var WORD
    
    CRLF.HighByte=CR
    CRLF=CRLF>>1
    CRLF.LOWBYTE=CRLF.LowByte | LF
    it works... just harder to figure out. BAH could be worst. And BTW, a 18F will be more appropriate for that.

    About the String placement... you're right. As i figure to place all string at the top, it shouldn't be a problem. All the string together. Make it easy if some modification have to be done.
    Last edited by mister_e; - 27th August 2005 at 22:14.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, another solution...
    Code:
    String1 da "My string",13,10,"blah blah",13,10,125,126,127,0
    Just modify a little bit the StringOut Sub
    Code:
    StringOut:  ' Send the string out via Hserout
        Readcode Addr, TwoChars       ' Get the 14 bit packed characters
        Char = TwoChars >> 7          ' Separate first char
        if Char then                  ' Look for Null char, Stop if found
           hserout [Char]             ' Send first char
           endif
    
        Char = TwoChars & $7F         ' Separate second char
        if Char then                  ' Look for Null char, Stop if found
           hserout [Char]             ' Send the second char
           Addr = Addr + 1            ' Point to next two characters
           goto StringOut	          ' Continue with rest of the string
           endif
    return
    that way it works. BUT it don't take all the advantage of the 14 BIT pack stuff. It's just more readable the the previous.
    Last edited by mister_e; - 27th August 2005 at 22:21.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hmmmpf,

    Apparently, none of them are right.

    With mine, it puts 00's in front of each byte (13,10), that will cause the send routine to terminate early.

    With the 0x068a, if there's an ODD number of characters in the string, it will pad the string with a 00, again causing the send routine to terminate early.

    So there doesn't seem to be a way to add CRLF on the end of a string with "DA".

    Your program seems to have an advantage after all. My apologies.
    <br>
    DT

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    How dare you fix my program while I'm still posting that you were right!

    Ha ha, Good job!
    <br>
    DT

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    OK as i will probably never happen again, i'll write the date/month/year in my notebook with the note
    once in my life, i beat Mr Darrel Taylor
    THE Canadian 1
    United State 0
    Just kidding Darrel I learn a lot from all of your previous posts.

    Keep up the good work !!!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Oh shoot,

    Still has that "Padding the string" problem.

    Code:
    010D   26F9 1073 3A72 00255 String1 da "My string",13,10,"blah blah",13,10,125,126,127,0
           34EE 3380 000D
           000A 316C 30E8
           1062 3661 3400
           000D 000A 007D
           007E 007F 0000
    Sendstring still terminates early if the string has an ODD number of charaters.

    Almost there.

    P.S.
    THE Canadian 0.99
    <br>
    Last edited by Darrel Taylor; - 27th August 2005 at 23:02.
    DT

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. Please help with storing strings in codespace
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th May 2008, 02:02

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts