0% found this document useful (0 votes)
4 views8 pages

Lab Manual 4 (1)

The document provides an overview of assembler directives, constants, and identifiers used in computer architecture and organization. It explains the purpose of directives, various data declaration formats, named constants, and reserved words, along with guidelines for creating identifiers. Additionally, it includes exercises for practical application of the concepts discussed.

Uploaded by

syedamenahil206
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)
4 views8 pages

Lab Manual 4 (1)

The document provides an overview of assembler directives, constants, and identifiers used in computer architecture and organization. It explains the purpose of directives, various data declaration formats, named constants, and reserved words, along with guidelines for creating identifiers. Additionally, it includes exercises for practical application of the concepts discussed.

Uploaded by

syedamenahil206
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
You are on page 1/ 8

​ Computer Architecture & Organization ​ Department of Computer Science &

Information Technology

Lab # 04

Assembler Directives, Constants & Identifiers


Directives:

A directive is a command embedded in the source code that is recognized and acted upon by the
assembler. Directives do not execute at runtime. Directives can define variables, macros, and
procedures. They can assign names to memory segments and perform many other housekeeping
tasks related to the assemble or assembler directive is a message to the assembler that tells the
assembler something it needs to know in order to carry out the assembly process; for example, an
assemble directive tells the assembler where a program is to be located in memory.

Data Declarations:

The default number system used by the assembler is decimal. Using other number systems
entail appropriate suffixes as shown below:

Number System Suffix

Binary B

Hexadecimal H

Octal O or Q

Decimal None

Table 1
A hexadecimal value must start with a digit. For example, code 0a8h rather than a8h to get
a constant with value A816. The assembler will interpret a8h as a name.
Some Assembler Directives:

Pseudo-op Stands for

DB
define byte
DW define word

DD define double word (two consecutive words)

DQ define quad word (four consecutive words)

DT
define ten bytes (five consecutive words.
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

Byte Variables
Assembler directive format assigning a byte variable
​ Name DB ​ initial value

A question mark (“?”) place in initial value leaves variable uninitialized

I​ DB ​ 4​ ;define variable I with initial value 4


J​ DB ​ ?​ ;Define variable J with uninitialized value
​ Name ​ DB ​ "Course" ​ ;allocate 6 bytes for name
K​ DB ​ 5, 3,-1 ​;allocate 3 bytes

Other data type variables have the same format for defining the variables like:
​ Name ​ DW ​ initial value

Named Constants

•​ EQU pseudo-op used to assign a name to constant.


•​ Makes assembly language easier to understand.
•​ No memory allocated for EQU names.

LF ​ EQU 0AH
o MOV DL, 0AH

o MOV DL, LF
PROMPT ​ EQU "Type your name"

o MSG DB ​ “Type your name”

o MDC DB ​ PROMPT

Integer Constants

An integer constant (or integer literal) is made up of an optional leading sign, one or more
digits, and an optional suffix character (called a radix ) indicating the number‟s base:

[{+ | -}] digits [radix]

Radix may be one of the following (uppercase or lowercase), If no radix is given, the
integer constant is assumed to be decimal. (Refer table 1 for radix examples)
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

Character Constants

A character constant is a single character enclosed in single or double quotes.


Examples are 'A', "d".

String Constants

A string constant is a sequence of characters (including spaces) enclosed in single or


double quotes: “ABC' , "Good night, Gracie” etc.

Reserved Words

Reserved words have special meaning in Assembler and can only be used in their correct context.
There are different types of reserved words:

•​Instruction mnemonics, such as MOV, ADD, and MUL


•​Register names
•​Directives, which tell Assembler how to assemble programs
•​Attributes, which provide size and usage information for variables and operands. Examples
are BYTE and WORD
•​Operators, used in constant expressions

Identifiers

An identifier is a programmer-chosen name. It might identify a variable, a constant, a


procedure, or a code label. Keep the following in mind when creating identifiers:

•​They may contain between 1 and 247 characters.


•​They are not case sensitive.
•​The first character must be a letter (A..Z, a..z), underscore (_), @ , ?, or $. Subsequent
characters may also be digits.
•​An identifier cannot be the same as an assembler reserved word.
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

P-1
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

EXERCISE:
Q1. Refer to p-1, assemble the program and examine the listing file. Determine the opcode
and size of each instruction inside the main procedure.
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

Q2. Refer to p-1, examine the listing file and determine how many bytes reserved by each
constant/ variable also determine the address range occupied by each variable.

Q3. Find the values that the assembler will generate for each of the directives below. Write
your answer using two hex digits for each byte generated.

Q4. Write an assembly language program to swap numbers stored at value1 and value2.
Assume value1 is last-digit-of-roll# and value2 is second-last-digit-of-your-roll
​ Computer Architecture & Organization ​ Department of Computer Science &
Information Technology

Q5 Write down the code to generate following output using DB.


C
A
O

You might also like