You are on page 1of 8

Title: Advantages and Disadvantages of Using Assembly Language in Embedded Systems

Introduction
Assembly language is a low level programming language for programmable devices and mainly
computers. Today, assembly language is used primarily for direct hardware manipulation and to
access to specialized processor instructions, or even to address critical performance issues.
In a book specialising in assembly language, the author (Blum, R. 2005) explains the general use of
assembly language, where it is stated assembly language enables programmers to directly create
instruction code programs without having to worry about the many different instruction code set
combinations on the processor [1].
Typical uses are device drivers, low-level embedded systems, and real-time systems. The assembly
language is converted into executable machine code by an assembler which basically is a utility
program. The process of conversion is called assembling the code or even assembly. Assembly
language is machine specific and considered a "low level" language. This means that the code and
syntax is much closer to the computer's processor, memory, and I/O system. A high level language is
designed with keywords, libraries, and a syntax that introduces a high level of abstraction between
the language and the hardware. Since a computers behaviour is defined by its instruction set, the
logical way to learn such concepts is to study assembly language.

Until today, there are still programmers who uses assembly language in application development.
Why is this so? Because there are advantages of using it and these advantages are very significant
hence assembly language is currently still popular and in demand. However, everything has its
advantages and disadvantages, so in this report we are going to discuss the advantages and
disadvantages of using Assembly Language in applications such as embedded systems.
An embedded system is a microprocessor based system that is incorporated into devices to control
and monitor the functions of the components of the device. Where are embedded system used?
From the range of a microwave oven to a nuclear reactor. Embedded systems are usually designed
for performing specific tasks. It is programmed by the designers of the system and generally cannot
be programmed by the end user.

Embedded systems should be very reliable since they perform only critical functions. For example,
consider the embedded system is used for flight control, if the system should failed, disastrous
consequences will occur. Hence embedded system programmers should take into consideration of
all possibilities and write programs that do not fail.
Programming embedded system software typically involves more than one programming
language. Normally, a high-level language such as C/C++ is used for application oriented tasks and
a low-level assembly language for direct interaction with the underlying hardware. In most cases

those languages are closely interwoven and the assembly is embedded in the C/C++ code *2] is
stated by (Fehnker, A., Huuck, R., Raunch, F., Seefried, S., 2008).
Embedded systems should respond to events as soon as possible. For instance, a patient monitoring
system should process the patients heart signals quickly and immediately notify if any abnormal
signals is detected. Since embedded systems are used for performing specific functions, specialized
hardware is used. For example, embedded systems that monitor and analyse audio signals use signal
processors. As embedded systems are extensively used in consumer electronic systems, they are
cost sensitive and thus their cost must be low.
(Ebrahim, A., 2010) points out that the transition to embedded systems development is difficult
without a reasonable understanding of assembly language and computer architecture, he further
states that as embedded computing enters almost every aspect of the modern technology
landscape, from intelligent gadgets of all kinds to remote and autonomous systems, not having
this knowledge becomes a fundamental impediment to seeing and being able to seize the many
opportunities for participating in this interesting and rapidly expanding area [3].
Unlike personal computers that run a variety of applications, embedded systems are designed for
performing specific tasks. An embedded system used in a device (for instance the embedded
system in washing machine that is used to cycle through the various states of the washing
machine) is programmed by the designers of the system and generally cannot be programmed by
the end user [4 ] is a brief description of embedded systems provided by (Reddy, P. M., 2002) .
So, embedded systems have requirements that differ significantly from general purpose computers.
(Reddy, P. M., 2002) states the fact that The main goal of an embedded system developer is to
design a lowest cost system that performs the desired tasks without failing and later affirms that
recent developments in hardware-software co-design permit trade-offs between hardware and
software for cost-effective embedded systems *5]. This can be supported by the fact that
algorithms can be implemented in hardware or software. While the hardware approach improves
performance the software approach provides flexibility. And through this aspect of efficiency being
achieved, this may not only comply to the wants and needs of the company or a client but allows the
business to operate efficiently.

Advantages of Using Assembly Language in Embedded Systems


First of all, assembly language uses mnemonic codes. Mnemonic codes are an abbreviated term that
is used to define a specific command. These codes are shorter and yet provide the same function as
the original term but are more efficient to enter. Mnemonics allows us to access a wide variety of
commands at a much quicker pace without the need to type out extended phrases.
(Shibu, K. V., 2009) states that in Assembly language based design, it (embedded system) is
developed using the Assembly language specific to the target processor. The Assembly code is
converted to machine specific code by an assembler *6].
We often require precise accurate timing and fast speed. Coincidently, assembly language is well
known for these two specific features. Assembly language can be optimized for speed ensuring that
applications are able to run as fast as possible. Assembly language offer the best choice for
applications that requires very precise timing since there is no need for the code to be interpreted
unlike high level languages that sometime may have delay during processing. Assembly language
lets programmers squeeze out the maximum performance from their application in terms of speed
and memory a statement provided by (Moyer, B., 2013) [7].
While assembly language is more primitive in the instructions that are available compared to a highlevel language, it is a huge improvement upon programming in the binary code of machine language.
For example, JMP is a jump instruction that will transfer program flow to a new location. Basically
this point of benefits is actually pointing out that using of assembly language actually saves time
because of the prevention of using long codes. (Moyer, B., 2013) states that programmers
frequently use the assembly output of the C compiler to debug, hand-edit or hand-optimize the
assembly code to maximize in performance in ways the compiler cannot. This lets them to go
down to architectural details of their code and count instructions in order to obtain accurate
timing characteristics of their application and look at the execution of their code at the machine
instruction level *8].

Assembly language is transferable across machines. Compared to machine code programs an


assembly language program enjoys some portability and can be executed on computers of different
types so long as there is an assembler there that is able to interpret the code into binary code for a
particular machine. Portability is one of the strongest advantages of using assembly language. It has
more portability compared to machines codes and yet shares the same flexibility of a high level
programming language.
(Aguiar, A. & Hessel, F., 2010) states that Their functionality was also mostly determined by
hardware, with software mainly consisting of largely device drivers, a task scheduler and some
control logic, resulting in a low complexity of the software. Besides, these systems used to be
closed, which means that during its lifetime, no change in the software is required *9]. So,
assembly language is used because it can be executed on firmware or processors which do not have
any operating system (OS) or high level language compilers. To make it clearer, devices such as
mobiles phones, dish washers , washing machines , water heaters , table fans and such are often

require computer instructions that are written in assembly language because the code is a
standalone item that can be executed without the overheads of a full computer system. This may
actually decrease the cost of a business in order to operate an embedded system that does not need
a yearly change or update in the software. (Moyer, B., 2013) states that In some low-cost
embedded systems with no support for other language (like C) compilers, such as small
microcontrollers. Assembly is the only programming interface available. Situations where a highlevel language compiler does not provide support for all hardware features, you will ned to write
the functionality (of the embedded system) in assembly, either in-line or as a separate function
[10].
Interaction with hardware is also one of the strong points of assembly language. Why is this so?
Because assembly language can interact directly with the hardware hence it remains one of the best
ways of interacting with hardware with many low level functions to read sensors or control
components being done at a machine level.
(Linggesmeyer, P. & Trapp, M., 2009) states that embedded software must be tailored to
heterogeneous hardware platforms and operating system to meet high performance demands
despite limited resources such as (memory and searching power). This yields tailored, specific
software platforms that are either created through the application and adaptation of the platform
frameworks or developed specifically for an embedded system *11].
Assembly language is able to access hardware drivers and system code hence having the privileges
to access hardware, system control registers and etc. This benefit however may be difficult or
impossible with the use of high level code. The code is so lightweight that it is optimized for size.
Although storage space now a days are cheap but cache size is still such a critical resource that it
may be useful in some cases to optimize a critical piece of code for size in order to make it fit into
the code cache. Not to mention that assembly language has the same efficiency of execution as the
machine level language. Because this is one-to-one translator between assembly language program
and its corresponding machine language program.

Disadvantages of Using Assembly Language in Embedded Systems


However, in the case of language preferences, there are some programmers who prefer the use of C
language over assembly language. In other cases, C language would be used as the main language
while the assembly language would just be used for some routines. Same as can be said about a
clients (in the case of a company offering to develop an embedded system for a client), may also
have some preferences about the language they may choose which may entirely affect the
programming language choice of the programmer. This in turn complicates the language choice in
the development of embedded systems.
This can be seen in an article written by Michael Barr, an embedded systems developer himself,
when a scenario was being put out in an Embedded Systems Conference in San Jose. The scenario
was that an imaginary company has hired the attendees of the conference to operate as a
consultant for their embedded software system that has been causing some issues with their new
product development. Long story short, the company needed a complete redesign and
implementation of a new firmware. The options of the languages used were narrowed down the
two, Assembly language and C language.
In the article, Barr analyses the difference between the two languages and how much it may suit to
fit the conditions of the required specifications of the scenario. With a collaboration with an
another embedded systems developer that specialises in assembly langue (Barr specialises in the
development of embedded systems in the C language), two different firmwares were created and
put through tests in order to determine how suitable they would be as a solution to the given
scenario. At the end of it, Barr has come up with a surprising discovery; that the C language was
more efficient than assembly language in terms of program efficiency.
In the analysis Barr writes that this race condition was exposed when my C code was unable to
communicate with a remote system with which the assembly code had no trouble exchanging
information. After two days in the lab, we finally determined that the true source of the problem
was that the C code was twice as fast to respond to a sync command than the assembly language
has ever been. With a shorter latency in the communication channel, a race condition in the
remote software was exposed. Surprise, surprise, surprise...C had beaten assembly in terms of
program efficiency *12].
This may bring out the assumption that in theory assembly language may actually seem better which
and in terms of application of the development of an embedded system, C language may be a better
choice but it is not as it seems. The lesson here is the choice of the language and the intended use of
the embedded system (whether it is heavy on the arithmetic functions or is it operable in the
companys terms). Based on the analysis done by Barr, the C language was only more efficient than
the assembly language when a sync command was used.
This proves that the efficiency of the language is only determined by the optimization of certain
conditions in order to determine which of the languages are more efficient than the other. That and
also the preferences of the programmer would determine which of the language that is used in the
application of the embedded system itself. But Barr does advise that choosing a language more

tuned to the problem at hand made this system design easier, the implementations faster (by a
factor of 10), and the whole project ran smoothly. The end result was a program that could be
easily maintained and/or ported to new hardware *13].
This is not to say that the disadvantages of assembly language programming are any the less
assembly language is not portable and almost always has higher overhead when coding,
debugging, and maintaining. But in these few areas of embedded systems development, the
benefits occasionally outweigh the trade-offs. *14], a statement made by (Ebrahim, A., 2010)
The statement above may shed some light towards why assembly language would still be chosen in
the programming an embedded system even if it is sometimes used in conjunction with other
languages such as C or C++ language.
There are many factors why some programmers disagree with the use of assembly language in
embedded system. One of the biggest factors is actually development time. Writing code in
assembly language can sometime take much more and longer time than writing codes in a higher
level language. Secondly, we talk about the maintainability of the use of assembly language , it is
more difficult to modify and maintain because the language allows unstructured spaghetti code and
all kinds of dirty tricks that are hard for others to actually fully understand the code. Moving on to
portability, assembly code is very platform specific hence the porting to a different platform is very
difficult.
It is also known that assembly language has low reliability and security. It is easy to make errors, and
the assembler is not checking if the calling conventions and register save conventions are obeyed.
There are so many possibilities for hidden errors in assembly code that is affect the reliability and
security of the system unless testing and verifying with a very systematic approach is done.

Conclusion
In conclusion, it can be easily said that assembly language clearly has more advantages than
disadvantages when compared to most high-level programming languages. Firstly, because of its
shortened mnemonic codes, it is more efficient as it is faster for a programmer to input codes which
can save time, and offers the same flexibility as other programming languages. Assembly language
can be used across almost all machines, if they have an interpreter to translate it into binary, and for
machines that lack Operating systems. Another advantage is the ability to communicate easily and
directly with hardware. Finally, assembly language can be enhanced for speed and accurate timing,
and is interpreted quickly during processing. So, when compared with its disadvantages, it is clear
that assembly language is the better and more favourable choice.
To write great code requires one to write efficient code. Writing efficient code requires good
algorithm choices and a good implementation of those algorithms. The best implementations are
going to be written by those who've mastered assembly language or fully understand the low-level
implementation of the high-level language statements they're choosing. This doesn't mean that we'll
return to the days when major commercial applications were written entirely in assembly language.
However, to reverse the trend of software running slower and slower even though CPUs are running
faster and faster is going to require programmers to begin considering the low-level implications of
the code that they write.
So, even if you never intend to write a single line of assembly language code again, learning
assembly language, and learning to think in assembly language, is one of the best things you can do
to learn how to write better assembly code.

References
[9]. Aguiar, A. & Hessel, F. (2010). Embedded Systems Virtualization: The Next Challenge, IEEE
International Symposium on Rapid System Prototyping, Source: http://www.inctsec.org/actrep/sites/default/files/highlights/GSE%20-%20Highlight%201%20and%20paper.pdf
[12],[13]. Barr, M. (2007). Assembly vs. C, Source: http://www.barrgroup.com/EmbeddedSystems/How-To/Assembly-vs-C-Comparison
[1]. Blum, R. (2005). Professional Assembly Language, Wiley Publishing Inc., ISBN: 0-7645-7901-0.
[3],[14]. Ebrahim, A. (2010). Assembly Language and Embedded Systems Development, Source:
http://mathscitech.orgarticlesassembly-value
[2]. Fehnker, A. & Huuck, R. & Raunch, F., Seefried, S. (2008). Some Assembly Required Program
Analysis of Embedded System Code, Eighth IEEE International Working Conference on Source Code
Analysis and Manipulation, IEEE Computer Society Australia.
[11]. Linggesmeyer, P. & Trapp, M. (2009). Embedded Software: Trends in Embedded Software
Engineering, IEEE Software Issue May/June 2009, Source:
http://disciplinas.stoa.usp.br/pluginfile.php/28857/mod_resource/content/1/trends_in_embedded
_software_engineering.pdf
[7],[8],[10]. Moyer, B. (2013). Real World Multicore Embedded Systems, Newnes, Source:
http://books.google.com.my/books?id=GSV6ho2zZUC&pg=PA290&lpg=PA290&dq=advantages+of+assembly+language+in+Embedded+systems&sou
rce=bl&ots=HpecqjAjA1&sig=B_QpflOAau1AeKk657DF7vwdZI&hl=en&sa=X&ei=hdZqVMzaKcaQmwXNh4DIBg&ved=0CCcQ6AEwAjgU#v=onepage&q=advanta
ges%20of%20assembly%20language%20in%20Embedded%20systems&f=false
[4],[5]. Reddy, P. M. (2002). Embedded Systems, Resonance December 2002 Issue.
[6]. Shibu, K. V. (2009). Introduction to Embedded Systems, Tata McGraw-Hill Education, Source:
http://books.google.com.my/books?id=8hfn4gwR90MC&pg=PA378&lpg=PA378&dq=advantages+of
+assembly+language+in+Embedded+systems&source=bl&ots=kItJac8ysq&sig=43AwesZHLaGq6kuA2S67cVf28s&hl=en&sa=X&ei=3dRqVNSwDivmAX91IK4Cw&ved=0CEIQ6AEwBTgK#v=onepage&q=advantages%20of%20assembly%20language%
20in%20Embedded%20systems&f=false