# how to convert decimal to hexdecimal in assembly

1. ## how to convert decimal to hexdecimal in assembly

can anyone help me

•

2. ## Re: how to convert decimal to hexdecimal in assembly

write a decimal to binary conversion routine and transform the resultant binary to hexadecimal.
you have not specified it for which controller . remember assembly code differs for each controller

•

3. ## Re: how to convert decimal to hexdecimal in assembly

Originally Posted by jjeevan007
can anyone help me
I think this is what you mean ..

In Pic Assembler you simply tell it what the value is Decimal, Hex, Binary. example :-
movlw d '255'
movlw 0xFF
movlw b'11111111'

If when writing your code you want to use nearly all decimal values , in MPlab for instance ,you can set the default Radix to Decimal so all the complier assumes all values are decimal unless otherwise prefixed.

Its when you come to output the values to say an lcd that you then need some code to convert it to Ascii etc.

•

4. ## Re: how to convert decimal to hexdecimal in assembly

I've done it using a table... It was quite long time ago, I cannot remember exactly how I did, but I think I setup a ROM in assembly which has decimal input and hex output.

5. ## Re: how to convert decimal to hexdecimal in assembly for 8051

Originally Posted by srizbf
write a decimal to binary conversion routine and transform the resultant binary to hexadecimal.
you have not specified it for which controller . remember assembly code differs for each controller
for 8051 controller
eg: the contains of accumulator is 99 then it has to be converted to 63

•

6. ## Re: how to convert decimal to hexdecimal in assembly

Try this (Source and result at accumulator):
[syntax=asm]
Begin:
Mov A,#99h
Acall Con_Dec_2_Hex
Sjmp \$

Con_Dec_2_Hex:
Push Acc
Anl A,#F0h
Swap A
Mov B,#0Ah
Mul AB
Xch A,B
Pop Acc
Anl A,#0Fh
Ret
[/syntax]

1 members found this post helpful.

7. ## Re: how to convert decimal to hexdecimal in assembly

Originally Posted by Arch Zone
Try this (Source and result at accumulator):
[syntax=asm]
Begin:
Mov A,#99h
Acall Con_Dec_2_Hex
Sjmp \$

Con_Dec_2_Hex:
Push Acc
Anl A,#F0h
Swap A
Mov B,#0Ah
Mul AB
Xch A,B
Pop Acc
Anl A,#0Fh