+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Full Member level 5
    Points: 1,942, Level: 10

    Join Date
    Apr 2012
    Location
    bangalore
    Posts
    311
    Helped
    39 / 39
    Points
    1,942
    Level
    10

    how to convert decimal to hexdecimal in assembly

    can anyone help me

    •   Alt13th April 2012, 18:15

      advertising

        
       

  2. #2
    Advanced Member level 4
    Points: 7,982, Level: 21

    Join Date
    Apr 2010
    Posts
    1,207
    Helped
    242 / 242
    Points
    7,982
    Level
    21

    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. #3
    Advanced Member level 5
    Points: 23,580, Level: 37

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    2,803
    Helped
    797 / 797
    Points
    23,580
    Level
    37

    Re: how to convert decimal to hexdecimal in assembly

    Quote Originally Posted by jjeevan007 View Post
    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.



    •   Alt13th April 2012, 23:47

      advertising

        
       

  4. #4
    Full Member level 2
    Points: 716, Level: 5

    Join Date
    Mar 2012
    Posts
    132
    Helped
    20 / 20
    Points
    716
    Level
    5

    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. #5
    Full Member level 5
    Points: 1,942, Level: 10

    Join Date
    Apr 2012
    Location
    bangalore
    Posts
    311
    Helped
    39 / 39
    Points
    1,942
    Level
    10

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

    Quote Originally Posted by srizbf View Post
    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. #6
    Full Member level 3
    Points: 1,389, Level: 8
    Arch Zone's Avatar
    Join Date
    Dec 2011
    Location
    Daerah Khusus Ibukota Jakarta, Indonesia
    Posts
    171
    Helped
    37 / 37
    Points
    1,389
    Level
    8

    Re: how to convert decimal to hexdecimal in assembly

    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


    1 members found this post helpful.

  7. #7
    Full Member level 5
    Points: 1,942, Level: 10

    Join Date
    Apr 2012
    Location
    bangalore
    Posts
    311
    Helped
    39 / 39
    Points
    1,942
    Level
    10

    Re: how to convert decimal to hexdecimal in assembly

    Quote Originally Posted by Arch Zone View Post
    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



+ Post New Thread
Please login

LinkBacks (?)

  1. 10th October 2013, 18:26