Anda di halaman 1dari 1

8-bit HEX to BCD convertor Code Library - 8051 Assembly Share inShare Download SocButtons This subroutine converts

8 bit Hexadecimal number into its equivalent BCD value. The number to be converted should be in the Accumulator. The output BCD number is stored in R0 & R1. R0 is used to save the MSB i.e. the hundreds place & R1 stores the LSB i.e. the Tens & Units place. hextobcd: mov r0,#00h mov r1,#00h cjne a,#00h,c1_hextobcd ret c1_hextobcd: clr c mov b,#100 div ab mov r0,a clr c mov a,b mov b,#10 div ab swap a mov r1,a mov a,b orl a,r1 mov r1,a ret // save the tens place in the Lower nibble of R1

//If number is not 0 then continue

//First divide by 100 //save MSB in R0

//Divide by 10

//save the tens place in the Higher nibble of R1

Anda mungkin juga menyukai