I am trying to convert a decimal value to the corresponding BCD code. However, this seems not to be working at all, because only gives the 'tens' part and the 'unit' is lost. Such as, 27 only return 2.I want the result into a 8-bit array (the result will not be greater than 99)...

Not sure I understand the question. Do you mean your decimal interpretation of a value in a register? ie does "15" =0x0F? isn't the example "27" stored internally as 0x1B? if so then what you want is Binary to BCD. Here is my take on using the ADD3 algorithm for converting binary to BCD. I only needed two BCD digits but it can be easily expanded.