While we're on the subject of optimization...


Closed Thread
Results 1 to 32 of 32

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    16F or 18F ?
    <br>
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    16F or 18F ?
    <br>
    18F4620...
    Trying some asm at the moment...but I still know there's something easier and yet more compact than what I've got... just... what... is... it...
    Spock...help... me ... here...

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


    Did you find this post helpful? Yes | No

    Default

    Here's a slight modification of the old Embedded String thread...
    Code:
    lcdpx VAR byte
    lcdpy VAR BYTE
    Addr  VAR WORD
    
    ASM
    PrintStr macro x, y, Str
        local TheString, OverStr
        goto OverStr
    TheString
        data  Str, 0
    OverStr
        MOVE?CB  x, _lcdpx
        MOVE?CB  y, _lcdpy
        MOVE?CW  TheString, _Addr
        L?CALL   _StringOut
        endm
    ENDASM
    
    Char  VAR lcdchardata[0]
    StringOut:
        Readcode Addr, Char           ' Get a character
        if Char = 0 then StringDone   ' Look for Null char, Stop if found
        gosub puttext
        Addr = Addr + 1               ' Point to next character
        lcdpx = lcdpx + 1
        goto StringOut                ' Continue with rest of the string
      StringDone:
    return
    ;-----------------------------------------------------------------------------
    Then you can do this...
    Code:
    @  PrintStr  0,0, "RESET ELM327..."
    @  PrintStr  0,1, "Hello World!"
    HTH,
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Here's a slight modification of the old Embedded String thread...
    Code:
    lcdpx VAR byte
    lcdpy VAR BYTE
    Addr  VAR WORD
    
    ASM
    PrintStr macro x, y, Str
        local TheString, OverStr
        goto OverStr
    TheString
        data  Str, 0
    OverStr
        MOVE?CB  x, _lcdpx
        MOVE?CB  y, _lcdpy
        MOVE?CW  TheString, _Addr
        L?CALL   _StringOut
        endm
    ENDASM
    
    Char  VAR lcdchardata[0]
    StringOut:
        Readcode Addr, Char           ' Get a character
        if Char = 0 then StringDone   ' Look for Null char, Stop if found
        gosub puttext
        Addr = Addr + 1               ' Point to next character
        lcdpx = lcdpx + 1
        goto StringOut                ' Continue with rest of the string
      StringDone:
    return
    ;-----------------------------------------------------------------------------
    Then you can do this...
    Code:
    @  PrintStr  0,0, "RESET ELM327..."
    @  PrintStr  0,1, "Hello World!"
    HTH,
    Actually, I just found what I was looking for a couple of minutes ago...and I think I'll kick myself now... how about a little LOOKUP !
    But....I think I like your solution much better...
    As soon as I figure out why my '4620 started double-resetting itself and locking up on initial powerup (without changing the code!!! left the room, came back, sat down, did a verify and it started!), I'll give it a whirl and see what happens. I see nothing but good stuff ('cept for that resetting bit. time to throw another chip I think).

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


    Did you find this post helpful? Yes | No

    Default

    Storing it as data in program memory uses about 1/4th the code space compared to LOOKUP.

    If you'll have a lot of strings to display, it could save a big chunk of space.
    Not that you need to worry about it with the 4620. (64kb)
    <br>
    DT

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Storing it as data in program memory uses about 1/4th the code space compared to LOOKUP.

    If you'll have a lot of strings to display, it could save a big chunk of space.
    Not that you need to worry about it with the 4620. (64kb)
    <br>
    I just converted a few of my strings over to your format....
    And after fighting with it for about an hour, I figured out that the thing is case sensitive...jeeze...what next...
    I'm up to 40K used out of 64K on the '4620, might have to go to a 4685 (or maybe even an '8722 with my little 40 pin adapter I built awhile back). Hopefully this little routine helps me save a LOAD of space. I'm not even halfway done with my program yet.

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


    Did you find this post helpful? Yes | No

    Default

    Well, using an external EEPROM have it's advantages as well. If you Strings are LCD dedicated, you can also format them the right way in a HEX Editor.

    I use bpsoft Hex WorkShop.
    Steve

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

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Storing it as data in program memory uses about 1/4th the code space compared to LOOKUP.

    If you'll have a lot of strings to display, it could save a big chunk of space.
    Not that you need to worry about it with the 4620. (64kb)
    <br>
    Kudos to you and all that. I just went thru and converted all of my major string routines to your embedded routine example.
    So far, I've saved 7,486 in code space (started with $9C22, now I'm only using $7EE4 of space).
    And I've still got to optimize the rest of the code...

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


    Did you find this post helpful? Yes | No

    Default

    Sweet!

    Let me know how it is after optimizing the rest. Just for curiosity sake.
    <br>
    DT

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Not quite optimization...or is it?

    Got a modification of the PRINTSTR macro for my nokia lcd...
    Code:
    ASM
    PrintStr macro x, y, Str
        local TheString, OverStr
        goto OverStr
    TheString
        data  Str, 0
    OverStr
        MOVE?CB  x, _lcdpx
        MOVE?CB  y, _lcdpy
        MOVE?CW  TheString, _Addr
        L?CALL   _StringOut
        endm
    ENDASM
    StringOut:
        Readcode Addr, Char : if Char = 0 then StringDone   ' Look for Null char, Stop if found
        gosub puttext : Addr = Addr + 1 : lcdpx = lcdpx + 1 : goto StringOut
    StringDone: return
    Is there a conditional directive that'll "overload" (I suppose like C++) the PRINTSTR macro to either accept or ignore 2 extra parameters?
    In my case, I want to add foreground color and background color, but not neccessarily one or both at the same time...like this
    Code:
    PrintStr macro x, y, Str , forecolor , backcolor
    If both are there, great, process them as normal.
    If the background color value isn't there, ignore it and don't change it.
    If the foreground color value isn't there, ignore both of them and don't change either.
    Sure, it's easy enough to make 3 different versions of the same thing, and use 3 different names, i.e. printstr, printstrf (set foreground only ), printstrfb (set both foreground/background), printstrb (set background only).
    If I assumed null-zero's would work, that would be fine except that I'm dealing with 8 bits of color (soon to be 16) and a zero-null is a valid color.

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


    Did you find this post helpful? Yes | No

    Default

    Well, as far as i'm aware of, MPASM don't provide any features like that. If you don't fill all arguments, it will prompt you. That's one downside.

    So you'll probably need to build some different version of you macro, one calling the other or variant of.
    Steve

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

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Well, as far as i'm aware of, MPASM don't provide any features like that. If you don't fill all arguments, it will prompt you. That's one downside.
    It'll prompt me all-right...prompt me with an error message!

    So you'll probably need to build some different version of you macro, one calling the other or variant of.
    I've been pouring over the MPASM documentation looking for some insight into 'overloading' macros like I want to do and not finding anything interesting. I guess it's back to multiple versions of the same thing, but different. It's either that or I'm going to try a version with a 'mode number' in the front, sort like that multiple LCD mod on another thread...
    @ printstr 1 , 5 , 5 , "works here" - mode 1 - no color modify
    @ printstr 2 , 5 , 5 , 1 , "works here" - mode 2 - foreground color change...
    ...and so on...
    Let the code in the macro do the choosing based on the mode number.
    But if I go that way, I may as well have different versions.
    More thought required...

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


    Did you find this post helpful? Yes | No

    Default

    That's one of only 2 circumstances in which I would prefer PM.EXE

    With PM, you are not limited to a specific number of parameters supplied to a macro.

    If paramaters are ommited, they show up as "undefined".
    Then you can just do a IFNDEF to see if a parameter was included or not.

    The second circumstance is IRPC, which can split up each character of a string and repeat the macro for each one.

    However, since PM can't "Nest" macro's. It doesn't help a bit.
    Not to mention the 18F problem.

    And like you've both already pointed out...
    MPASM can't do either one of them.
    <br>
    DT

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. code size VS speed optimization setting?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2008, 14:38
  3. Multiple if then optimization
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 5th March 2008, 12:15
  4. Replies: 2
    Last Post: - 1st May 2006, 13:45

Members who have read this thread : 0

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