Shop OBEX P1 Docs P2 Docs Learn Events
SX/B routine to convert WORD value to ASCII — Parallax Forums

SX/B routine to convert WORD value to ASCII

BeanBean Posts: 8,129
edited 2008-03-19 23:05 in General Discussion
I was working on a STR routine that converts a word value to ASCII for inclusion in the SX/B compiler.

Here is what I came up with. The routine had to be small and relatively fast, I think this one fits the bill nicely.

You specify an array address that will hold the ascii characters, then a word variable, then a character to use for leading zeros (most often a space or a zero).

There has been other routines posted to do this, but I think this one is more flexible (by allowing user specified leading zero character), smaller and faster.

Let me know what you think.

Bean.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com

Comments

  • dkemppaidkemppai Posts: 315
    edited 2008-03-19 19:55
    Bean (Hitt Consulting) said...
    I was working on a STR routine that converts a word value to ASCII for inclusion in the SX/B compiler.

    Here is what I came up with. The routine had to be small and relatively fast, I think this one fits the bill nicely.

    You specify an array address that will hold the ascii characters, then a word variable, then a character to use for leading zeros (most often a space or a zero).

    There has been other routines posted to do this, but I think this one is more flexible (by allowing user specified leading zero character), smaller and faster.

    Let me know what you think.

    Bean.
    ·
    Do you happen to have an ASM version of this cleaned up???·

    -Dan


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    "A saint-like quantity of patience is a help, if this is unavailable, a salty vocabulary works nearly as well." - A. S. Weaver
  • BeanBean Posts: 8,129
    edited 2008-03-19 20:22
    Dan,
    · It is in assembly ??? What do you mean by "cleaned up" ???

    · SX/B will automatically load __PARAM1 with the address of the array, __PARAM2 will hold the LSB of the word variable, __PARAM3 will hold the MSB of the word variable, and __PARAM4 will hold the leading zero character.

    · Note that __PARAM1 thru __PARAM5 must be in the global area (as is always the case in SX/B).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-03-19 20:45
    Hello Bean,

    This is excellent! A friend of mine is waiting on his SX development kit and one of the first programs he was going to work on needs to use a routine like this. I'm going to help him get started with the SX chips and this routine will certainly save some time.

    Does this mean you're getting another release of SX/B ready? If so i'd be willing to test it. I've also got some notes about the SX48 timers which could help a lot if added to the help file for SX/B.

    Best Regards,

    Robert
  • dkemppaidkemppai Posts: 315
    edited 2008-03-19 23:05
    Bean (Hitt Consulting) said...
    Dan,
    · It is in assembly ??? What do you mean by "cleaned up" ???

    · SX/B will automatically load __PARAM1 with the address of the array, __PARAM2 will hold the LSB of the word variable, __PARAM3 will hold the MSB of the word variable, and __PARAM4 will hold the leading zero character.

    · Note that __PARAM1 thru __PARAM5 must be in the global area (as is always the case in SX/B).

    Bean.

    I just assumed the code was SX-B (I don't read SX-B yet [noparse];)[/noparse]·· I'll look at a little closer when I get a chance, but from what you say, it sound good.
    (I've been a little busy testing a SX-Key debug issue [noparse];)[/noparse]

    -Dan


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    "A saint-like quantity of patience is a help, if this is unavailable, a salty vocabulary works nearly as well." - A. S. Weaver
Sign In or Register to comment.