[SOLVED] how to convert decimal to hexdecimal in assembly

Status
Not open for further replies.
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
 

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.
 

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.
 

Re: how to convert decimal to hexdecimal in assembly for 8051

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
 

Try this (Source and result at accumulator):

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
    Add A,B
    Ret

 

thank you very much
it was help full
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…