Shop OBEX P1 Docs P2 Docs Learn Events
word comparing — Parallax Forums

word comparing

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2006-08-18 20:46 in General Discussion
Hi,
I made a little test program to compare two 16bit values
and set a true/false result based on the values and
the test to perform (=,<,<=,>,>=,<>)
I would like to know if anybody knows of a faster way (smaller code)
or wether my method can be optimized.

regards peter

Post Edited (Peter Verkaik) : 8/18/2006 11:18:04 AM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2006-08-18 11:39
    Peter,
    · I don't know what you're up to, but it looks very interesting...

    · I made a couple little changes. If your interested.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-18 12:35
    Thanks Bean.
    The ramX.15<>ramY.15 takes two more codebytes than the xor method.
    For the result, result equals the inverted Z flag (if Z set, result = false)
    so I changed that. Saved a few bytes compared to if else.

    I also added a asm method which I think is correct. That requires less than 32 codebytes.

    The goal is to use this in an expression parser where an expression yields true or false.

    regards peter
  • BeanBean Posts: 8,129
    edited 2006-08-18 14:25
    Peter,
    The assembly code look about as tight as possible. I can't see anything obvious to improve it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-18 16:12
    Thanks Bean for checking it.
    I found a small error, the clr statement affects the Z flag so I had
    to make a little change.

    regards peter
  • BeanBean Posts: 8,129
    edited 2006-08-18 17:25
    Hmm, I wouldn't have thought that CLR would affect the Z flag. I guess it does.

    Strange that MOV W,#0 doesn't affect Z though...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • James NewtonJames Newton Posts: 329
    edited 2006-08-18 18:55
    I believe you are duplicating the effort I put forth years ago at sxlist.com

    http://www.sxlist.com/techref/ubicom/lib/flow/compcon_sx.htm

    Or did I miss something on that page?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    James Newton, Host of SXList.com
    james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
    SX FAQ / Code / Tutorials / Documentation:
    http://www.sxlist.com Pick faster!



  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-18 19:04
    Hi James,
    I got the getUnsignedCompareFlags routine from exactly that page,
    only my routine then returns flags for all comparison values.
    Then I make a difference between signed and unsigned compare.
    I believe the asm routine is correct now.
    Please feel free to add it to your page as an example for signed compare.

    regards peter
  • James NewtonJames Newton Posts: 329
    edited 2006-08-18 19:29
    Ahh, yes, I missed that it was signed... Excellent! I'll add that to the page.

    Now, does SX/B not already mange 16 bit comparisons?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    James Newton, Host of SXList.com
    james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
    SX FAQ / Code / Tutorials / Documentation:
    http://www.sxlist.com Pick faster!



  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-18 19:50
    Yes, but that is only unsigned.
    That's why I had the sxbasic routine first.
    The sxbasic and the asm perform the same task.

    regards peter
  • BeanBean Posts: 8,129
    edited 2006-08-18 20:46
    James,
    Yes the current version supports word (16-bit) unsigned variables. They are pretty well incorporated in the compiler.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
Sign In or Register to comment.