cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S

debruyne.marc
Associate II
Posted on October 22, 2012 at 12:14

hello,

please is there a sort of stm8s assembly language available who convert a 16 bit binary  to 5 bcd  code

many thanks

marc debruyne
3 REPLIES 3
fggnrc2
Associate II
Posted on October 22, 2012 at 14:24

Marc,

here is the code I use to compute the ASCII representation of an unsigned 16 bit quantity:

.PrintU16

        PUSHW   X

        LDW     Y,#10000

        DIVW    X,Y

        LD      A,XL

        ADD     A,#'0'

        LDW     X,Y

        LDW     Y,#1000

        DIVW    X,Y

        SWAPW   X

        LDW     (1,SP),X

        LDW     X,Y

        LDW     Y,#100

        DIVW    X,Y

        ADDW    X,(1,SP)

        ADDW    X,#'00'

        LDW     (1,SP),X

        LDW     X,Y

        LDW     Y,#10

        DIVW    X,Y

        PUSH    A

        LD      A,XL

        LD      YH,A

        POP     A

        ADDW    Y,#'00'

        POPW    X

        RET

The caller must store in the X register the quantity to convert, while on exit the registers {A,X,Y} contain its ASCII representation.

I hope you'll find it useful.

Regards

EtaPhi

klaasdc
Associate II
Posted on October 22, 2012 at 14:42

No asm, but I have a double dabble C implementation here

https://sites.google.com/site/klaasdc/stm8s-projects/16bit-to-bcd-conversion

It can probably be done better, but it's what I needed at the time. Maybe it's useful for you.

debruyne.marc
Associate II
Posted on October 22, 2012 at 21:19

hello sir,

many thanks, i have just try the program and its working very well;

i must you wish ,youre a clever man.

i could not find it, have search a lot, and tryed to convert from different processors, but with no result.so i have tryed the last chance to come to this forum.

congratulations