Assembly Language Programming
Assembly Language Programming
Assembly Language Programming
The text section: The text section is used for keeping the actual
code. This section must begin with the declaration global main, which tells
the kernel where the program execution begins.
The syntax for declaring text section is:
section .text
global main
Main:
Assembly Basic Syntax
Comments:
Assembly language comment begins with a semicolon (;). It may
contain any printable character including blank. It can appear
on a line by itself, like:
; This program displays a message on screen
or, on the same line along with an instruction, like:
add eax ,ebx ; adds ebx to eax
Assembly Language Statements
Assembly language programs consist of three types of statements :
1. Executable instructions or instructions
2. Assembler directives or pseudo-ops
3. Macros
The executable instructions or simply instructions tell the
processor what to do. Each instruction consists of an operation
code (opcode). Each executable instruction generates one
machine language instruction. The assembler directives or
pseudo-ops tell the assembler about the various aspects of the
assembly process. These are non-executable and do not
generate machine language instructions.
Macros are basically a text substitution mechanism.
Syntax of Assembly Language Statements
Assembly language statements are entered one statement
per line. Each statement follows the following format:
[label] mnemonic [operands] [;comment]
The fields in the square brackets are optional. A
basic instruction has two parts, the first one is the
name of the instruction (or the mnemonic) which
is to be executed, and the second are the
operands or the parameters of the command.
Following are some examples of typical assembly
language statements:
Syntax of Assembly Language Statements
Symbols / Labels
Symbols:
– Symbols are used as labels, constants, and substitution values
– Symbols are stored in a symbol table
– A symbol name l
i is a string of up to 200 alphanumeric characters (A-Z, a-z, 0-9,
$, and _)
ii cannot contain embedded blanks
iii first character cannot be a number
iv case sensitive
– Symbols used as labels become symbolic addresses that are
associated with locations in the program
Label Field
Labels are symbols
– Labels must begin in column 1.
– A label can optionally be followed by a colon
– The value of a label is the current value of the
Location Counter (address within program)
– A label on a line by itself is a valid statement
– Labels used locally within a file must be
unique
Performance: C Versus Assembly Language
Now let us write programs in assembly language. As an
example, consider multiplying two 16-bit integers. Our
strategy is to write the multiplication procedure in C (a
representative of high-level language) and in the
Pentium assembly language and compare their
execution times.