Assembly Language Introduction
An assembly language is an extremely low-level programming language that has a 1-to-1 correspondence to machine code — the series of binary instructions which move values in and out of registers in a CPU (or other microprocessor).
A microprocessor is a mechanical calculator. It has a number of named registers, which are like holding pens for numbers. It receives instructions in the form of machine code, which is represented by a series of binary bits (1s and 0s). For example, here is a line of machine code:
The first few bits (
10110) are an instruction to copy a value into a register. The next three digits (
000) identify the register which the value will be copied into. The rest of it (
01100001) is the value which is to be copied.
10110 is meaningless, and the computer doesn't "know" that it means "copy the value." The processor is designed so that the series of electrical impulses represented by
10110 (on-off-on-on-off) causes the desired result. This is part of what is meant by "mechanical."
Now if you're going to write a program for the processor to execute, you can imagine writing thousands of lines of 1s and 0s would be both tedious and error prone. The solution is assembly language. Assembly language provides human-understandable substitutions for long strings of binary code.
For example, if
10110 means "move the value," then we could abbreviate it with the
MOV command. We could also give the
000 register a easier to remember name (in this case, the register is named
AL). Finally, we could render the value in a different numbering system, such as decimal (
91) or hexidecimal (
61). That line would then be
MOV AL,61. Once a whole program is written this way, an assembler can easily translate each line into the appropriate binary representation.
Computers do work (perform calculations, move data, transform data), by processing billions of these tiny instructions per second. Very simple instructions (move this value, copy that value, add these two values together and save the value over there) combine to form complex operations, which combine at higher and higher levels to actually do things you would recognize as meaningful.
Assembly Language Resources
Tutorials and Basic Guides
- Assembly Programming Tutorial from Tutorials Point;
- X86 Assembly Language Programming, a chapter from the FreeBSD Developers' Handbook, which helps put assembly language writing in the context of operating system development;
- Say Hello to X64 Assembly, a fairly gentle introduction to assembly, from the Code as Art blog;
- X86 Assembly Language Programming, another tutorial that places assembly language well in its OS programming context, this one in reference to Linux, Windows, and even a bit about Mac OS X;
- PC Assembly Language, this focuses on 32-bit PCs running Linux, Windows, or FreeBSD;
- X86 Assembly Guide, from the University of Virginia Computer Science department;
- Webster: billing itself as "The place on the internet to learn assembly language," this site is (apparently) run by the author of The Art of Assembly Language, and the inventor of HLA;
- Linux Assembly Tutorial;
- Easy X86-64;
- X86 Assembly;
- Windows Assembly Programming Tutorial (pdf);
- Video Tutorials:
- Assembly Language Programming Tutorial, a very thorough 55-video series on assembly, following the book Assembly Language for x86 Processors (6th Edition) by Kip Irvine (if you aren't following the videos, you'll probably want the more recent edition);
- Assembly Language Programming Video Course, a 70-part video series, taught by Arthur Griffith, who has a very folksy charm;
- Assembly Language Tutorial, a 7-part series from open-source learning community ShowMeDo.
- Assembly Language Intro, a class room lecture at Cornell, introducing assembly language;
- Assembly Language Programming, an hour-long introduction to assembly, and a great format if you really liked following algebra examples on an over-head projector when you were in high school (this is part of a larger series on Microprocessors and Microcontrollers).
- X86 instruction listings, full list of all instructions for the x86 architectures, with notes on when each was added;
- X86 Opcode and Instruction Reference;
- Intel X86 Assembly Language Cheat Sheet (pdf);
- Another X64 Cheat Sheet (pdf).
- Assemblers — there are a lot of assemblers available — here are a few of the most popular free and open source assemblers:
- IDEs (Integrated Development Environments) ;
Community and Ongoing Learning
- The Art of Assembly Language (online edition) is one of the most popular books on assembly language, from always-readable No Starch Press; you might also be interested in these from the same author:
- Assembly Language Step-by-Step: Programming with Linux
- Professional Assembly Language
- Assembly Language for x86 Processors
- Modern X86 Assembly Language Programming: 32-bit, 64-bit, SSE, and AVX
- ntroduction to 64 Bit Assembly Programming for Linux and OS X: Third Edition - for Linux and OS X
- Introduction To 80X86 Assembly Language And Computer Architecture
- Assembly Language Programming: For PC and Laptop Computers
Should You Learn Assembly Language?
Whether you should learn assembly language depends on what your goals are. For most developers, the answer is "no."
There are two primary reasons to learn assembly language: because you want to use it directly, or because you want to understand computers at a fundamental level.
From a practical standpoint, only a relative handful of the world's engineers and computer scientists actually use assembly language. The overwhelming majority of software development, including virtually all applications development of any kind, uses high level programming languages, and not assembly code. Some specific areas where assembly language gets used are:
- Operating systems
- Device drivers
- Language design
- Compiler design
- Embedded systems
- Hardware design
- Advanced cryptography
- Theoretical computer science
The other reason to learn assembly language is just to gain a better understanding of what is actually going on deep in the guts of a computer. (This is why virtually all Computer Science majors have to learn assembly language.) Of course, if you're the kind of person who is really interested in that, you might want to think about a career working in low-level systems development.
Other Things to Learn
There are some languages where, if you know just a little, you can do a whole lot. Python and Ruby are like that — you can learn enough in a weekend to build something worthwhile. Assembly language is not like that.
Assembly language is never used in a vacuum. The type of engineer who needs to know assembly is likely to be working in area where there is a need a to know a handful of other skills to be effective. These likely include:
- Hardware languages, like VHDL and Verilog, along with a good understanding of microprocessors and electrical engineering;
- Low-level operating system languages like C and its derivatives: C++, C#, and D;
- Legacy languages like Fortran and Cobol;
- Platform languages like Java and Objective-C;
- Compiler, interpreter, and language design.
Further Reading and Resources
We have lots more information on this kind of stuff, Programming: Languages, Timeline & Guides.
What Code Should You Learn?
Confused about what programming language you should learn to code in? Check out our infographic, What Code Should You Learn? It not only discusses different aspects of the languages, it answers important questions such as, "How much money will I make programming Java for a living?"