Definition

assembler

What is an assembler?

An assembler is a type of computer program that takes in basic instructions and converts them into a pattern of bits that the computer's processor can use to perform basic operations. The assembler's job is to convert assembler or assembly language code into machine code that the computer can then read and execute.

In simple terms, an assembler is a piece of software that converts instructions written in assembly language to computer-readable machine code. It can also compile or convert low-level assembly language code into machine language code.

During the compilation process, the assembler assembles and converts assembly language source code into object code. Object code is written in a series of bits that the computer processor can then directly execute. In addition to translating assembly code into machine code, some assemblers also enable the use of control statements and data abstraction services. Certain assemblers support object-oriented programming structures.

How assemblers work

Most computers come with a basic set of instructions called assembler instructions that correspond to the basic machine operations that the computer can perform. For example, a load instruction causes the processor to move a string of bits from a location in the processor to a special holding place called a register.

A programmer uses a sequence of these assembler instructions to write the source code. The assembler program then takes each statement in the source program and generates a corresponding bit stream or pattern called the object code. This output remains relative to the input source program and can then be executed as needed. The bit stream that constitutes the object program is called the machine code.

The assembler identifies the symbolic names associated with each instruction and allocates memory to each instruction. It also maintains a program counter or location counter (LC) to keep track of the memory addresses of every instruction. As it processes these instructions, it updates the LC and generates the target machine code.

diagram illustrating the generation of object code from source code using an assembler
Here is the sequence of events to generate object code from source code using an assembler.

Types of assemblers

Assembler programs bridge the gap between assembly language and machine language that the computer's processor and memory can read. The assembler type is defined by the number of times it takes the program to scan the source code to translate it into machine language. There are two main types of assemblers.

Single-pass assembler

A single-pass or one-pass assembler translates the entire assembly language program into its equivalent machine language program in one go. In a single scan, the assembler substitutes the pseudo or symbolic instructions in the assembly program with computer-readable machine code.

Multipass assembler

In a multipass assembler, the assembler must scan the assembly language program multiple times before it can be translated to its equivalent machine language avatar. In the first pass, the assembler generates a symbol code where it records and processes the pseudo instructions in assembly language. In the second pass, it generates the equivalent machine code.

Assembly language

In the earliest computers, programmers wrote programs in machine code. Over time, assembler languages or instruction sets were developed to speed up programming. Today, programmers use assembler programming for efficient control over processor operations, but this type of programming requires knowledge of a particular computer's instruction set.

Machine language consists strictly of binary digits -- 0s and 1s -- which makes it extremely difficult to write programs for human users to understand. Assembly language uses mnemonics, which are symbolic representations of specific code -- known as operation code -- meant to be intuitive to programmers. This low-level language conveys instructions to the computer processor using a simpler syntax.

Assembler vs. compiler

Even though assemblers are sometimes known as assembly language compilers, assemblers and compilers are not the same type of program. While both assemblers and compilers output machine code, the main purpose of an assembler is to convert assembly language into its equivalent machine language. By contrast, a compiler converts high-level source code, such as C, Java, JavaScript or PHP code, into machine-level language code. Thus, an assembler's input is made up of low-level code, while a compiler's input consists of higher-level language.

diagram illustrating the order of typical compiler steps
Assemblers and compilers output machine code. However, assemblers convert assembly language into its equivalent machine language, while compilers convert high-level source code typically using the steps outlined in this diagram.

Another difference is that assemblers can convert source code into machine code in a single pass or in multiple passes. Compilers almost always do the conversion in a single pass. Assemblers produce binary code in a stream of 0s and 1s. Compilers produce machine code in the form of mnemonics.

Learn about a modern approach to enterprise software development and the differences between functional vs. object-oriented programming. Explore this breakdown of object-oriented programming concepts.

This was last updated in August 2023

Continue Reading About assembler

Dig Deeper on Data center careers, staffing and certifications

SearchWindowsServer
Cloud Computing
Storage
Sustainability
and ESG
Close
  翻译: