6. Program to convert a decimal number to hex number :

mov dptr,#9000h ; Load 9000h into dptr register
movx a,@dptr ; move data from external memory location to a
mov r2,a ;move data from r2 to a
clr c ;clear carry bit
subb a,#0ah ;subtract with borrow, 0ah from a
jc over ;if carry, jump to label over
mov a,r2 ;move data from r2 to a
anl a,#0f0h ;and a with 0f0h
swap a ;swap a
mov b,#0ah ;move 0ah to b
mul ab ;multiply and b
mov r3,a ;move data from a to r3
mov a,r2 ;move data from r2 to a
anl a,#0fh ;move 0fh to a
add a,r3 ;add a and r3
inc dptr ;increment dptr
movx @dptr,a ; move data from a to external memory location
sjmp here
over:mov a,r2 ;move data from r2 to a
inc dptr ;increment dptr
movx @dptr,a ;move data from a to external memory location
here:sjmp here
end
Input:99
Output:63

Web Statistics