如何在 Windows 上获得我的 Arduino 草图的汇编语言列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/919781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get an assembly language listing of my Arduino Sketches on Windows?
提问by Matthew Murdoch
I would like to be able to see an assembly language listing of my Arduino sketches. How can I achieve this?
我希望能够看到我的 Arduino 草图的汇编语言列表。我怎样才能做到这一点?
Update:I am running the Arduino Software on a Windows machine.
更新:我在 Windows 机器上运行 Arduino 软件。
采纳答案by Greg Hewgill
One way to do this is to use avr-objdump
on the .elf
file created by the build. For example, on OS X I can do this:
一种方法是在构建创建avr-objdump
的.elf
文件上使用。例如,在 OS XI 上可以这样做:
$ cd ~/arduino-0015/examples/Digital/Blink/applet $ avr-objdump -d Blink.elf
(Your path on Windows may be different, obviously.) This produces a disassembly of the code, part of which will look something like this:
(显然,您在 Windows 上的路径可能会有所不同。)这会生成代码的反汇编,其中一部分将如下所示:
0000013a <main>: 13a: 0e 94 3e 01 call 0x27c <init> 13e: 0e 94 97 00 call 0x12e <setup> 142: 0e 94 80 00 call 0x100 <loop> 146: fd cf rjmp .-6 ; 0x142 <main+0x8>
回答by Magnus Hoff
If you are using Linux, you can follow this tutorial on how to compile for the Arduino without the IDE.
如果您使用的是 Linux,则可以按照本教程了解如何在没有 IDE 的情况下为 Arduino 进行编译。
Once you do that, you can get an assembly listing by running gcc with the -s flag.
一旦你这样做了,你可以通过运行带有 -s 标志的 gcc 来获得一个程序集列表。
回答by Matthew Murdoch
The following (hacky) steps will provide assembly language listings of Arduino sketches and associated libraries on Windows:
以下(hacky)步骤将在 Windows 上提供 Arduino 草图和相关库的汇编语言列表:
- Download (and rename) the Arduino Windows command line batch filesinto the directory containing your sketch (the
.pde
file) - Set up the required environment variables as specified in the above linked page
- Add
-S
to theabuild_gcc_opts
variable inabuild.bat
(line 158) - Run
abuild -r -c <pde_filename>
Expect to get the following warnings and errors, which you can ignore:
... warning: #warning "This file has been moved to <util/delay.h>."
.\obj\<pde_filename>.cpp.o: file format not recognized: treating as linker script
.\obj\<pde_filename>.cpp.o:1: syntax error
- 将Arduino Windows 命令行批处理文件下载(并重命名)到包含您的草图(
.pde
文件)的目录中 - 按照上述链接页面中的指定设置所需的环境变量
- 添加
-S
到abuild_gcc_opts
变量中abuild.bat
(第 158 行) - 跑
abuild -r -c <pde_filename>
预计会收到以下警告和错误,您可以忽略它们:
... warning: #warning "This file has been moved to <util/delay.h>."
.\obj\<pde_filename>.cpp.o: file format not recognized: treating as linker script
.\obj\<pde_filename>.cpp.o:1: syntax error
The assembly language listings can be found in the .o
files in the created obj
directory. For example the listing for the sketch itself is in obj\<pde_filename>.cpp.o
汇编语言列表可以.o
在创建obj
目录的文件中找到。例如,草图本身的列表在obj\<pde_filename>.cpp.o
回答by Marco linux
The -S (not s) flag show the c code as well.Also know as mixed listing:
-S(不是 s)标志也显示 c 代码。也称为混合列表:
linux: (.arduino/preferences.txt: delete_target_folder=false)
linux: (.arduino/preferences.txt: delete_target_folder=false)
$ cd /tmp/buildxxxx.tmp
$ avr-objdump -dS Blink.cpp.elf
int main(void)
{
init();
2f4: 8a df rcall .-236 ; 0x20a <init>
...