0% found this document useful (0 votes)
19 views15 pages

Chapter 4 Overview of Assembly Language - Part1

Uploaded by

mohammadfuzarif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views15 pages

Chapter 4 Overview of Assembly Language - Part1

Uploaded by

mohammadfuzarif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OVERVIEW OF ASSEMBLY

LANGUAGE
CHAPTER 4
ASSEMBLY LANGUAGE STATEMENTS

• Assembly language programs are created out of three different classes of


statements.
• Statementsin the first class tell the processor what to do. These statements are
called executable instructions, or instructions. Each executable instruction consists
of an operation code (opcode for short). Executable instructions cause the
assembler to generate machine language instructions.
• The second class of statements provides information to the assembler on various
aspects of the assembly process. These instructions are called assembler
directives or pseudo-ops. Assembler directives are nonexecutable and do not
generate any machine language instructions.
ASSEMBLY LANGUAGE STATEMENTS

• The last class of statements, called macros, are used as a shorthand notation for
a group of statements. Macros permit the assembly language programmer to
name a group of statements and refer to the group by the macro name.

• During the assembly process, each macro is replaced by the group of statements
that it represents and assembled in place. This process is referred to as macro
expansion.
ASSEMBLY LANGUAGE STATEMENTS

• All three classes of the assembly language statements use the same format:
[label] mnemonic [operands] [;comment]
• The fields in the square brackets are optional in some statements. The fields in
a statement must be separated by at least one space or tab character. The
assembler does not care about spaces between the fields.
• The label in the executable instruction is followed by a colon (:) but not in the
directive statement
DATA ALLOCATION

• In the assembly language, allocation of storage space is done by the define


assembler directive.
• The define directive can be used to reserve and initialize one or more bytes.
However, no interpretation.
• The general format of the storage allocation statement for initialized data is
[variable-name] define-directive initial-value [,initial-value],· ·
• The square brackets indicate optional items. The variable-name is used to
identify the storage space allocated.
DATA ALLOCATION

• The define directive takes one of the five basic forms:


• DB Define Byte ; allocates 1 byte
• DW Define Word ; allocates 2 bytes
• DD Define Doubleword ; allocates 4 bytes
• DQ Define Quadword ; allocates 8 bytes
• DT Define Ten Bytes ; allocates 10 bytes
DATA ALLOCATION

• To reserve space for uninitialized data, we use RESB, RESW, and so on. Each
reserve directive takes a single operand that specifies the number of units of
space (bytes, words, . . .) to be reserved. There is a reserve directive for each
define directive.
• RESB Reserve a Byte
• RESW Reserve a Word
• RESD Reserve a Doubleword
• RESQ Reserve a Quadword
• REST Reserve Ten Bytes
DATA ALLOCATION

• Multiple Definitions
• Assembly language programs typically contain several data definition
statements. When several data definition statements are used as above, the
assembler allocates contiguous memory for these variables.
• Multiple data definitions can be abbreviated (example from book).
• The TIMES directive allows multiple initializations to the same value.
The TIMES
directive is useful in defining arrays and tables. Using TIMES, the marks array
can be defined as
marks TIMES 8 DW 0
DATA ALLOCATION

• Symbol Table
• When we allocate storage space using a data definition directive, we usually
associate a symbolic name to refer to it. The assembler, during the assembly
process, assigns an offset value for each symbolic name.
• the assembler assigns contiguous memory space for the variables. The
assembler also uses the same ordering of variables that is present in the
source code (example from book).
ADDRESSING MODE

• Assembly language programs can be thought of as consisting of two logical


parts: data and code. Most assembly language instructions require operands.
There are several ways to specify the location of the operands. These are
called the addressing modes.
• An operand required by an instruction may be in any one of the following
locations:
• in a register internal to the processor;
• in the instruction itself;
• in main memory (usually in the data segment);
• at an I/O port
REGISTER ADDRESSING MODE

• In this addressing mode, processor’s internal registers contain the data to be


manipulated by the instruction. For example,

mov EAX,EBX
• Notethat The contents of EBX are not destroyed and the original contents of
EAX are lost.
• Register-addressing mode is the most efficient way of specifying data because
the data are within the processor and, therefore, no memory access is required.
IMMEDIATE ADDRESSING MODE

• In this addressing mode, data are specified as part of the instruction itself. As
a result, even though the data are in memory, it is located in the code
segment, not in the data segment.

mov AL, 75
• Inthis case, this mode can only specify the source operand. In addition, the
immediate data are always a constant
DIRECT ADDRESSING MODE

• Operands specified in a memory-addressing mode require access to the main


memory, usually to the data segment.
• In the direct addressing mode, the offset value is specified directly as part of
the instruction. In an assembly language program, this value is usually
indicated by the variable name of the data item.
• Theassembler will translate this name into its associated offset value during
the assembly process. To facilitate this translation, the assembler maintains a
symbol table.
INDIRECT ADDRESSING MODE

• In this addressing mode, the offset or effective address of the data is in one
of the general registers. For this reason, this addressing mode is sometimes
referred to as the register indirect addressing mode.
• The indirect addressing mode is not required for variables having only a
single element. But for variables like table1 containing several elements.
• the starting address of the data structure can be loaded into a register and
then the register acts as a pointer to an element in table1. By manipulating
the contents of the register, we can access different elements of table1.
THE MOV INSTRUCTION

• The MOV instruction has two operands and has the syntax as follows
mov destination, source
• The data are copied from source to destination and the source operand remains
unchanged. Both operands should be of the same size. The mov instruction can
take one of the following five forms:
• mov register, register
• mov register, immediate
• mov memory, Immediate
• mov register, memory
• mov memory, register

You might also like