assembly language

term

programming

Kept in this browser · My desk

A notation for machine code in which each line names one processor instruction: a mnemonic for the operation, names for the registers, labels instead of addresses. An assembler translates it into bytes one for one.

Assembly is where software meets the processor's own vocabulary, so it turns up wherever a compiler cannot reach or cannot be trusted: boot code, cryptographic and multimedia kernels, debuggers, malware analysis. There is no single assembly language for a processor, only one notation per assembler, which is why the same x86 instruction is written add rax, rdi in Intel syntax and addq %rdi, %rax in AT&T syntax. Its origin has two documented claims: Kathleen Booth's 1947 notation and David Wheeler's EDSAC initial orders of 1949.

What it is. Intel's manual describes the notation it uses as a subset of the IA-32 (Intel Architecture, 32-bit) assembly language in which an instruction is written label: mnemonic argument1, argument2, argument3, where a mnemonic is "a reserved name for a class of instruction opcodes which have the same function" and, with two operands, the right one is the source and the left the destination. IBM put the idea to its 1401 customers in a manual copyrighted from 1959: symbolic programming uses mnemonic characters, the program written in symbols is the source program, the machine-language result is the object program, and the translation is "one-for-one", done by a processor "sometimes called an assembly system". Intel's 8080/8085 manual of November 1978 calls the assembler's work "the clerical task of translating symbolic code into object code" and lists its three outputs: the object file, a listing of source and generated code with the symbol table, and a cross-reference of every symbol.

One line, one instruction. That one-for-one relation separates assembly from compiled languages. The line add rax, rdi becomes exactly the three bytes 48 01 F8 on x86-64: 48 is a prefix selecting 64-bit operands, 01 is the opcode Intel lists for ADD r/m64, r64, and F8 is the ModR/M byte naming RDI as source and RAX as destination. An x86 instruction is built from optional prefixes, one to three opcode bytes, a ModR/M byte, a SIB (scale-index-base) byte, a displacement and an immediate, and never exceeds 15 bytes. Fixed-width architectures are simpler: mov x1, #0 becomes the 32-bit word D2800001 on AArch64; li a1, 0 becomes 00000593 on RISC-V. Some lines are pseudo-instructions that the assembler expands (RISC-V's li, mv, beqz and ret): the RISC-V Assembly Programmer's Manual shows li a0, 0xdeadbeef becoming two instructions on a 32-bit target, lui a0, 0xdeadc and addi a0, a0, -273, because a 32-bit constant does not fit in one. The same manual gives each register two names, such as x10 and a0, the second from the calling convention.

Statements and directives. The GNU assembler's manual says a statement begins with zero or more labels, each a symbol followed by a colon, then a key symbol: if it begins with a dot the statement is a directive, if with a letter it is an instruction that assembles into a machine instruction, and "the same symbol may represent a different instruction in a different computer's assembly language". Directives place data and set options rather than produce instructions (.align, .ascii, .byte and many more). The Netwide Assembler (NASM), at version 3.02, describes its line as label: instruction operands ; comment, with pseudo-instructions such as DB and DW for initialized data, RESB for reserved space, EQU for constants and TIMES for repetition. The Microsoft Macro Assembler (MASM) adds a macro language with loops, arithmetic and strings. Syntax is per assembler, not per processor: the GNU assembler's default AT&T syntax writes the same addition addq %rdi, %rax, with $ before immediates, % before registers, a size suffix and the operands reversed.

Two passes. A label may be used before it is defined, as in a call to a later subroutine. David Salomon's Assemblers and Loaders (1993) calls this the future symbol problem and describes the two answers: a one-pass assembler that loads code straight into memory, and the two-pass assembler most systems use, which collects every label into the symbol table on the first pass and assembles the instructions on the second, producing a relocatable object file for a linker and loader to place.

Who was first. MacTutor calls Kathleen Booth "the first to create assembly language", from the reports she and Andrew Booth wrote at the Institute for Advanced Study in 1947, and The Register's 2022 obituary says her Contracted Notation "is today known as assembly language". The extracts MacTutor publishes show the reports written in the summer of 1947 by Andrew Booth and Kathleen Britten, as she then was; in Coding for the A.R.C. (Automatic Relay Computer) they made the relay machine's code identical to the one planned for their electronic computer. The IEEE Computer Society calls David Wheeler's initial orders for the EDSAC (Electronic Delay Storage Automatic Calculator), 31 instructions that assembled programs written as letters and numbers from paper tape in 1949, "the first 'assembly language'". Wheeler's own notes, kept by the Cambridge Computer Laboratory, explain the form: a 17-bit order of five function bits, a spare bit, ten address bits and a length bit, written as a function letter, a decimal address and F or D, as in S 4D, with letters chosen to be "as mnemonic as possible" (no J for jump, since the operation was thought of as "transfer of control"), and orders mixed with directives. The laboratory's chronology dates the first logged program to 6 May 1949 and the wiring of Initial Orders 2 to 22 October 1949. Salomon credits Maurice Wilkes with labels ("floating addresses"), an early form of macros ("synthetic orders") and the first subroutine library. Both claims are documented; they answer different questions.

Into industry. Salomon dates the IBM 650's first deliveries to about 1953 and describes its SOAP (Symbolic Optimum Assembly Program) as a symbolic assembler that also placed each instruction on the magnetic drum where it would come under the read head just as the previous one finished. In February 1958 D. E. Knuth of the Case Institute of Technology documented CASE SOAP III, a revision of SOAP II, originally written by Stan Poley at IBM, with 24 new pseudo-operations, and in August 1959 his SuperSoap for a 650 with extra attachments such as index registers, core memory and a disk unit. For the IBM 704, first delivered in 1956, Roy Nutt of United Aircraft wrote UASAP-1 (United Aircraft Symbolic Assembly Program), a later version of which IBM's user group SHARE adopted and distributed.

What goes wrong. The classic misreading is operand order: Intel syntax puts the destination first and AT&T last, so a listing read in the wrong convention inverts every move. Disassembly is not simply assembly reversed: GNU objdump's -d option decodes only the sections expected to hold instructions, -D decodes everything, and -M intel or -M att picks the syntax. Hovav Shacham showed in 2007 that x86 is so dense that decoding from one byte later yields different, valid instructions, the raw material of return-oriented programming, whereas on an architecture with aligned 32-bit instructions, such as MIPS, there is no such ambiguity.

In Brazil. Brazilian practice long used "Assembler" for the language itself: the magazine Micro Sistemas in August 1982 described programs written "em linguagem de máquina ou em Assembler, uma linguagem que utiliza símbolos ou códigos mnemônicos". WebAssembly, despite the name, is not an assembly language for any physical processor but "a binary instruction format for a stack-based virtual machine".

Also known as: assembly, asm, assembler language, linguagem de montagem, linguagem assembly

Sources

← Back to A Back to the glossary