You are on page 1of 9

Computer Organization and

Assembly Language
Subroutines
BScs 5th
Lecturer Hashim Javed
objectives
• Procedure
• Example program of procedure
What is procedure?
First of all there must be a question if you want to print the 3 strings
then what you will do like

Hello? Mov dx,10


Mov ah,2
How are you? Int 21h

Good to see you Mov dx,13


Moh ah,2
Int 21h
Procedure/subroutine/Functions
They have similar meaning in Assembly language

A subroutine is a sequence of instructions which is a logical


unit. Subroutines are also called procedures or functions. Their original
and main purpose is to reduce the amount of code which must be
repetitively written for a program. This makes assembly language
programming easier and faster
Definition
It is just a block of code that can be called anywhere in the program
with the name

So why do need it?


Reusability
Reduce complexity
Now the Question?
How to use procedures?

• Syntax
Name proc
ret
Name endp

Name=name of the procedure


Proc=procedure
Ret=Return
Write a procedure for using the
Escape Sequences???
EscapeSeq proc
Mov dx,10
Mov ah,2
Int 21h

Mov dx,13
Mov ah,2
Int 21h
Ret
Escapeseq proc
How to call a procedure
Simple with the help of CALL keyword with the procedure name
For example
In the previous example we have created the escapeseq procedure if
we want the call that procedure
Then simple we will write that procedure like this

CALL escapeseq (Before or after the instructions)

You might also like