Double Precision Binary-to-BCD: ALTS/D thoughts
tomcrawford
Posts: 1,126
in Propeller 2
I adapted a DP Bin2BCD routine for Prop2. The routine repeatedly subtracts double precision powers of 10, beginning with 10E19.
The change from the Prop1 method is that it uses Register Indirection. Here it is.
The prop1 method used self-modifying code to directly point into the table of powers of ten; this uses register indirection.
The nice news is no more self-modifying code; the not-so-nice news is that the inside loop goes from three instructions to five (beginning at B2BL2).
You pays your money, you takes your choice.
I was gonna get all philosophical here about whether avoiding self-modifying code is A Good Thing, but won't.
The change from the Prop1 method is that it uses Register Indirection. Here it is.
Bin2BCD mov x, #0 'clear index regs (goes by 1) mov y, #0 'goes by 2 mov temp, #20 'will do 20 digits B2BL1 mov count, #0 'used to count subtracts B2BL2 alts y, #E19+1 'index into DP 10**X table sub BinLo, 0 wc 'subtract lo order alts y, #E19 subx BinHi, 0 wc 'subtract hi order if_NC djnz count, #B2BL2 'still positive, adjust count altd x, #tens abs 0, count 'save result alts y, #E19+1 add BinLo, 0 wc 'restoring add alts y, #E19 addx BinHi, 0 add x, #1 'adjust indexes add y, #2 djnz temp, #B2BL1 'do next power of temp Bin2BCD_ret ret 'all done
The prop1 method used self-modifying code to directly point into the table of powers of ten; this uses register indirection.
The nice news is no more self-modifying code; the not-so-nice news is that the inside loop goes from three instructions to five (beginning at B2BL2).
You pays your money, you takes your choice.
I was gonna get all philosophical here about whether avoiding self-modifying code is A Good Thing, but won't.
Comments
Basically alts, altd, alti are self-modifying code like we used on the P1, just without the hassle of counting instructions in between modifying and using.
I am slowly diving into PASM2 and like it a lot, already...
Mike
Code is quite compact too.