ASSEMBLY LANGUANGE
Introduction In
Writing a program in assembly language requires knowledge of the computer’s instruction set, the rules of its use, and the hardware on which it runs. An assembly language program consists of one or more segments for defining data and for machine instructions and a segment named the stack that contains stored addresses.
We
will utilize ROM (Read-only Memory), the important feature of ROM in programming is its Basic Input/Output System (BIOS), RAM (Random Access Memory) , its importance is its availability as a “worksheet” for temporary storage and execution of programs, and Addressing Memory Locations, an assembly language programmer has to distinguish between the address of memory location and its contents.
SEGMENTS A
segment is an area in memory that begins on a paragraph boundary.
TYPES OF SEGMENTS Code
Segment Data Segment Stack Segment Segment Boundaries
Code
Segment – the code segment contains the machine instructions that are to execute. Typically, the first executable instruction is at the start of this segment, and the operating system links to this location for program execution. The CS (code segment) register addresses this segment.
Data
Segment – The data segment contains a program’s defined data, constants, and work areas. The DS (data segment) register addresses this segment.
Stack
Segment – the stack contains any data addresses that you need to save temporarily for your own “called” subroutines to return to your main program. The SS (stack segment) register addresses this segment.
Segment Boundaries The
segment registers contain the starting address of each segment. Extra segment registers are the ES.
Segment Boundaries
Segment Offsets All
memory locations are relative to the start of a segment. The distance in bytes is expressed as an offset (or displacement) from the start of a segment. For example: a two-byte (16-bit) offset can range from hex 0000 through hex FFFF or 0 through 65,535. Thus the first byte of the code segment is at offset 00, the second byte is at offset 01, and so forth, through to offset 65,535.
REGISTERS The
processor’s registers are used to control instructions being executed, to handle addressing of memory, and to provide arithmetic capability. The registers are addressable by name. Bits are conventionally numbered from right to left.
Segment Registers A
segment register is 16 bits long and provides for addressing an area of memory, known as the current segment.
CS register the
code segment register contains the initial address of a program’s code segment. This address plus an offset value in the instruction pointer (IP) register indicates the address of an instruction to be fetched for execution.
DS register the
data segment register contains the initial address of a program’s data segment. In simple terms, this address plus an offset value in an instruction causes a reference to a specific byte location in the data segment.
SS register the
stack segment register permits implementation of a stack in memory, used for temporary storage of addresses and data. The SS register contains the starting address of the program’s stack segment. This address plus an offset value in the stack pointer (SP) register indicates the current word in the stack being addressed.
ES register Some
string (character data) operations use the extra segment register to handle memory addressing. In his context, the ES register is associated with the DI register.
Instruction Pointer Register (IP) The
16-bit IP register contains the offset address of the instruction that is to execute next. The IP is associated with the CS register such that the IP indicates the current instruction within the currently executing code segment.
POINTER REGISTER The
pointer registers, SP and BP, are associated with the SS register and permit the system to access data in the stack segment.
SP register The
16-bith stack pointer is associated with the SS register and provides an offset value that refers to the current word being processed in the stack.
BP register The
16-bit base pointer facilitates referencing parameters, which are data and addresses passed via the stack.
General Purpose Registers The
AX, BX, CX and DX generalpurpose registers are the workhorses. They are unique in that you can address them as one word or as a one-byte portion. The leftmost byte is the “high” portion and the rightmost byte is the “low” portion.
For example, the CX register consists of a CH and a CL portion, and you can reference any of the three names.
The
following instructions move zeros to the CX, CH, and CL respectively: MOV MOV MOV
CX, 00 CH, 00 CL, 00
AX register The
AX register, the primary accumulator, is used for operations involving input/output and most arithmetic.
BX register The
BX is known as the base register since it is the only general-purpose register that can be used as an “index” to extend addressing.
CX register The
CX is known as the count register. It may contain a value to control the number of times a loop is repeated or a value to shift bits left or right.
DX register The
DX is known as the date register. Some input/output operations require its use, and multiply and divided operations that involve large values assume the DX and AX pair.
INDEX REGISTER The
index registers are available for extended addressing and for use in addition and subtraction.
SI register The
16-bit source index register is required for some string (character) operation. In this context, the SI is associated with the DS register.
DI register The
16-bit destination index register is also required for some string operations. In this context, the DI is associated with the ES register.
Flag Register 9
of the 16 bit of the flags register are common to all 8086-family processors to indicate the current status of the machine and the results of execution. The FLAGS Register consists of 9 status bits. These bits are also called flags, because they can either be SET (1) or NOT SET (0). All these flags have a name and purpose.
Flag Register