See the AVR assembly output from the IDE

I would like to see the actual assembly output from a sketch that is compiled. I would like to see the memory address of the opcodes, operands, etc.

Can this be done in the IDE? Is there some setting I can change so I not only have my compiled sketch, but readable assembly output as well.

Thanks.

I found the .hex files Is there any way to "translate" the .hex files into ASM?

I would live to resolve the .hex into

0000 LDI R16, 66
0001 MOV R24, R16

and so on where "0000" and "0001" on the left side are the actual memory address in SRAM / Flash

Thank you

Google "avr-objdump"

Nick Gammon used to do that frequently and post it here, but not in a while.

I did and I tried to get it to work... it says file format ihex I can't find anything to get beyond it :frowning:

Please note I am still a beginner so a lot of this is Greek to me.

I also have an ".elf" file: would that be a better route to take? I don't have a preference as long as i get the ASM with the memory locations

Thanks you!

I don't speak Greek either, so you're going to have to explain what you did and the exact messages you got.

So here is a random snippet of what the .hex files looks like. This is not the whole lenthy file, just a sample of what the .hex file looks like. There is also a "with boot loader" .hex file as well.

It appears to be a simple TXT file. I just want to input this to a black box and get assembler out.

Any / all help is appreciated!!

:1002000005B904E005B900920020860F971F9C01F4
:100210008B0180E060E090E070E0C901B8010895D2
:1002200020914C0130914D0140914E0150914F0170
:10023000C901DA018395911DA11DB11D8A9591090E
:10024000A109B1090096911DA11DB11D0097910949
:10025000A109B1099C01AD0120934C0130934D01DE
:1002600040934E0150934F01B901CA010895EAEC41
:10027000F0E080E08CE0E80F8491089508958617FF
:10028000970740F0A1E0B0E00C944D01089581E0A3
:1002900090E0089580E090E00895861B970B861704

Please keep in mind: the avr-objdump.exe I am using is the one that comes with Arduino.

SamBrownADK:
Can this be done in the IDE? Is there some setting I can change so I not only have my compiled sketch, but readable assembly output as well.

Probably not.

SamBrownADK:
I also have an ".elf" file: would that be a better route to take?

Yes. The ELF file will also contain some symbols (e.g. main, loop, and setup).

How is your Python?

Read this
https://www.hex-rays.com/files/decomp_disasm.pdf
Find a tool to disassemble the .hex file the IDE tool chain creates.

Try this one
https://onlinedisassembler.com/odaweb/
Under Platform you'll have to select one of the AVRs, I don't know which corresponds to the 8-bit processors that Arduino is based on.

avr-objdump -S Blink.ino.elf

Is this what you are looking for? This is just a short fragment of a 23K file.

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 37e:   81 e0           ldi     r24, 0x01       ; 1
 380:   0e 94 70 00     call    0xe0    ; 0xe0 <digitalWrite.constprop.0>
  delay(1000);                       // wait for a second
 384:   0e 94 dd 00     call    0x1ba   ; 0x1ba <delay.constprop.1>
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 388:   80 e0           ldi     r24, 0x00       ; 0
 38a:   0e 94 70 00     call    0xe0    ; 0xe0 <digitalWrite.constprop.0>
  delay(1000);                       // wait for a second
 38e:   0e 94 dd 00     call    0x1ba   ; 0x1ba <delay.constprop.1>
 392:   20 97           sbiw    r28, 0x00       ; 0
 394:   a1 f3           breq    .-24            ; 0x37e <main+0xc0>
 396:   0e 94 00 00     call    0       ; 0x0 <__vectors>
 39a:   f1 cf           rjmp    .-30            ; 0x37e <main+0xc0>

Blech, that doesn’t look at all very useful!

gdsports:

Yes! I also got it to work with avr-objdump -D

Now that i have the file i want … I assume the sequential numbers on the left are just that: program line numbers. but are the next numbers in hex the actual memory address of the opcode or data?

so: from your snippet:

37e: 81 e0 ldi r24, 0x01 ; 1
380: 0e 94 70 00 call 0xe0 ; 0xe0 <digitalWrite.constprop.0>

The 37E and 380 on the far left are program line numbers.

The 81E0 and 0E94 are 16 bit memory address of “LDI” and “CALL”?

Line numbers, even to the dimmest disassembler are expressed in decimal.

Address, opcode/operand (it’s a sixteen bit instruction word, remember)

I know i can read / write to DATA space... what i want to do is read / write directly to PROGRAM / SRAM space.

Yes, i know that is dangerious... it is essentialy the program trying to edit its self in run time.. yes I know... i just want to see if I can do it.

So change an "ADIW Z , 3" to say "ADIW Z , 5" and so on.

I just want to see if I can do it. Its just for learning.

It may have utility later on, but for now, just to learn and explore the AVR world.

What is the smallest unit of PROGMEM that can be written?

a word I guess.. 16 bits.

Don't guess.

We seem to be suffering from mission-creep

Huh???

This is what i want to do: first step be able to identify the memory location of the opcode, then try to change it or the operands. How is it mission creep?