3: ASCII to BCD conversion:

To convert ASCII to packed BCD, it is first converted to unpacked BCD(to mask 3) and
then combined to make packed BCD. For example, for 4 and 5 the keyboard gives 34 and
35, respectively. The goal is to produce 45h, which is packed BCD.
;ASCII to packed BCD conversion

mov r0,#10h ;R0=10h,Internal memory adress
mov a,@r0 ;a=hex value of Ist ASCII number
anl a,#0fh ;mask upper nibble
swap a ;swap upper and lower nibble of a
mov b,a ;save the number in B
inc r0 ;Increment R0
mov a,@r0 ;Get the next number from memory
anl a,#0fh ;Mask Higher nibble
orl a,b ;Or a & B
inc r0 ;Increment memory address to store the result
mov @r0,a ;Move the content of A to internal RAM location
here:sjmp here
end


Web Statistics