Assembly Language – features, uses, advantages and disadvantages

Programming languages are critical when comes to embedded systems. Programmers have many languages to choose from these days, their choice depends on their need such as user friendliness, readability, scope and so on. Among all programming languages, Assembly language aka ASM is most widely used and important language used by many industries and engineers. Assembly language is a low level language that uses instructions specified by the chip manufacturers. This tutorial covers various aspects of Assembly language and discuss the advantages and disadvantages of assembly language.

Levels in programming languages:

assembly-machine-high-level-language

Before heading into the advantages and disadvantages of Assembly language we need to understand how microcontrollers and Microprocessors are programmed. When a programmer uses any high level language such as C, C++, Python this will be first converted into assembly language. This in a way of saying without assembly language there wouldn’t be any high level languages. Translated assembly language will be then translated to machine language. Machine language is the final level in programming languages which a MCU or MPU can understand and operate.

When using Assembly language or ASM, it can be directly translated into machine language. This translation from Assembly to machine language is done by a special program known as assemblers.

Popular Assemblers:

The below are the most popular assemblers available.

  • Microsoft Assembler(MASM)
  • Borland Turbo Assemble (TASM)
  • The GNU Assembler (GAS)

What makes Assembly language special:

ASM gives programmer the ability to access the actual registers in the microcontrollers or any target hardware. It was developed to provide programmer a ease to program microcontrollers and microprocessors. When you are programming hardware using machine language, you use “0” and “1”s, a lot of them. Take a look at the below table to visualize how messy machine code can be.

machine-assembly-code

Difference between Assembly and Machine language . Image courtesy: www.computerscience.chemeketa.edu/

Assembly language replaces the messy and inconvenient “0” and “1”s with alphanumeric commands which is known as mnemonic codes. Not only assembly language is easy to interpret and understand also it still offers the high level of control and accessibility to registers, memories in your target hardware. Typically assembly language consists of three types of instructions

  1. Opcode mnemonic – This refers to a single instruction that performs a specific task. Examples are – MOVE, LOAD, STORE etc
  2. Data definitions – These are instructions programmers use to declare the type, size and scope of data. Examples are – BYTE, SBYTE, WORD etc
  3. Assembly directives – This instructions targets to the assembler software rather than the hardware itself. It instructs the assembler software to start, jump, end and other functions while executing the code. Examples are – START, END, EQU etc

Things to know if you intend to program a microcontroller using Assembly language:

By now you would have got a good idea about Assembly language. Before programming a target hardware using it you need to be aware of following things.

  1. Complete instruction set provided for the hardware of the application.
  2. Register organization of the hardware.
  3. Development environment / tool chain ( assembler, directives, linkers etc )
  4. Addressing modes and peripheral features of target hardware

Advantages of Assembly language:

  1. Faster in speed as it will be extremely optimized to use only necessary resources.
  2. Efficient use of memory
  3. High level of control of hardware operations.
  4. Access registers and memory in hardware which cannot be accessed while using high level languages.
  5. Don’t need to rely on compilers to optimize the code.
  6. Assembler bugs are much more easier to identify and fix than compiler bugs.

Disadvantages of Assembly language:

  1. Takes a lot of effort to write and maintain the code.
  2. Most the time the code will not be portable to other Microcontrollers or Microprocessors
  3. Limits algorithm design

Hope this article gave you a good idea about Assembly language. Post your queries and comments in the below comment section.


4 Comments

  1. b

    Where uses of assembly language?

    Reply
    1. Frank DonaldFrank Donald

      It is mentioned in Advantages section

      Reply
  2. Ron Hoffman

    Assembler is used to create the algorithms that “C” and other high level languages use to write to an LCD display or read the direction and count of a quadrature encoder, or create a delay routine, and prctically any routine offered by a higher level language compiler. Without assembly language, there wouldn’t be higher level languages. Also, higher level language compiler bugs (errors) are much more difficult to unravel than assembler bugs which can be followed step-by-step to see where they go wrong. Often, compiler bugs can only be uncovered by examining the assembler language used to generate the routine. I know because I have had to fix some of those types of compiler problems. The last point is that assembler is the ultimate way to decrease program memory size and increase execution speed for a given action. Many “C” routines have multiple lines of code that may or may not be used according to the flags set by the programmer when specifying the routine parameters. All the lines are loaded, but many are skipped, or jumped over. This slows the execution and increases the memory space needed too hold the program.

    Reply
    1. Frank DonaldFrank Donald

      Thanks Ron for sharing your valuable experience. I have incorporated your points in the article now.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *