Você está na página 1de 4

The parts of an assembly language program

An assembly language program consists of a sequence of statements. There are three


types of statements: comments, instructions, and directives.

Comments
● These are statements, or parts of statements, that are ignored by the
assembler.
● Comments are used to write descriptions in English regarding parts of your
program.
● A semicolon (;) is used as the character that denotes a comment, or denotes
a line that is to be ignored by the assembler
● Example: ; This line is a comment.
MOV AX,99 ; Here is another comment
Instructions
● This is a statement that will be translated into machine language.
● Example: ADD AX,BX
MOV SUM, AX
Directives
● This is a statement that gives directions to the assembler.
● Sometimes directives are called pseudo-ops (“pseudo operations”).
● Directives are not translated into machine language; however, they are
necessary for your program to assemble properly.
● Example: SUM DB 1
(Tells assembler to set aside 1 byte of memory and give it to the name SUM)
CSEG SEGMENT
(Tells assembler to start a segment named CSEG)
The Format of Assembly Language Statements
General Guidelines on writing and assembly language program
1. Each line can contain only one statement
2. A statement may begin anywhere on the line
3. Uppercase or lowercase letters may be used. Distinction is only made within
single or double quotes as in “Hello”

Instructions and directives have a more structured format. Each of these type of
statements has up to three parts: a name, an opcode and an operand. These three parts
must always be in this proper order and must be separated by at least one space or tab.
Example:
Name Opcode Operand Comment

SETUP MOV DX, OFFSET MESSAGE ; setup DX

Col 1 Col 9 Col 17 Col 41

Rules for Specifying Names


Names are symbols that you choose to represent various addresses in your program.
You must specify a name according to the following rules:
1. Names use letters, digits(0-9) and special characters ? @ _ $
2. The first character of a name must always be a letter. No numbers for first
characters to enable the assembler to distinguish numbers from names.
3. The @ character is always used for special purposes and may not be used as
first character for names
4. Names are considered until 31 characters long.
5. Avoid using Reserved names as identifier names to avoid compiler confusion.
Reserved names are the opcodes for all the instructions and directives, and the
names of the registers.

Examples:
HELLO $MARKET A12345 LONG_NAME PART_3

Rules for Specifying Numbers


Numbers that can be used in Assembly are decimal, hexadecimal and binary.
For decimal, use digits 0-9 straightforward
Example: MOV AX, 855

For hexadecimal, use digits 0-9 and letters A-F (upper or lower case) making note that
the letter “H” should always be added at the end of the digit.
Example: MOV AX, 855H

For binary, use digits 0 and 1 and make note to add the letter “B” at the end of the digit.
Example: MOV AX,01101001011B

Registers
General Registers (AX,BX,CX,DX)
These registers offer convenient temporary storage for any type of information.
However they all have special purposes.

AX is the principal register used by arithmetic instructions(although all general


registers can be used). It is often used to accumulate the results of calculation. For this
reason, it is sometimes called accumulator.
BX (along with BP) is sometimes called base register because it can be used to
hold a base address.
CX is used with certain instructions that perform operations repeatedly. In such
cases, CX must contain the number of times you want to repeat the operations. Thus
CX is referred to as count register.
DX is sometimes called data register because it is used to hold data for general
purpose.
Alternate names for General Registers
2-Byte Names 1-Byte Names
AX AH, AL
BX BH, BL
CX CH, CL
DX DH, DL

Using The H and L for the alternate names which stand for “high” and “low”

Register Names, Abbreviations and Functions.

Directives for Building Programs


The following directives are called “DOT Directives”

Directive Purpose
.MODEL Specify the memory model
.STACK Setup the Stack
.DATA Setup a data segment
defines the beginning of the data segment
.CODE Setup a code segment
ends the data segment and starts code segment
.STARTUP Generate start up instructions for the main program
.EXIT Generate exit instructions for the main program
Model Choices:
TINY SMALL MEDIUM COMPACT LARGE HUGE FLAT

Types of Data used in Assembly

The following are Building Blocks Used to Define Data Items


Building Block Size (in bytes)
BYTE 1
WORD 2
DWORD 4
QWORD 8
TBYTE 10

The Define Data Directives


Directive Type Description
DB BYTE byte, also read as “define bytes”
DW WORD word, also read as “define words”
DD DWORD doubleword, also read as “define doublewords”
DQ QWORD quadword, also read as “define quadwords”
DT TBYTE 10 bytes, also read as “define 10 bytes”

Range of numbers that can be stored in Data Items


Type of number Allowable Range
Byte
Unsigned 0 to 255
Signed -127 to 128
Word
Unsigned 0 to 65535
Signed -32768 to 32767
Double Word
Signed -2147483648 to 2147483647
Floating Point positive and negative: 10-38 to 1038
Quadruple Word
Signed -922337203685477808 to 922337203685477807
Floating Point positive and negative: 10-308 to 10308
Ten Bytes
Floating Point positive and negative: 10-4932 to 104932
Signed -999999999999999999 to 99999999999999999

Five Attributes of Data Items Operators


TYPE + add
LENGTH - subtract
SIZE * multiply
SEG / divide
OFFSET MOD modulo

Processing and Linking an Assembly Program

These are the steps in processing a program:


ASSEMBLY LINKING EXECUTION

File extensions used in processing and linking a program


Extension Meaning Extension Meaning
ASM Source Program OBJ Object Module
CRF Cross Reference Information MAP Map
EXE Executable Program REF Cross Reference Report
LIB Library LST Listing

Interrupts

Terms:
Interrupt
An interrupt is a signal that an event has occurred which requires immediate attention.
Interrupt Handler
A procedure that does whatever is necessary when an interrupt occurs.
Interrupt Vector
A number that identifies a specific interrupt.
Hardware Interrupt
An interrupt that originates from a hardware service, also called external interrupt.
Software Interrupt
An interrupt that originates from a program that is executing, also called internal
interrupt.

How interrupts are used in a program


The following is the general format for using interrupt
INT interrupt-vector
These are the different interrupt vectors being used:

Vector Purpose
05H Copies contents of the screen to printer or print the screen
18H Stops DOS and executes the simple version of BASIC that is stored in
ROM, usually this is called switching to cassette basic
19H Reboots the computer
20H Terminate assembly program and give control back to DOS
This interrupt vector has the same purpose are the opcode RET
which means to Return either to jump to an address/function specified or
simply return to DOS
21H General interrupt, used to request DOS function calls

Você também pode gostar