ASSEMBLY LANGUAGE
An Introduction
MACHINE LANGUAGE
Machine language
The language made up of binary
coded instructions built into the
hardware of a particular computer
and used directly by the computer
Why would anyone choose to use machine
language?
(Hint: they had no choice. Why?)
MACHINE LANGUAGE
Characteristics of machine
language:
Every
processor type has its own set
of specific machine instructions
The relationship between the
processor and the instructions it can
carry out is completely integrated
Each machine-language instruction
does only one very low-level task
DEFINITION
Assembly
Language is a lowlevel language for programming
computers.
It is a machine language, which
means that it is the language of
computer.
DEFINITION OF TERMS:
Register
is a storage space within
the microprocessor that holds binary
digits.
Bit is the smallest unit of data on
a binary computer.
Nibble is a collection of four bits.
Byte consists of eight bits and is the
smallest addressable datum (data
item) on the 80x86 microprocessor.
Bit numbering in a Byte:
Two nibbles in a Byte: High Order and Low
Order
Word is a group of 16 bits.
Bit numbers in a Word
TWO BYTES IN A WORD
Nibbles
in a Word
There are eight 16 bit general purpose
registers on the 8086: AX, BX, CX, DX, SI,
DI, BP, and SP.
1. AX register (Accumulator) is where most
arithmetic and logical computations take
place.
2. BX register (Base) is commonly used to hold
indirectGENERAL
addresses, much
like the BX register
8086
PURPOSE
on the x86 processors.
REGISTERS
3. The CX register (Count) often use it to
count off the number of iterations in a loop
or specify the number of characters in a
string.
4. The DX register (Data) has two special
purposes: it holds the overflow from certain
arithmetic operations, and it holds I/O
addresses when accessing data on the
80x86 I/O bus.
5. The SI and DI registers (Source Index and
Destination Index) used as pointers (much
like the BX register) to indirectly access
memory. Also used with the 8086 string
instructions when processing character
strings.
7. The BP register (Base Pointer) is
similar to the BX register. Used to
access parameters and local variables in
a procedure.
8. The SP register (Stack Pointer) has a
very special purpose it maintains the
program stack. Normally used for
arithmetic computations. The proper
operation of most programs depends
upon the careful use of this register.
The
eight bit registers are not
independent. AL stands for AXs L.O.
byte. AH stands for AXs H.O. byte.
THE
BASIC SYSTEM COMPONENTS
The basic operational design of a
computer system is called its
Architecture. John Von Neumann,
a pioneer in computer design, is
given credit for the architecture of
most computers in use today. For
example, the 80x86 family uses
the Von Neumann Architecture
(VNA).
typical Von Neumann system
has three major components: the
central processing unit (or CPU),
memory, and input/output (or
I/O). The way a system designer
combines these components
impacts system performance
SYSTEM
THE
The system
busBUS
connects
the various
components of a VNA machine. The
80x86 family has three major busses: the
address bus, the Data bus, and the
control bus. A bus is a collection of wires
on which electrical signals pass between
components in the system. These busses
vary from processor to processor.
However, each bus carries comparable
information on all processors.
THE DATA BUS
The
80x86 processors use the data bus
to shuffle data between the various
components in a computer system. The
size of this bus varies widely in the
80x86 family. Indeed, this bus defines
the size of the processor. On typical
80x86 systems, the data bus contains
eight, 16, 32, or 64 lines. The 8088 and
80188 microprocessors have an eight bit
data bus (eight data lines). The 8086,
80186, 80286, and 80386SX processors
have a 16 bit data bus.
THE ADDRESS BUS
The
data bus on an 80x86 family
processor transfers information
between a particular memory
location or I/O device and the CPU.
The only question is, Which
memory location or I/O device?
The address bus answers that
question.
To
differentiate memory locations
and I/O devices, the system
designer assigns a unique memory
address to each memory element
and I/O device. When the software
wants to access some particular
memory location or I/O device, it
places the corresponding address on
the address bus.
THE CONTROL BUS
The
control bus is an eclectic
collection of signals that control how
the processor communicates with the
rest of the system.
The CPU sends data to memory and
receives data from memory on the
data bus. This prompts the question,
Is it sending or receiving?
END OF FIRST PART
Figure: Byte, Word, and Double word Storage
in Memory
CPU
Registers are very special memory
locations constructed from flip-flops.
a flip-flop is an electronic circuit (a bistable multi-vibrator) that has two stable
states and thereby is capable of serving as
one bit of memory.
The names for the x86 CPU registers are:
AX The accumulator register
BX The base address register
CX The count register
DX The data register
THE BUS INTERFACE UNIT
The
bus interface unit (BIU) is
responsible for controlling the address
and data busses when accessing main
memory. If a cache is present on the
CPU chip then the BIU is also
responsible for accessing data in the
cache.
THE X86 INSTRUCTION SET
The
x86 CPUs provide 20 basic
instruction classes. Seven of these
instructions have two operands, eight
of these instructions have a single
operand, and five instructions have no
operands at all. The instructions are
mov (two forms), add, sub, cmp,
and, or, not, je, jne,jb, jbe, ja, jae,
jmp, brk, iret, halt, get, and put.
The move instruction or (mov)
is a command that moves data from
one location in the computer to
another (such as from one register to
another). Therefore, the move
instruction requires two operands: a
source operand and a destination
operand.
The two forms of the mov instruction take
the following forms:
mov reg, reg /memory/constant
mov [destination], [source]
mov memory, reg
where reg is any of ax, bx, cx, or dx;
constant is a numeric constant (using
hexadecimal notation),
and memory is an operand specifying a
memory location.
The
arithmetic and logical instructions take
the following forms:
add reg, reg/memory/constant
sub reg, reg/memory/constant
cmp reg, reg/memory/constant
and reg, reg/memory/constant
or reg, reg/memory/constant
not reg/memory
Note: The reg/memory/constant
operand tells you that this particular
operand may be a register, memory
location, or a constant.
Register
operands are the easiest to
understand. Consider the following forms of
the mov instruction:
mov ax, ax
mov ax, bx
mov ax, cx
mov ax, dx
The first instruction accomplishes absolutely
nothing. It copies the value from the ax
register back into the ax register. The
remaining three instructions copy the value of
bx, cx and dx into ax. Note that the original
values of bx, cx, and dx remain the same.
The
first operand (the destination) is
not limited to ax; you can move
values to any of these registers.
Constants
are also easy to deal with.
Consider the following instructions:
mov ax, 25
mov bx, 195
mov cx, 2056
mov dx, 1000
There are three addressing modes which deal
with accessing data in memory. These
addressing modes take the following forms:
1. mov ax, [1000]
2. mov ax, [bx]
3. mov ax, [1000+bx]
mov ax, [1000]
The first instruction above uses the direct
addressing mode to load ax with the 16 bit
value stored in memory starting at location
1000 hex.
mov ax, [bx]
The mov ax, [bx] instruction loads ax from
the memory location specified by the
contents of the bx register. This is an
indirect addressing mode. Rather than
using the value in bx, this instruction
accesses to the memory location whose
address appears in bx. Note that the
following two instructions:
mov bx, 1000
mov ax, [bx]
are equivalent to the single instruction:
mov ax, [1000]
The
last memory addressing mode is the
indexed addressing mode. An example of
this memory addressing mode is
mov ax, [1000+bx]
This instruction adds the contents of bx
with 1000 to produce the address of the
memory value to fetch. This instruction is
useful for accessing elements of arrays,
records, and other data structures.