0% found this document useful (0 votes)
3 views9 pages

Lab 14 Mehwish

The document outlines an assembly language lab experiment focused on constructing procedures and macros. It provides learning outcomes, required software, and detailed explanations of procedures and macros, including their definitions, syntax, and examples. Additionally, it includes exercises for students to practice creating macros for various tasks.

Uploaded by

sb1911612
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)
3 views9 pages

Lab 14 Mehwish

The document outlines an assembly language lab experiment focused on constructing procedures and macros. It provides learning outcomes, required software, and detailed explanations of procedures and macros, including their definitions, syntax, and examples. Additionally, it includes exercises for students to practice creating macros for various tasks.

Uploaded by

sb1911612
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/ 9

Mehran University of Engineering & Technology, Jamshoro

Department of Telecommunication Engineering


BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14
Name: ______Mehwish Naz____________________ Roll No. 23bscys003 Score:

Submission Date: Signature of the Lab Tutor:

LAB Subject Data analysis Ability to


PERFORMANCE knowledge and conduct
INDICATOR interpretation experiment
OBTAINED

TO CONSTRUCT PROCEDURES, AND MACROS IN ASSEMBLY LANGUAGE

Learning Outcomes:
After this experiment, the understudy will be able to
• explain the basic concepts of procedures and macros in assembly language.
• understand the syntax of procedure declaration in assembly language.
• write simple programs in assembly language using procedure and macros structures.
Required Software:
• DOSBOX, MASM, Link or EMU 8086
Introduction
Procedures
In assembly language, a procedure is a block of code designed to perform a specific task and can be called
from multiple points in a program. Procedures help organize code into smaller, more manageable pieces,
making complex programs easier to develop and maintain. They are also known as subroutines or functions in
other programming contexts. A typical procedure begins with a label and ends with the ret (return) instruction,
which transfers control back to the calling part of the program. Procedures are invoked using the call
instruction, which saves the return address on the stack before jumping to the procedure. This ensures that
when the procedure finishes, the ret instruction retrieves the return address from the stack and resumes
execution at the correct point in the main program.
Procedures in assembly language promote code reusability, modularity, and maintainability. By allowing the
same code to be used in multiple places, procedures reduce duplication and make modifying or updating parts
of a program easier without affecting other sections. This structure not only enhances the clarity of the code
but also simplifies debugging and future maintenance.
How to Use Procedures
Procedures are defined using the syntax mentioned below. The name of the procedure can be any name instead
of any reserved word or other rules that are considered in assembly language programming when naming a
label structure.
Name proc
; Instructions
for procedure
(any)
Ret
Name endp
When calling any procedure, it is done so by calling it in the main program of the code. Thus for this reason
call and ret instructions are used. Call instruction is used to call any procedure in main program while the return
instruction is used to return from a procedure to the main program.

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14
.model small
.stack 100h
.data
.code main
proc call Name
main endp

Name proc
; Instructions
ret
Name endp
End main
Program Example 1:
Write a program that display three strings each on new line using procedure.

Program Example 2:
Write a program with procedures for user input and print the entered character.

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14

Macros
In assembly language, macros are powerful constructs that allow programmers to define reusable blocks of
code, which can be inserted into a program wherever needed. A macro is essentially a template that consists of
a sequence of instructions and can take arguments to make it flexible. Unlike procedures, macros are expanded
directly into the source code during assembly, which means that the code within a macro is substituted at every
point where the macro is invoked, potentially increasing the size of the code but reducing the overhead of
procedure calls. This makes macros ideal for small, frequently used code snippets where performance is
critical, as no jumps or return instructions are needed.
Macros are defined using the macro directive, followed by the macro name and its optional parameters. When
invoked, the assembler replaces the macro call with the corresponding block of code, including any arguments
passed to it. This makes them a useful tool for simplifying complex operations, ensuring code reusability, and
improving readability.
However, macros should be used judiciously since their repetitive expansion can lead to larger code sizes.
Unlike functions or procedures, macros do not offer the benefit of code modularity since they are expanded
inline rather than being called. Despite this, macros provide a convenient way to automate repetitive tasks and
avoid writing the same code multiple times, especially in scenarios where inline expansion is more efficient
than procedure calls.
Thus, the macro is defined as a block of code that can be used with input parameters anywhere in the program
with a name. It is a function to handle code statements that are required for multiple parameters operation.
How to use Macros
In assembly language, macros can be defined as using the following syntax.
Name macro
;Instructions
endm
The name used for the macros should follow the same rules that are defined while writing a label name which
include no reserved words and other rules
Program Example
Write a program to print a string using the macros syntax.

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14

Program Example 2
Write a macro named COMPARE that takes two numbers and prints "Equal" if they are equal or
"Not
Equal" otherwise. compare db 'Equal$'
macro num1, num2 mov not_equal_msg
ax, num1 mov bx, db 'Not Equal$'
num2 cmp ax, bx
je equal .
; Not Equal case mov dx, c
offset not_equal_msg jmp o
print_msg d
e
equal: mov dx, offset m
equal_msg a
i
print_msg: n
mov ah, 09h int p
21h r
endm o
c
.model small mov ax,
.stack 100h @data
.data equal_msg mov ds, ax
Prepared By: Engr. Rohma Qadir
Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14
n
co t
m 2

pa 1
re h
5, m
1 a
0 i
n
m e
o n
v d
a p
h e
, n
4 d
c m
h a
i
i n

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14

Exercise
1. Define a macro CHECK_EVEN that takes a number in AX and prints "Even" if it’s even or "Odd" if
it’s odd.
SOLUTION:

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14
2. Create a macro SET_REGS that accepts two parameters and moves them into AX and BX,
respectively.
SOLUTION:

3. Create a macro FIND_MAX that takes two registers, compares them, and stores the larger value in
AX.
SOLUTION:

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14
4. Write a macro named ADD_TWO that takes two arguments and stores their sum in a register. Call
this macro with different register pairs and print the results.
SOLUTION:

Prepared By: Engr. Rohma Qadir


Mehran University of Engineering & Technology, Jamshoro
Department of Telecommunication Engineering
BS In Cyber Security (23BSCYS)
4th Semester, 2nd Year
Computer Organization and Assembly Language (CSC220) Lab
Experiment No # 14

OUTPUT:

Prepared By: Engr. Rohma Qadir

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy