Search code examples
assemblygcccommand-linearduinoobjdump

How do you get the assembly code for a program in the Arduino IDE (macOS)?


I am trying to get the assembly code of my Arduino program (One of the comments in this question explains why I need the assembly code). I've seen many answers to this question that say to use "objdump" or"gcc" command on the terminal, but whenever I try to run these commands on my computer it tells me "{command} is not recognized as an internal or external command".

I then proceed to try and download these commands by following guides, but I have found these guides are extremely hard to follow and they skip steps. Plus they seem kind of outdated.

Can someone show me an idiot proof way to get the assembly code without skipping steps? I have access to both a mac and a windows computer, but no linux.


Solution

  • Here is how I finally managed to do this on mac:

    First: Find the file path of your Arduino program. Do this by going to your Arduino program in the IDE, select the "Arduino" tab at the top, then select "Preferences". This should pull up a Preferences box where you can check the "Compilation" box under the "Show verbose output during:" section, then select "OK".

    Here is a picture of what i'm talking about:

    enter image description here

    Now when you go into your program in the Arduino IDE and you click the "verify" button you should be able to find your .elf file in the terminal window. Copy the line located directly above "Sketch uses xxx bytes (x%) of program storage space..." (I have highlighted the line you are looking for below):

    enter image description here

    Here is the line I have Highlighted: /private/var/folders/d7/ffdh68g156vdshm9gq4pf3440000gn/T/AppTranslocation/FFDDB455-276F-4474-8B17-B9A99F34B321/d/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-size -A /var/folders/d7/ffdh68g156vdshm9gq4pf3440000gn/T/arduino_build_829591/Working_Sep25_PMOS_Sketch.ino.elf

    You can now erase everything before the -A flag and only copy this part: /var/folders/d7/ffdh68g156vdshm9gq4pf3440000gn/T/arduino_build_829591/Working_Sep25_PMOS_Sketch.ino.elf

    Second: follow this guide which shows you how to download the avr-gcc package which you are going to need.

    Third: Open the terminal and run this command: `avr-objdump -S {insert path to your .elf file we copied earlier}. You should now have access to the assembly code.