E556GB — 6.16.4 Binary-to-BCD converter, 16 bit

Examples Program CLR BM00.02 ;set to zero CLR BM00.03 ;“ THOU1 LD BM00.00 ;load binary value CMPD 1000 JP THOU2 ;smaller than one-thousand ? SUBD 1000 ;if yes: subtract 1000 =D BM00.00 INC BM00.03 ;count subtraction steps JP THOU1 ;check again THOU2 L BM00.03 ;if not: shift thousands LSL ;to the upper LSL ;nibble of the LSL ;BCD output’s LSL ;high byte = BM00.03 ;prepare high byte HUND LD BM00.00 ;remaining binary value (no thousands) CMPD 100 JP TEN1 ;smaller than one-hundred? SUBD 100 ; if yes: subtract 100 =D BM00.00 INC BM00.03 ;count subtraction steps (in lower ;nibble of BCD output’s high byte) JP HUND ;check again TEN1 L BM00.00 ;rem.

binary value (no hundreds either) V 10 JP TEN2 ;smaller than ten ? SUB 10 ;if yes: subtract 10 = BM00.00 INC BM00.02 ;count subtraction steps JP TEN1 ;check again TEN2 L BM00.02 ;if not: shift tens LSL ;into the upper LSL ;nibble of the LSL ;BCD output’s LSL ;low byte ADD BM00.00 ;remaining ones into lower nibble = BM00.02 ;output low byte 145