yeah, I already changed my implementation above.

Not proficient in PIC assembler, but this is his algorithm for an x86, the compiler doesn't even get close to this optimization.

` unsigned char in_val = 255;`

char digits[3];

digits[0] = digits[1] = digits [2] = '0';

_asm {

mov bl,in_val

loop_100:

cmp bl,100

jb exit_loop_100

inc digits[2]

sub bl,100

jmp loop_100

exit_loop_100:

loop_10:

cmp bl,10

jb exit_loop_10

inc digits[1]

sub bl,10

jmp loop_10

exit_loop_10:

add digits[0],bl

}

// similar code in C

in_val = 255;

digits[0] = digits[1] = digits [2] = '0';

while (in_val > 99) {

digits[2]++;

in_val -= 100;

}

while (in_val > 9) {

digits[1]++;

in_val -= 10;

}

digits[0] += in_val;

Less instructions than my more general BCD algorithm that I posted earlier converted to assembler and without assigning the actual digits.

` unsigned char in_val = 255;`

unsigned short accumulator=0;

unsigned short count=8;

char digits[3];

_asm {

mov cx,count

mov ax,accumulator

mov bl,in_val

begin_loop:

shl ax,1

mov bh,bl

and bh,80h

je skip_inc

inc ax

skip_inc:

cmp cx,1

je end_loop

mov bh,al

and bh,0fh

cmp bh,04h

jbe skip_plus0x03

add al,3

skip_plus0x03:

mov bh,al

and bh,0f0h

cmp bh,40h

jbe skip_plus0x30

add al,30h

skip_plus0x30:

shl bl,1

dec cx

jne begin_loop

end_loop:

mov accumulator,ax

}