0% found this document useful (0 votes)
15 views21 pages

Chap 4 Asm

Uploaded by

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

Chap 4 Asm

Uploaded by

dejenehundaol91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

More in assembly language

instruction
Comparisons
The CMP Instruction

The CMP instruction compares two operands.

It is generally used in conditional execution.

This instruction basically subtracts one


operand from the other for comparing
whether the operands are equal or not.
CMP…
It is used along with the conditional jump
instruction for decision making.
SYNTAX
CMP destination, source
CMP compares two numeric data fields.
The destination operand could be either in
register or in memory.
The source operand could be a constant
(immediate) data, register or memory.
CMP…
Example on CMP
Procedure(PROC)
Procedure Definition
Large problems can be divided into smaller tasks to
make them more manageable
A procedure is the ASM equivalent of a Java or C++
function
PROC is a statement used to indicate the beginning
of a procedure or subroutine.
 ENDP indicates the end of the procedure
PROC…
PROC…

ProcedureName may be any valid identifier.


Attribute is NEAR if the Procedure is in the same
code segment as the calling program; or FAR if in a
different code segment.
PROC…
The procedure is called from another function by
using the CALL instruction.
The CALL instruction should have the name of
the called procedure as argument as shown
below:
CALL proc_name
PROC…
When you create a procedure other than your
program’s startup procedure, end it with a RET
instruction.
RET forces the CPU to return to the location from
where the procedure was called:
Example on proc
Nested Procedure Calls

 A nested procedure call occurs when a called


procedure calls another procedure before the
first procedure returns.
 Suppose that main calls a procedure named
Sub1.
 While Sub1 is executing, it calls the Sub2
procedure.
 While Sub2 is executing, it calls the Sub3
procedure.
The loop instructions

The LOOP instruction, formally known as Loop


According to ECX Counter, repeats a block of
statements a specific number of times.
ECX is automatically used as a counter and is
decremented each time the loop repeats
Loop…
Its syntax is
LOOP destination
The execution of the LOOP instruction involves two
steps: First, it subtracts 1 from ECX.
Next, it compares ECX to zero.
If ECX is not equal to zero, a jump is taken to the
label identified by destination.
Otherwise, if ECX equals zero, no jump takes place,
and control passes to the instruction following the
loop.
Loop…
In the following example, we add 1 to AX each
time the loop repeats. When the loop ends,
• AX 5 and ECX 0:
• mov ax,0
• mov ecx,5
• L1:
• inc ax
• loop L1
Example on loop
Branching instructions

In branching instructions the control of


program is transferred from one location
to another location based on some
condition
Example on Branch instruction
Jz –jump if zerp

You might also like