Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

hex code to c code

madhunmadhun Member Posts: 2
Dear All

Is it poosible to convert hex 8051 compiled code back to C code.
Any tool available or any trcick to implement that.
Looking for you help. Thanks in advance.
Thanks
Madhu

Comments

  • LundinLundin Member Posts: 3,711
    : Dear All
    :
    : Is it poosible to convert hex 8051 compiled code back to C code.
    : Any tool available or any trcick to implement that.
    : Looking for you help. Thanks in advance.
    : Thanks
    : Madhu
    :


    That is impossible, but it could be converted to assembler.
    I don't know about any tools for it though.
  • pintuz_4_upintuz_4_u Member Posts: 7
    : Dear All
    :
    : Is it poosible to convert hex 8051 compiled code back to C code.
    : Any tool available or any trcick to implement that.
    : Looking for you help. Thanks in advance.
    : Thanks
    : Madhu
    :

    Hi,

    I am providing a manual method for finding assembly code from hex code, may it help you out.


    Suppose this is our assembly code:

    org 2014h
    db 025h,0DAh

    org 2B20h
    btjo #40h,0B5h,2B2Bh
    mov #03h,0B8h
    clr 0B5h
    clr 08h
    br 3C18h

    org 3BD7h
    br 2B20h

    and here is what it look like disassembled from the hex file:

    2014: 25DA

    2B20: 7640B507 btjo #40h,0B5h,2B2Bh
    2B24: 7203B8 mov #03h,0B8h
    2B27: D5B5 clr 0B5h
    2B29: D508 clr 08h

    2B2B: 8C3C18 br 3C18h
    3BD7: 8C2B20 br 2B20h

    Lets take the first line

    2014: 25DA

    Starting address = 2014h
    To state starting addresses in ASM format you will use org so for the first line in a new notepad (or whatever text editor that you use) it will look like this:

    org 2014h

    org = Starting address that the bytes to follow will be written to

    2014h = The address to start writing those bytes to

    now for the bytes

    the bytes that we are going to be writing to address 2014 do not
    disassemble because they belong to the FUSE BYTES so they are called

    DATA Bytes which are done in ASM like this:

    db 025h,0DAh

    So now you first two lines should look like this:

    org 2014h
    db 025h,0DAh

    Remember to only use the ORG when addresses are NOT concurrent (meaning that no addresses are skipped)

    Lets move onto the next section of the ASM

    2B20: 7640B507 btjo #40h,0B5h,2B2Bh
    2B24: 7203B8 mov #03h,0B8h
    2B27: D5B5 clr 0B5h
    2B29: D508 clr 08h
    2B2B: 8C3C18 br 3C18h

    Now these addresses are all concurrent which means that no addresses

    are skipped in this section which means that you will only need 1 org for this section

    Only use an org if addresses are skipped

    The starting address is 2B20h so put a blank line under the db 025h,0DAh

    (because it makes it easier to read then and makes it neater) then put:

    org 2B20h

    now the next line, we need to strip out everything that is NOT needed in the ASM file

    2B20: 7640B507 btjo #40h,0B5h,2B2Bh

    we already did the org for address 2B20h so the address is NOT needed
    which leaves us with this:

    7640B507 btjo #40h,0B5h,2B2Bh

    the hex values at the beginning are not needed because HUASM will fill
    those in for us which leaves us with this:

    btjo #40h,0B5h,2B2Bh

    which IS what HUASM needs to assemble that line properly so put that on
    the line under the org 2B20h

    Next line

    2B24: 7203B8 mov #03h,0B8h

    the address is concurrent with the one before it and no address is skipped (left blank) so we can delete that and the HEX values that are right after it which leaves us with this:

    mov #03h,0B8h

    so put that on the next line

    Lets move onto the next line now

    2B27: D5B5 clr 0B5h

    again. delete the address and the hex value right behind the address since they are NOT needed which leaves us with this:

    clr 0B5h

    put that on the next line

    2B29: D508 clr 08h <--now do the same for this line
    2B2B: 8C3C18 br 3C18h <--and do the same for this line also

    which leaves us with this left to do:

    3BD7: 8C2B20 br 2B20h

    which is not concurrent with the last address that was used (2B2Bh), so we will need to put a blank line and another org for it so put in a blank line and

    then put this in your text file

    org 3BD7h

    and you should know what to do with the rest of the line by now

    br 2B20h

    Now that we have a good ASM file (if you followed instructions that is), now you want to save that text file as Class7.asm

    NOTE: Notepad users will have to select ALL file types and then make the filename "Class7.asm" (with the quotes) in order for it to save as an asm file now your ASM FILE should look like this:

    org 2014h
    db 025h,0DAh

    org 2B20h
    btjo #40h,0B5h,2B2Bh
    mov #03h,0B8h
    clr 0B5h
    clr 08h
    br 3C18h

    org 3BD7h
    br 2B20h



    Regards,
    Saroj Kumar

Sign In or Register to comment.