Professional Documents
Culture Documents
18 Instructions
LEARNING OUTCOMES
By the end of this topic, you should be able to:
1. List down seven types of basic instructions for an assembly
language program; and
2. Differentiate between immediate addressing, register addressing
and direct addressing.
INTRODUCTION
A assembly language program usually has the basic instructions that will be
explained in this topic. Each basic instruction has its own purpose and there are
seven basic instructions that will be discussed in this topic. These basic
instructions are MOV, XCHG, INC, DEC, ADD, SUB and LOOP. You are
advised to understand these basic purposes to enable you to determine the
suitable time to use these basic instructions.
MOV instruction will copy data from a one operand to another operand. This
operand could be 8 bits or 16 bits.
Example:
Mov al,count
mov bl,al
Mov count, bl
count 02 AL 02 BL 02 count 02
The Value in the count variable is assigned to the AL register. Then the value in
the AL register is assigned into the BL register and finally the value in the BL
register is assigned to the count variable. Finally, the value in all the registers
and the variables involved is 02.
Example:
Array db 1h,2h,3h,4h
Array +0 +1 +2 +3
1h 2h 3h 4h
Example of instruction:
The XCHG instruction will exchange the values of two registers and variables.
The syntax is as below:
xchg op1,op2
One of the operands must be a register. The other operand can be a register and
memory location.
xchg ax,bx
xchg ah,al
xchg variable,bx
Example:
mov Al ,value1 1
xchg Al ,value 2
mov Value1 ,al
.
.
.
; data segment
value1 db 0ah
value2 db 14h
154 TOPIC 18 BASIC INSTRUCTIONS
mov al,value1:
Meaning: value1=0ah will be assigned to the AL register. As we
know, the AL register can only store 8 bits.
xchg al,value2:
Meaning: value1 and value2 will exchange their positions and this
will cause AL register to store value2 whereas variable value2
will store value1, which was previously from the AL register
mov value1,al:
Meaning: the current value of AL will be assigned to value1. This
changes the current value of value1 to value2.
ACTIVITY 18.2
Perform a comparison between MOV and XCHG instructions.
inc destination
dec destination
The size of the Destination Operand would be 8 bits or 16 bits, and it can be a
register or variable that represents memory location.
The usage of INC and DEC instructions are more efficient compared to the
addition (ADD) and subtraction (SUB) instructions.
Example:
inc ax
dec al
TOPIC 18 BASIC INSTRUCTIONS 155
INC and DEC instructions are used for addition and subtraction. In
your opinion, what are the differences between these instructions and
the ADD and SUB instructions?
The usage of these instructions depends on the condition that the source operand
and destination operand should be of the same size. The following are the
example of syntaxes:
Example:
add al,1
sub ax,1
add cl,al
sub ax,bx
156 TOPIC 18 BASIC INSTRUCTIONS
ACTIVITY 18.4
SELF-CHECK 18.2
The loop instructions used in a high-level language are far and while.
How about the Assembly language?
Loop destination
Example:
mov cx, 5
start:
.
.
.
loop start
TOPIC 18 BASIC INSTRUCTIONS 157
In this example, start is a label used to show the beginning of a loop. The
statement
loop start
will cause the loop instruction to repeat the steps and the value in CX register to
be reduced by 1. This repetition will occur until the CX value equals to 0.
SELF-CHECK 18.3
In the previous example, how many times has the loop been
executed?
You have learned all the seven basic instructions in an assembly language
program. Now you should able to differentiate each instruction based on the
function and determine when to use these instructions in a program.