Page 150 - Embedded Microprocessor Systems Real World Design
P. 150

The Development Language


                 It has been said that you cannot consider yourself a true embedded programmer
                 unless you can code in assembly language. While this may be an exaggeration, it is
                 true that many embedded systems have some code written in assembler. Part of this
                 is because high-level languages (HLL) often assume that things like the stack are
                 initialized. Since function calls in any language need the stack, which usually is in
                 RAM, you cannot do a function call to the function that initializes the stack or the
                 RAM chip select logic. The other reason is speed. The best code optimizers still are
                 not quite as good as a human at generating fast assembly code.
                   That said, high-level languages for embedded applications are becoming more
                 sophisticated, more efficient, and better able to handle the unique hardware that
                 embedded systems must control. The choice of development language, like every
                 other engineering tool, is driven by tradeoffs such as cost, ease of use, and utility.
                   I know that the following statement will  make some software engineers throw
                 this book across the room in disgust, but a simple project may be well served with
                just assembly language. Many small projects are not completed any faster by using
                 an HLL. Some manufacturers  (Microchip and Atmel, for example)  provide free
                 assemblers on their Web sites. But cost is not necessarily a factor in choosing assem-
                 bler over an HLL. Sometimes the issue is speed. Sometimes assembly language is
                 the only way  to get everything to run fast enough. This is particularly true when
                 using a DSP or other hardware-intensive processor. And, if  most of  the  code is
                 dedicated to flipping bits on 1/0 ports or loading timers, much of the design effort
                 goes into calculating things like the  timer values. The actual code may be fairly
                 simple. Of course, the drawback to using assembler is that whoever must maintain
                 the  code  in  the  future  must  learn  the  architecture  and  instruction  set  of  the
                 processor.
                   I  once  used  assembly  for  a  small  microcontroller  project  because  I  could
                 download the  assembler from  the  manufacturer’s Web  site and  get  the  project
                 going faster than I could get the paperwork through  the purchasing department
                 to order a C compiler.
                   As the complexity of a project grows and labor becomes a larger part of the soft-
                ware design, assembly language looks less attractive. The time spent debugging the
                 code becomes more of  a factor, and the ability to write code for more than one
                 processor without  learning a new language is  important.  However, some of  this
                 advantage often is lost on simple microcontrollers. The high-level languages for
                 those devices often have limitations, such as lack of floating-point capability, that
                 limits code portability. In addition, special instructions are frequently needed for
                 controlling device-specific hardware  (timers, 1/0 ports,  and so  on) that will  not
                port to another processor.



                 Software Design                                                      131
   145   146   147   148   149   150   151   152   153   154   155