Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

Assembly Language Pros and Cons

Both of these cases show situations where using assembly language was useful - either to speed up a program or to allow the use of a smaller, simpler chip - but also the problems that come along with it.

These days, Simon Long is a Senior Principal Software Engineer at Raspberry Pi, but in the past he worked in contract research and development and sometimes found himself having to work with assembly language. Here are a couple of incidents that stuck in his mind:

Assembly Language Challenge

For one project, I was working on a rebar scanner, which used a magnetic sensor to detect and graphically display the depths and widths of steel bars embedded in reinforced concrete. In one mode, the scanner could be rolled along a wall and the display would show a diagram of the positions of the bars within that part of the wall. This was originally designed to be used on relatively small 5-metre sections of wall. However, the engineers using it wanted to be able to attach it to a vehicle and drive along a much longer tunnel, 50 to 100 metres long, mapping out all the rebars in one go. This meant that the algorithm used to convert the raw sensor data into the diagram of the wall had to deal with much more data, and still give a result in just a few seconds.

A photograph of Simon Long

One way that I hoped to achieve the required speed-up in the algorithm was to re-write some parts of the code in assembly language, directly using the instructions and registers of the embedded processor in the scanner. This could be quicker than the existing program, which was written in the C programming language, because when a program written in C is converted into machine code, it will be done in a standard way that isn’t necessarily the most efficient for this particular case, but works well generally.

Luckily, I didn’t have to re-write the entire program in assembly language; I was able to identify the most timing-critical repeated segments of the algorithm, and implement them in as few instructions as possible. Also, I didn’t start from nothing – I was able to start from the intermediate assembly language file produced from the C program. Even so, re-writing these sections didn’t speed the program up enough.

In the end, I was able to get the required improvement in speed by re-writing the algorithm itself so that it didn’t perform the slowest parts of the calculation for bars that were too deep to be of concern – but for some programs, a re-write in assembly language can be enough to speed up the program by five times, or even more.

Hidden Issues in Assembly language

In another case, I was called in to debug the car part responsible for measuring the level of fuel remaining in a petrol tank. For some reason, these devices were failing within a few hours of being activated, and the engineers at the company responsible were baffled.

As the sensor was such a small component, it had a small and relatively simple processor, which meant that all of the code written for it was written in assembly language. To debug this, I had to work through the code line by line, with pencil and paper to keep track of the contents of the registers. I eventually discovered that it was possible for the program to look for some data at position “0” of a table, when the positions went from “1” upwards, which would crash the program. Had the program been written in a language like C or Python, this error would have been relatively obvious, but as it was in assembler, it was easy to miss this subtle problem.

Assembly Language Pros and Cons

Both of these cases show situations where using assembly language was useful – either to speed up a program or to allow the use of a smaller, simpler chip – but also the problems that come along with it.

This article is from the free online

How Computers Work: Demystifying Computation

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education