X86 Assembly language tutorial :: Assembly

X86 Assembly language tutorial

Stainless steel double lock
University of Virginia Computer Science
CS216: Program and Data Representation, Spring 2006
| | |

This guide describes the basics of 32-bit x86 assembly language programming, covering a small but useful subset of the available instructions and assembler directives. There are several different assembly languages for generating x86 machine code. The one we will use in CS216 is the Microsoft Macro Assembler (MASM) assembler. MASM uses the standard Intel syntax for writing x86 assembly code.

The full x86 instruction set is large and complex (Intel's x86 instruction set manuals comprise over 2900 pages), and we do not cover it all in this guide. For example, there is a 16-bit subset of the x86 instruction set. Using the 16-bit programming model can be quite complex. It has a segmented memory model, more restrictions on register usage, and so on. In this guide, we will limit our attention to more modern aspects of x86 programming, and delve into the instruction set only in enough detail to get a basic feel for x86 programming.

Registers

Modern (i.e 386 and beyond) x86 processors have eight 32-bit general purpose registers, as depicted in Figure 1. The register names are mostly historical. For example, EAX used to be called the accumulator since it was used by a number of arithmetic operations, and ECX was known as the counter since it was used to hold a loop index. Whereas most of the registers have lost their special purposes in the modern instruction set, by convention, two are reserved for special purposes — the stack pointer (ESP) and the base pointer (EBP).

For the EAX, EBX, ECX, and EDX registers, subsections may be used. For example, the least significant 2 bytes of EAX can be treated as a 16-bit register called AX. The least significant byte of AX can be used as a single 8-bit register called AL, while the most significant byte of AX can be used as a single 8-bit register called AH. These names refer to the same physical register. When a two-byte quantity is placed into DX, the update affects the value of DH, DL, and EDX. These sub-registers are mainly hold-overs from older, 16-bit versions of the instruction set. However, they are sometimes convenient when dealing with data that are smaller than 32-bits (e.g. 1-byte ASCII characters).

When referring to registers in assembly language, the names are not case-sensitive. For example, the names EAX and eax refer to the same register.


Figure 1. x86 Registers

Declaring Static Data Regions

You can declare static data regions (analogous to global variables) in x86 assembly using special assembler directives for this purpose. Data declarations should be preceded by the .DATA directive. Following this directive, the directives DB, DW, and DD can be used to declare one, two, and four byte data locations, respectively. Declared locations can be labeled with names for later reference — this is similar to declaring variables by name, but abides by some lower level rules. For example, locations declared in sequence will be located in memory next to one another.

You might also like

Assembly Language Programming Tutorial - 51 - Creating a
Assembly Language Programming Tutorial - 51 - Creating a ...
Assembly Language Programming Tutorial - 34 - AND Instruction
Assembly Language Programming Tutorial - 34 - AND Instruction
Hasbro Furby (Teal)
Toy (Hasbro)
  • Furby responds to your voice and to music
  • Pet Furby s head, tickle its tummy, or pull its tail and see what happens
  • Get the free Furby app that lets you virtually feed your Furby and translate its Furbish language
  • App is optional and works with iPad, iPod touch and iPhone with iOS 4.2 or later
  • Includes Furby and instructions
Video-Tutorials.Net Inventor Essentials - A Comprehensive Introduction
Software (Video-Tutorials.Net)
  • Inventor 2013 Video Tutorials DVD. Includes disc, download and online access. See from any computer and no delay in starting your studies. Please allow 12 hours...
  • 24:46 hours, 311 videos, English language, part files included.
  • For dozens of sample videos that help you gauge the pacing and quality of our work, please visit our Amazon Author Page or our YouTube channel at videotutorials2.
  • VTN is an Authorized AutoDesk Publisher and is a leading provider of high quality, affordable CAD self-study video training.
  • Courses included in this bundle: Essentials (Interface, Data Management, Sketching, Part Modeling, Drawing, Assembly, What s New), Intermediate Assembly, Surface...
Thames & Kosmos Thames & Kosmos Electricity and Magnetism
Toy (Thames & Kosmos)
  • Investigate the relationship between electricity and magnetism
  • Explore electricity with easy snap-together blocks
  • Experiment with a motor and electromagnet
  • Ages 8 and up can safely and easily experiment with electric currents and magnetic fields
  • New 2012 Item - includes 64-page full-color manual
Melissa & Doug Melissa & Doug Traffic Signs and Vehicles
Toy (Melissa & Doug)
  • 15-piece wooden set of vehicles and signs
  • Scaled to fit popular wooden train tracks
  • Play-and-learn activities recommend skill-building play ideas
  • All pieces store in a compartmentalized wooden box
  • Great for motor skills, color and shape recognition, and imaginative play
Hasbro Furby (Pink)
Toy (Hasbro)
  • The beloved, bilingual Furby is back
  • Who your Furby becomes might surprise you
  • Pet Furby s head, tickle its tummy, or pull its tail and see what happens
  • Get the free Furby app that lets you virtually feed your FURBY and translate its Furbish language
  • App is optional and works with iPad, iPod touch and iPhone with iOS 4.2 or later

Copyright © . All Rights Reserved