Is there a way to regenerate C/Assembly code from hex file using AVR studio.

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Folks,

               I am newbie to micro controller programming.

               I didn't have source code for a project but I do have a hex file.

               Is there anyway to regenerate a C/assembly code from hex file using AVR studio.

               Please assist me.

 

 

Thanks,

senthil Kumar M

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

C no,  Asm sort of. If you run the code in a debugger using the hex file as input then you can see assembler code but not necessarily understandable or easily reassembled.
 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regenerated assembly language code, as said above, can be done but that code will be illegible as it will be missing meaningful function and variable names and the author's code comments.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Disassemblers can also be tripped-up by data in the Hex file.

 

For all these reasons, using a disassembler is a skilled task - not for a newbie.

 

If you are a newbie, you should be starting by learning the basics:

 

https://www.avrfreaks.net/comment...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And to add. If it was C not Asm the source will not appear "logical". Optimising compilers even do things like splitting single statements into 2 or 3 seemingly disconnected bursts of Asm simply because it suits them to do things in a different order to what you have written. Also you will see a lot of stack frame variable creation and destruction which (at least to an Asm programmer) will look very odd and pointless indeed.

 

Usually it is simply easier (for small micro code anyway) to just study the complete job the existing code is doing (like PortC bit 5 goes high 13 microseconds afer PORTB pin 3 is taken low or whatever) and just re-cde this from scratch. Much simpler/easier.

 

Also a lot of people who "just have a .hex file" have extracted it from some AVR not knowing that the lockbits were set. It may appear to be a valid AVR program but if you study it you find that it's just meaningless data bytes (because that's what lockbits do). Is, for example, the very first byte 0x0C (as it is on a large majority of AVR programs)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Thanks Everyone for your valuable comments and suggestion.