convert hex to assembly code

Go To Last Post
67 posts / 0 new

Pages

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

Maybe get some pills to get over your allergy for C and then realize C is nothing but glorified (abstracted?) assembler which also happens to be cross platform.

Trying to learn assembly from a 10 year old hex file of unknown origin is well, very backward.

In many situations especially on a small micro as the tiny13 C is very inefficient compared to C.   

I do know that there are many small examples where C is close, but with a micro with only 500 instructions C is clumsy.

And for many of those that get C close it's only because they know ASM to begin with.   

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

In the late 1960s I managed a computer controlled jet engine test stand project. The company was large enough that there were separate divisions for hardware and software development.  Both divisions were under the impression that they made the system and the other only provided support.  The task of getting both of them to talk to the other made me realize that I knew enough to be dangerous.  The one thing that I did learn was compilers produce workable executables BUT not the fastest or the smallest file sizes.  When the people that really had a handle on the instruction set could clean up the compiler generated executables by using assembly that was a valuable lesson.

 

I have to assume the same is true for the compiler I use for the AVRs.  My interest in assembly coding is one of our projects uses a tiny25 but the executable would run in a tiny23 if around 2% smaller.  In addition our product is battery powered so there is a small improvement in battery life with a tiny13.  So for 2% more room the cost of the micro is more that 50% higher.  If you are competing with the offshore manufacturers you must cut costs were ever possible.

 

Having said that; this may be a useless effort but no one can be sure of that if it’s not tried.  The other factor is doing something others say can’t be done.  If that can be accomplished it may be worth more than the cost savings.  Besides that it keeps me out of the bars and off the streets!!!

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

Which BASIC compiler are you talking about? 

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

 

Being an old FORTRAN user I selected BASCOM-AVR because of the similar syntax and listing structure.  It looks like I should proof my posts,  the goal is to shrink the need for memory to fit a tiny13, it runs fine in a tiny25....

Last Edited: Sun. Oct 2, 2016 - 07:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I doubt Bascom is THAT inefficient to be able to half a code size. BASIC and C are not perfect but it'd be pretty unusual to be able to shave much more than 10..25%

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

 

It looks to me like it's only around 2%, only time will tell....

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

Which C compiler do you talk about? , for me this sound as nonsense.

 

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

If your comment is directed to me all I can say is it may be nonsense.  If it is it is just a repeat of other nonsense and that will be a lesson learned...
 

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

What is it you want to improve? (save 5% in size and same speed or ?)

 

Depending of the problem you solve the amount of RAM easy could be a bigger problem than flash size.

 

Hints to good ASM on a tiny13.

Don't use STS and LDS, but set Y to point to start of RAM, and then you can reach all RAM with instructions of 1/2 the size (LDD and STD). (and that way YH become your zero reg)

If you have 16 bit things that needs to be atomic store them in registers and use movw, that way they gets atomic by nature.

Have a good plan of the use of all the registers, and RAM , and if you don't use all the EEPROM perhaps put a small lookup table there.

add

and for thing where you need pointers try to keep them i 1 page, so they can be handled as 8 bit.

Last Edited: Sun. Oct 2, 2016 - 09:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No it was to #50 (look at the reply number)

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

I thought you were talking about fitting the code of a 2K micro into a 1K micro.  If all you are saying is that in the 2K micro you are only using 1K+2% and need to shave off that 2% to make it fit in a 1K micro then why do you even need to mess with disassembly,  hand optimisation and reassembly? Surely there must be at least one statement in your BASIC code that can just be rearranged or something to get back 2%?

 

2% of 1K is just 21 bytes!! 

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

You make my point, I've tried playing around with the instructions and made a slight improvement but that is like pushing a train with a wet noodle.  As for the speed it's not important in fact even the 128KHz clock is faster than necessary in this application, the goal is to reduce the memory space required.  While I realize this may be a waste of time if I can't knock off the 2, maybe 3% I will learn what I can't do.  One thing I know for sure is if I don't try it will not ever know if it would.

 

All of this still misses the initial question, i.e., is there a way to convert the hex file to assembly? 

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

If I find a way to go from HEX to ASM I'll take this as good advice....

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

If I find a way to go from HEX to ASM

What happens if you just open the hex file in Studio? You can open a hex file in AS4 (don't know about AS7) for debugging and it would generate an "asm" file.

 

This is what a get from a hex file for one of my test DS1307 project, and it's about as good as it gets. Compare it to what the original file contains.

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Mon. Oct 3, 2016 - 01:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

charger wrote:

All of this still misses the initial question, i.e., is there a way to convert the hex file to assembly? 

 

Yes, there is. Often this is called DisAssembly. Most debuggers include a DisAssembly pane, which often has a little more smarts than plain-DisAsm, and will include Symbol names.

The examples in #65 show what you can expect from such a DisAsm step.

There are no names, so all information is in Hex.

You can make a smarter DisAsm, that tries to build Data space equates, and use those names in the Assembler, but you still need to manually add the better names.

 

A smarter way to learn ASM, is to look at the Assembler output from your compilers, and find ways to pack that smaller...

Often, you can recode things, to better pack the code, and often avoid certain designs.

 

charger wrote:
the goal is to shrink the need for memory to fit a tiny13, it runs fine in a tiny25....

Why bother ? Will you be making 100,000+ of these ?

If price really dominates, you probably would choose a MCU other than an AVR anyway.

Just go to Digikey, and sort 8 bit MCU by CodeSize and Price...

 

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

charger wrote:
If I find a way to go from HEX to ASM I'll take this as good advice....
I guess you did not read #43 then? As I say avr-objdump will give you a disassembly. True it is annotated with opcode addresses and opcode bytes but any editor with "column delete" can quickly remove those.

 

To be honest though, for 1K (+21 bytes) of code I would just take whatever algorithm you are implementing and recode it in plain Asm from scratch. You can't be doing much in 1K that is so complex that it is not easy to just rewrite as Asm. It will give you a "cleaner" solution than HLL->DisAsm->edit->Asm.

 

EDIT: having said that, unless it is uber secret, just attach the .hex file that comes out of your Basic compiler to a post here and I'm pretty sure one of us could quickly produce a slimmed and trimmed Asm source from it.

 

PPS: oh and the BASIC source if that is not too secret - it'll make it easier to follow what's going on in the Asm that way.

Last Edited: Mon. Oct 3, 2016 - 08:51 AM

Pages