soja_a

Written by: soja_a

An Introduction to Assembly Language Programming

(©2001 alt.hacking)

1.1 What is assembly language?

The term "assembly language" is used to refer to those computer programming languages that are most basic to the computer. They employ commands that are directly convertible into "machine language," the stream of bits that the processor actually executes during its operation. Assembly language stands in contrast to other, more familiar computer programming languages such as BASIC, FORTRAN, COBOL, Pascal, C, Java and Perl -- all of which are collectively referred to as "high level languages."

The commands of high level languages typically do not correspond directly to machine language commands, so must instead be translated to machine language using a compiler or an interpreter. It's also important to realize that, because assembly languages are so close to the operation of the processor, they are necessarily processor-dependent. This tutorial covers the assembly language of the Intel 80x86 family of processors, but even within that family we will see a degree of processor-specificity.

1.2 Why should I learn assembly language?

There are any number of good answers to this question. My kneejerk reaction is to say that learning ANYTHING is a useful activity for an aspiring hacker. A less glib answer is that a knowledge of assembly language is a very useful thing. It will enable you to write programs that are simply impossible to write in other languages. A knowledge of assembly language will also increase your understanding of the principles of operation of your computer and will make you a better programmer in any language.

1.3 What are the problems with assembly language?

Assembly languages commands are necessarily less powerful than the familiar commands of higher level languages. There are no while-until loops in assembly language, for instance. Also, assembly languages have no high level data constructs such as arrays, matrices or strings. All of these concepts must be simulated in assembly language.

1.4 What are the advantages of assembly language?

Programs written in assembly language will generally take up less memory and run faster than the same programs would if written in a higher level language. More importantly in this age of cheap memory and fast chips is that programs written in assembly language can take advantage of the most fundamental aspects of your computer's operation and can do things that are impossible to code in a high level language. This is why, for instance, most viruses and keyloggers are written in assembly language.

1.5 Will knowing 80x86 assembly language enable me to program other types of CPUs?

As I wrote earlier, assembly language is specific to the processor it's written for. So, for instance, knowing 80*86 ASM won't enable you to write a working program for the Motorola Power PC chipset. However, once you know one assembly language, it takes next to no time to learn another. As an example, I learned the essentials of 80x86 assembly language in a day or two, having previously learned a half dozen others. However, as with most things, it takes considerably longer to become an expert at any one assembly language -- but you don't need to be an expert to write a working assembly language program.

1.6 What software will I need to write assembly language programs?

Aside from a text editor with which to write programs (e.g., Notepad in Windoze, vi or GNU emacs in linux) you will need only an assembler (the software that converts assembly language into executable code). The common assemblers available for the Intel platforms are Microsoft's MASM, Borland's Turbo Assembler (aka TASM, generally agreed to be somewhat more powerful than MASM) and NASM (shareware available both for Windoze and linux). As a strategy, this tutorial will deal with concepts and strategies that are assembler-independent. Likewise, the conventions -- which can vary somewhat between assemblers -- will be chosen as much as possible to be generally applicable.

1.7 How is this tutorial organized?

You've just seen what Section 1 of this text is all about. Sect. 2 covers the fundamentals of the architecture of the 80*86 processor and introduces several concepts that will be needed later. Sect. 3 is a description of the basic 80x86 instruction set -- that is, the assembly language instructions that are actually used to write programs. Sect. 4 describes the anatomy of an assembly language program and provides a few useful examples. Sect. 5 shows how to perform I/O in assembly language and concludes the introduction.

1.8 Other sources of information

This document cannot even attempt to cover all the aspects of either Intel architecture or assembly language programming. You can find further information on these topics in many places on the Web. Here are a few useful links:

Good luck! (Next Page)