有什么好的嵌入式平台可以用来自学汇编语言?
我有相当多的编程经验,但都是高级语言。我最近学习了 C,那个项目进展非常顺利,学习经历非常值得。
现在我想更进一步,学习汇编语言,但理想情况下我想在嵌入式平台上学习,因为那是我未来的一些项目所在。问题是,对于初学者来说,哪个是最好的起点或“工具包”?
我正在寻找一种相当容易组装、可以做“现实世界”的事情并且通常提供可以构建的良好基础的东西。
I've got a decent amount of programming experience but it is all in high level languages. I recently picked up C and that project went really well and the learning experience was well worth it.
Now I want to take that one step further and learn assembly language but ideally I'd like to learn on an embedded platform as that's where I see some of my future projects lying. The question is, which is the best starting point or 'kit' for a beginner?
I'm looking for something that's reasonably easy to put together, can do 'real world' things and generally provide a good foundation that can be built on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
比学习一个汇编程序更重要的是,至少学习两个。现有的体系结构多种多样,了解多个程序集似乎是避免做出过度概括的假设的好方法。
许多汇编课程都使用 MIPS。 MIPS指令集很简单,高端PIC微控制器(来自Microchip)都使用它。 MIPS 处理器常见于家庭路由器中。 OpenWRT 是许多此类家庭路由器的替代固件,基于 Linux。兼容 OpenWRT 的路由器售价 50 美元,是进入嵌入式系统世界的一种廉价且简单的方式。
许多移动平台,特别是手机,都使用 ARM 处理器(实际上,所有智能手机和平板电脑都使用 ARM 衍生产品,但我读到,大约 15% 的廉价非智能手机仍然使用其他处理器,通常是 MIPS)。 ARM平台有点复杂;有多种指令集(原始26位ARM、32位ARM、Thumb、Thumb-2)和多种调用约定(ATPCS、AAPCS...)。基于 ARM 的开发套件可以从多个供应商处购买,例如 Gumstix。有一些基于 ARM 的路由器可以运行 OpenWRT,但它们比基于 MIPS 的路由器要少得多。
汽车和飞机行业似乎非常喜欢将 PowerPC 处理器用于其嵌入式系统。而且,目前主流的游戏机都采用PowerPC架构(PS3、Xbox 360、Wii)。对于 PowerPC 开发平台,我建议购买一台旧 Mac,例如在 Ebay 上或从翻新计算机经销商处购买。有来自低端Mac的指针;寻找带有 G3 或 G4 的机器。我在 Ebay 上花了 60 美元买了一台基于 G3 的“翻盖式”iBook;加上NetBSD,这是一个完美的基于PowerPC的开发平台。
任何 PC 中都存在的 x86 CPU 也应该被研究,哪怕只是因为它如此普遍。您正在使用的机器,无论是 PC 还是 2005 年后的 Mac,都是您的开发平台,因此很便宜(您已经拥有硬件)。指令集“不优雅”。不要在第一次组装时学习它,而是在第二次或第三次组装时看看它。每隔一年左右,x86 处理器就会开发一组新的附加指令,所以现在它们有数百条,这可能会让人不知所措;我建议从原始 80386 的说明开始。
其他一些架构已经并且仍在用于嵌入式产品,例如68000,但它们较少见。请注意,我在这里谈论的是“大”嵌入式产品。还有一些较小的系统,其架构如 AVR、pre-MIPS PIC、80C51...这取决于当您说“嵌入式”时,您是否会想到“家庭路由器”或“可编程烤面包机”。
无论如何,我还建议使用 QEMU。 QEMU 是一个软件模拟器。它能够运行功能齐全的基于 ARM 或 MIPS 的虚拟机,并配有操作系统(例如 Debian Linux),在一台基本的 PC 上。它不会帮助您进行与时序相关的优化,但它使开发和校正测试变得更加容易。
More important than learning an assembler, learn at least two. There is a wide variety in existing architectures, and knowing several assemblies looks like a good way to avoid making over-generalized assumptions.
Many assembly courses use MIPS. The MIPS instruction set is simple, and the high-end PIC microcontrollers (from Microchip) use it. MIPS processors are commonly found in home routers. OpenWRT is a replacement firmware for many such home routers, based on Linux. An OpenWRT-compatible router costs 50$ and is a cheap and easy way to enter the world of embedded systems.
Many mobile platforms, in particular mobile phones, use ARM processors (actually, all smartphones and tablets use an ARM derivative, but I read that about 15% of the cheap, non-smart phones still use something else, usually a MIPS). The ARM platform is a bit complex; there are several instruction sets (original 26-bit ARM, 32-bit ARM, Thumb, Thumb-2), and several call conventions (ATPCS, AAPCS...). ARM-based development kits can be bought from several vendors, e.g. Gumstix. There are a few ARM-based routers on which OpenWRT runs, but they are much less common than MIPS-based routers.
The automobile and airplane industries seem to be quite fond of PowerPC processors for their embedded systems. Also, the current major game consoles all use the PowerPC architecture (PS3, Xbox 360, Wii). For a PowerPC development platform, I recommend buying an old Mac, e.g. on Ebay or from a refurbished computer dealer. There are pointers from Low End Mac; look for a machine with a G3 or a G4. I bought a G3-based "clamshell" iBook for 60$ on Ebay; with NetBSD on it, this is a perfect PowerPC-based development platform.
The x86 CPU, as found in any PC, should be studied as well, if only because it is so prevalent. The machine your are using, bet it a PC or a post-2005 Mac, is your development platform, so that's cheap (you already have the hardware). The instruction set is "inelegant". Do not learn it as your first assembly, but have a look at it for your second or third. Every other year or so, x86 processor develop a new set of additional instructions, so now they have hundreds of those, which can be quite overwhelming; I recommend beginning with the instructions for the original 80386.
Some other architectures have been used and are still used for embedded products, e.g. the 68000, but they are rarer. Note that I talk here about the "big" embedded products. There are also smaller systems with architectures such as AVR, pre-MIPS PIC, 80C51... It depends on whether, when you say "embedded", you think "home router" or "programmable toaster".
Anyway, I also recommend using QEMU. QEMU is a software emulator. It is able to run a fully functional virtual ARM or MIPS-based machine, complete with operating system (e.g. a Debian Linux), on a basic PC. It will not help you for timing-related optimization, but it makes development and correction testing much easier.
AVR 并不是最好的指令集。我会将其保存为第二个或第三个指令集。但最终你可能会到达那里,因为 arduino 非常受欢迎,并且得到了社区的良好支持(尽管 asm 是例外,而不是那个世界的规则)。
现在你可以花 4.30 美元买到一块 msp430 板,基本上 TI 正在承担赠送这些东西的成本。 msp430是一个很好学习的指令集。
armmite pro 是一个不错的 arduino 大小的板,但使用手臂而不是 avr。手臂和拇指是很好的指令集。
几乎所有东西都有模拟器,无论是否,编写模拟器都是了解事物如何工作的非常好的方法。如果不出意外的话,我通常建议编写一个反汇编程序。
另外,带有 C 编译器的指令集也很好,因为您可以编写一些 C 代码,进行优化,看看输出什么样的汇编程序,并了解有关汇编程序的不同知识。首先学习一些提高效率和性能的技巧,稍后您将能够超越编译器,或者至少达到同等水平。所有提到的都有某种C编译器,avr和msp有办法让gcc工作,arm和thumb受到主线编译器的支持。 llvm 是自动交叉编译器,因此您不必编译编译器即可开始使用,llvm 的 msp430 后端是实验性的,但应该可以工作或接近,arm 和拇指后端都很好(在 clang 中使用 -m32 以避免 64 位64 位主机上的整数)。
Stellaris 芯片以前是 luminary micro,现在是 ti(德州仪器),都很好,只有拇指/拇指 2。 mbed 实际上非常好,除了蓝色 LED(让我偏头痛),您不需要提交到沙箱,插入 USB,它像文件系统一样安装,将 .bin 文件复制到闪存,按重置按钮它运行你的程序。
Sparkfun.com 是您的朋友、开发者工具,并且有来自所有玩家的一长串基于微控制器的开发板。我提到的 msp430 板大约是 5 美元,armmite pro,arduino 的多种口味,我推荐 lilly pad,它的价格与 arduino pro 差不多,但已经焊接了接头,可以与小 USB 一起使用您也想购买的系列产品。 stellaris 在 Sparkfun 上没有代表,但许多 50 美元以下的开发板都有代表。
msp430 板、armmite pro、arduino 板、stellaris、mbed 等需要电源,通常通过 USB 电缆供电,或者某些需要基于 ftdi 的 USB 转串口
如果您采用模拟器路线,qemu 支持许多指令套装,手臂/拇指。有gameboy和nds模拟器。 nds 模拟器的想法,以源代码形式附带了适用于arm9 和arm7 的arm 内核,不过我还没有尝试单独提取和使用它们。如果您想继续使用旧式系统,那么市面上有大量的 6502 和 z80 仿真器,无论您相信与否,有些编译器肯定是汇编器。
我要学习的最后一个汇编程序是 x86,可怕的指令集,并且由于变化和微编码,您不会全面超越编译器,是的,您当时的计算机,但所有 x86 计算机都不值得花时间。其他指令集更重要的是要了解(arm、thumb、thumb2、avr)。
AVR is not the best instruction set. I would save it for a second or third instruction set. But eventually you may end up there as the arduino is incredibly popular and has good support through the community (although asm is exception not the rule in that world).
right now you can get a msp430 board for $4.30, basically TI is eating the cost to give these things away. msp430 is a good instruction set to learn.
The armmite pro is not a bad, arduino sized, board but uses an arm instead of avr. arm and thumb are good instruction sets.
There are emulators for pretty much everything, if or if not, writing an emulator is a very good way to learn how things work. If nothing else I normally recommend writing a disassembler.
Also an instruction set with a C compiler is good in that you can write some C code, play with the optimization, and see what kind of assembler is output, and learn different things about assembler. At first learn some tricks for efficiency and performance, later you will be able to outperform the compiler, or at least be on par. all of the ones mentioned have some sort of C compiler, avr and msp have ways to get gcc working, arm and thumb are supported by the mainline compilers. Llvm is automatically a cross compiler so you do not have to compile a compiler to get started, the msp430 backend to llvm is experimental but should work or be close, the arm and thumb backends are fine (use -m32 in clang to avoid 64 bit integers on a 64 bit host).
The stellaris chips formerly luminary micro, now ti (texas instruments) are good, thumb/thumb2 only. The mbed is actually pretty good other than the blue leds (give me migraines) you dont need to commit to a sandbox, plug in the usb, it mounts like a file system, copy your .bin file to the flash, press the reset button and it runs your program.
sparkfun.com is your friend, developer tools, and there is a long list of micrcontroller based boards, from all the players. the msp430 board I mentioned is about $5 something there, the armmite pro, many flavors of arduino, I recommend the lilly pad, it is about the same price as the arduino pro, but already has the header soldered on to use with the little usb to serial thing which you will want to purchase as well. stellaris is not represented at sparkfun, but many sub $50 boards are.
The msp430 boards, armmite pro, arduino boards, stellaris, mbed and others need power which is usually through the usb cable or for some get the ftdi based usb to serial thing
If you go the emulator route, qemu has support for a number of instruction sets, arm/thumb. there are gameboy and nds emulators out there. the ideas nds emulator, in source form comes with arm cores for both the arm9 and arm7, I have not tried to extract and use them on their own though. If you want to go old school there are tons of 6502 and z80 emulators out there, and some compilers believe it or not, certainly assembler.
The last assembler I would learn is x86, horrible instruction set and with the variations and microcoding you are not going to outperform the compiler across the board, yes your computer at that moment, but all x86 computers it is not worth the time. Other instruction sets are more important to know (arm, thumb, thumb2, avr).
对于AVR嵌入式平台,您可以使用免费的WinAVR,它集成了模拟器,因此学习ASM会很容易即使没有真正的董事会。您可以在此处找到 ASM 教程。 AVR 快速入门指南可以在此处找到。例如,所有 Arduino CPU 板都内置 AVR,因此您有非常广泛的选择。
For an AVR embedded platform you can use free WinAVR, which has integrated simulator so it will be easy to learn ASM even without real board. You can find an ASM tutorial here. Quick start up guide for AVR can be found here. For example, all Arduino CPU boards have AVR inside them, so you have a very wide choice.
我有点偏向低端的 14 位 PIC 指令集(Microchip)和高端的 ARM 指令集。两者都相对简单,但功能强大。 PIC 18F系列有更强大的指令集,但从美观角度来说我不太喜欢它。
I'm somewhat partial to the 14-bit PIC instruction set (Microchip) for the low end and the ARM instruction set for the high end. Both are relatively simple, but powerful for what they can do. The PIC 18F series has a somewhat more powerful instruction set, but aesthetically I don't like it as much.
这真的是更进一步,还是倒退?可以说,这是一条通往更深入理解的道路,但它很难说是一条提高生产力的道路。
没有一种“汇编语言”,每种处理器架构都有自己的指令集,因此学习一门汇编语言将使您只能够对特定目标进行编程(尽管它也会为您提供低级的通用技能)编程并了解处理器的工作原理)。您生成的代码也将特定于一种架构,因此您在代码上的所有努力和投资将远不如高级语言那样可移植。如果最终您选择的架构变得过时(并且有很多架构已经过时),那么除了它可能提供的通用技能之外,您对该架构的组装技能在很大程度上变成了多余的知识(学习新的指令集和架构会更快) 。
除非您要执行大量汇编程序并高度精通特定指令集(并且有充分的理由这样做),否则学习汇编程序的价值是有限的。如果您正在实现启动代码来初始化处理器并为 C 或 C++ 代码建立运行时环境,那么它很有用,但这可能主要由芯片或工具供应商提供,您不需要完全了解使用或改编此类代码的架构或指令集。
使用汇编程序的一个经常建议的论点是性能,但一般来说,优化编译器生成的代码几乎与专家汇编程序员一样高效,而且通常比不熟练的程序员更高效。您会看到,就目标指令集和体系结构而言,编译器本质上是一个专家系统。它通常知道每条可用指令及其执行时间、每个寄存器、每种寻址模式,并了解流水线、缓存和分支预测机制等。在中等复杂的处理器上,编译器的专业知识将胜过所有其他处理器。最专注的全职汇编程序员,而在简单的处理器上,无论哪种方式获得的收益都少得多。
汇编器可能有用的一个领域是利用编译器或其库可能不会触及的某些处理器的某些方面。例如,在 DSP 处理器上使用汇编器是很常见的,但即使在那里,使用优化的 DSP 库(通常本身是用汇编器编写的),或者编译器可识别并可以优化的编译器扩展或语言习惯用法,使得这在很大程度上没有必要,并且学习具有SIMD 和并行执行功能的DSP 指令集是一项重大投资。
我最后一次需要使用 C 运行时启动代码之外的汇编程序是在将代码从一个 ARM 设备移植到带有 VFP 协处理器的新设备时;尽管重新编译的库使用了 VFP,但 sqrt() 函数是使用收敛算法而不是硬件 sqrt 指令来实现的。一种功能,一条或两条装配线;我当然不需要学习 ARM 指令集就能做到这一点。
我唯一详细学习过的汇编语言是Z80和8051。那是很久以前的事了,我都忘了,现在这些知识基本上已经过时了。然而,所学到的一般技能确实允许我调整系统并进行电路板调配,如前所述,但作为招募其他嵌入式系统开发人员的人,我不会太关注候选人的组装技能。
我认为使用汇编语言,您要么需要旅游/短语书级别的知识才能在需要时顺利度过难关,要么像母语一样说话,这样你的技能具有真正的价值,介于两者之间的任何东西都没有什么价值。
也就是说,如果您必须或觉得有必要,我建议使用 ARM Cortex M3 设备。不太可能很快就会过时(来自多个被许可供应商的设备),并且足够复杂和现代,可以为您为其他架构奠定良好的基础。
Is that really a step further, or a step backward? Arguably it is a path to deeper understanding, put it is hardly a path to greater productivity.
There is no one "assembly language", each processor architecture has its own instruction set so learning an assembly language will equip you only to program that particular target (although it will also give you general skills in low level programming and understanding how the processor works). The code you generate will also be specific to one architecture so all your effort and investment in code will be far less portable than in a high level language. If ultimately the architecture you choose becomes obsolete (and there are many that have), you assembly skills for that architecture become largely redundant knowledge apart from the general skills it may provide (it will be faster to learn the a new instruction set and architecture).
Unless you are going to be doing a lot of assembler and become highly proficient at a particular instruction set (and have a strong justification for doing so), learning assembler at all has limited value. It is useful if you are implementing start-up code to initialise a processor and establishing the run-time environment for your C or C++ code, but that may be largely provided by the chip or tool vendor and you do not need a full undestanding of an architectire or instruction set to use or adapt such code.
One often suggested argument for using assembler is performance, but in general an optimising compiler will generate code nearly as or nearly as efficient as an expert assembly programmer, and most often more efficient than a less than proficient one. You see the compiler is essentially an expert system as far as the target instruction set and architecture is concerned. It generally knows every available instruction and thier execution times, every register, every addressing mode, and understands the pipelining, caching, and branch prediction mechanisms etc. On a moderatley complex processor the compilers expertise will outgun all but the most dedicated full-time assembler programmers, and on simple processors there is far less to be gained either way.
One area where assembler may be useful is in utilising aspects of some processors that the compiler or its library may not touch. It is common for example to use assembler on DSP processors, but even there the use of optimised DSP libraries (generally themselves written in assembler), or compiler extensions or language idioms that the compiler recognizes and can optimise make this largely unnecessary, and learning a DSP instruction set with SIMD and parallel-execution capabilities is a significant investment.
The last time I needed used assembler other than C runtime start-up code, was when porting code from one ARM defice to a new one with a VFP co-processor; although the recompiled library made use of the VFP, the sqrt() function was implemented using a convergance algorithm rather than the hardware sqrt instruction. One function, one or two lines of assembly; I certainly did not need to learn the ARM instruction set to get that far.
The only assemby languages I have learned in detail are Z80 and 8051. That was a long time ago, and I hve forgotton it all, and the knowledge is now largely obsolete. However the general skills learned do allow me to tweak systems and do board bring-up as already described, but as some one who recruits aother embedded systems developers, I would not pay that much attention to a candidated assembly skills.
I think with assembly language you either need tourist/phrase-book level knowledge to just get by when you need to, or speak-it-like-a-native so that your skills have real value, anything in-between has little value.
That said, if you must, or feel the need, I suggest as ARM Cortex M3 device. Unlikely to become obsolete any time soon (devices from multiple licensee vendors), and sufficiently complex and nodern to give you a good grounding for other architectures.