You are on page 1of 15

INTRODUCTION

ASSEMBLY LANGUAGE

12/12/2020 1
Assembly Language Syntax
• An assembly language program consists of statements.

• The syntax of an assembly language program statement obeys


the following rules:

12/12/2020 2
RULES
Only one statement is written per line

Each statement is either an instruction or an assembler directive

instruction
translated into machine code

assembler directive
 instructs the assembler to perform some specific task

12/12/2020 3
Operation Field
For an instruction

• This field consists of a symbolic operation code, known as


opcode

• The opcode describes the operation’s function

• Symbolic opcodes are translated into machine language


opcode.

12/12/2020 4
Operation Field
For an assembler directive

• This field consists of a pseudo-operation code (pseudo-op)

• pseudo-ops tell assembly to do something

• Not converted into machine code

• Eg. PROC (to create a procedure)

12/12/2020 5
Comment Field
• A semicolon marks the beginning of a comment

• A semicolon in the beginning of a line makes it all a comment


line

• Good programming practice dictates the use of a comment on


almost every line.

12/12/2020 6
Key rules for the use of comments

• Do not say something that is obvious

• Put instruction in context of program

12/12/2020 7
Comment Field
Examples of good and bad Comments

MOV CX , 0 ; Move 0 to CX (This is not a good


comment.)
MOV CX , 0 ; CX counts terms, initially set to 0
(This is a good comment.)

12/12/2020 8
Numbers
• Binary number is written as a bit string followed by the letter `b`.

• Decimal number is written as a string of decimal digits followed by the


letter `d`.

• Hex number is written as a string of hex digits followed by the letter `h`.

• Hex number must begin with a decimal digit (to differentiate between ABCH – a variable name
or hex number ABC)

• Numbers may have an optional sign

12/12/2020 9
Numbers
Examples:

number type
1010 decimal
1010B binary
-2134D decimal
ABFFH illegal
0ABFFH hex
1BHH illegal
1BFFH hex
1,23 illegal

12/12/2020 10
Characters
• Characters and character segments must be enclosed in single or double quotes;
‘A' , “hello“.

• Assembler translates characters to their ASCII code

• So there is no difference between using ‘A’ and 41h in a program

12/12/2020 11
Variables
Declaring Integer Variables:

• An integer is a whole number, such as 4 or 4444. Integers have no


fractional part. Integer variables can be initialized in several ways

with the data allocation directives .

12/12/2020 12
Variables
Allocating Memory for Integer Variables:
• When an integer variable is declared, the assembler allocates memory space for
the variable. The variable name becomes a reference to the memory space
allocated to that variable.

12/12/2020 13
Syntax

name directive initializer initial value

12/12/2020 14
Variables
Pseudo-op type size range
• DB unsigned 1 byte 0 to 255.
signed 1 byte -128 to +127.
• DW unsigned 2 bytes 0 to 65,535.
signed 2 bytes -32,768 to +32,767.
• DD unsigned 4 bytes 0 to 4,294,967,295 (4 Mbytes).
signed 4 bytes -2,147,483,648 to +2,147,483,647.
• DQ 8-byte integer 4 consecutive words
• DT 10-byte integer 10 consecutive bytes

12/12/2020 15

You might also like