Compilers, assemblers, linkers, loaders, and programming issues

For embedded Systems
Chris Gregg January 29, 2009

is programming for an embedded system different? • Speed • Size • Correctness • Portability • Real-Time or not • Other Hardware Considerations .

How does one actually program an embedded system? • Has this changed over the years? Has there been significant progress? • How does Ford program their Fuel Injection System computer? • How does GE program their Microwave Ovens (and was this different 30 years ago?) • How does Nikon program their digital SLR cameras? • How does Apple/RIM/Microsoft program their iPhone/Blackberry/SmartPhone? • How does a hobbyist program a Pic microprocessor? • How does NASA program (and reprogram) the Mars Rover? • How did James Gosling at Sun want his set-top boxes programmed? • (How was the original 128K Macintosh programmed?) .

Interpreted (?) Perl. XML Java All Eventually End up as Machine Code . Javascript Markup HTML. Ram. Forth. Ada. Python.Programming Languages Machine Code Assembly Code Fixed Rom. etc. nesC. Firmware Higher Level Languages Compiled C. C++.

speed. etc.) What does a programmer need to know about programming for an embedded system? • She’d better know about the hardware. Let’s Go! (Not so fast. I/O). actuators. how to interface with sensors. and how it runs programs • Limitations: memory. upgradability (firmware?) • How are hardware errors handled? (think Mars Rover) • Plan on debugging hardware issues… .So you’ve chosen C. • Whether there is an operating system. • Purpose • How data flows (to include getting the program onto the system.

? • How will debugging be managed? • How will testing be done? • What licensing needs to be organized (this can be tricky!) • Does the software need to be portable? (using C is probably going to help you—see the second point above). what bit-level knowledge of the hardware is necessary.So you’ve chosen C. how does one access pins. Let’s Go! (Not so fast. . • Is there a compiler/linker/assembler? (hopefully!) • How is the memory addressed.) What does a programmer need to know about programming for an embedded system? • She’d better know about the software tools related to programming for the specific hardware. etc.

M. & Massa. (ed. A. A.) Programming Embedded Systems . Oram.The Embedded Software Development Process Barr.

too). Also produces an object file. • Locator: Takes the relocatable file and information about the memory of the system and produces an executable. Produces an object file. and other data and produces a relocatable file.The Tools • Compiler: Translates human readable code into assembly language or opcodes for a particular processor (or possibly into machine-independent opcodes a la Java). (By the way: gcc takes care of all of these functions at once) . • Assembler: Translates assembly language into opcodes (it is really a compiler. necessary libraries. • Linker: Organizes the object files.

• Linker: Needs the correct libraries (open source c libraries. • Compiler: Has to know about the specific hardware (except in very trivial cases). the programmer needs to compile it independently). not the embedded computer. . • Assembler: Produces “startup code”. Pic programming) tools can automate most of it. are available). such as newlib.e.The Tools: Embedded System Specifics All of the tools run on the host computer. Should be able to optimize for size. although certain systems (e. Bottom Line: There can be a lot of extra work for the programmer. not inserted automatically as in general purpose computers (i. • Locator: Needs programmer input for information about memory..g.

the program is written (and possibly run in an emulator) on a host computer. and can include a bootloader as well. • Methods: • Build/burn the program into the hardware (firmware or other flash memory) • Bootloader: a bootloader resides on the embedded system and facilitates loading programs onto the system.Moving the program onto the embedded system • Remember. • Debug Monitor: The debug monitor is a more robust program on an embedded system that helps with debugging and other chores. . but it still needs to get onto the embedded system.

• Software Simulators allow the programmer to debug completely on the host system. A serial link is normally set up. an oscilloscope and a multimeter can be your best friend for debugging. • Emulators can be used to test the system without utilizing the actual hardware (but this has many caveats. which can be quicker and can allow faster code turnaround. or through a remote debugger on the host computer.Debugging • Debugging embedded systems can be facilitated with a Debug Monitor. . • When it comes down to it. and the debugger acts more or less like a general purpose debugger. and nothing beats testing on the real system).

• You had probably learn C (and a fair amount of assembly) to program embedded systems. but it still involves greater programmer involvement in the hardware aspect of the system.Final Thoughts • Programming for embedded systems has come a long way since the days of toggle switches. . • There are many software tools built for embedded systems. and many embedded system hardware designers include debugging tools with the hardware.

via software. • Hardware only does what you tell it to. .Final Thoughts • Is this a necessary topic for an Embedded Systems class? • Yes • You’ve got to get your program onto the system some how. and flipping toggle switches doesn’t put food on the table any more. • Discussion of the tradeoffs necessary to program an embedded system versus a GP system is a necessity.

2) What trade-offs are necessary when thinking about how you are going to program for an embedded system? 3) Why is C generally considered a better language to program in for embedded systems than. and the differences between similar steps on a general purpose system. Java or Perl? . say.6 Questions 1) Discuss the steps needed to get a program from source code to executable in an embedded system.

6) Talk about the role firmware plays in developing software for an embedded system. 5) Why is it imperative that an embedded system programmer know the details of the hardware that she is programming for? Compare this to someone writing a Java applet for a web site.6 Questions 4) Name three different ways you might debug the code for your embedded system. .

Brewer.... How compilers and tools differ for embedded systems. (ed. M. 2003.. R. Levis. S. M.. The nesC language: A holistic approach to networked embedded systems SIGPLAN Not..pdf • Gay. E. Inc. 38. P. Oram. D. 2003. D.) Programming Embedded Systems in C and C++.Bibliography • Barr. 1-11 • Williams. von Behren. 2nd Edition. 2006 • Wolfe.. Chung. Model-based programming of intelligent embedded systems and robotic space explorers Proceedings of the IEEE. A. Ingham. 2005. B. ACM. & Massa. M. 212-237 . O'Reilly & Associates. M. http://www.pgroup. & Culler. Welsh. & Elliott.. P. 91.com/lit/pgi_article_cases. A.

Sign up to vote on this title
UsefulNot useful