hex_to_bcd: pla #1 ; Get argument. div #10 ; Divide A by 10. lsl #4 ; Shift the result left by 4 bits. oab ; Or the result, with the remainder. pha #1 ; Push the packed BCD result to the stack. rts ; Return the result.