0% found this document useful (0 votes)
619 views18 pages

UNIT 5 - Procedure and MACRO

This document discusses procedures and macros in assembly language programs. It provides examples of programs that use procedures to perform operations like finding the smallest number in an array or counting the number of 1s in a binary number. It also gives an example of a program that uses a macro to compute squares in order to calculate y=a^2 + b^2 + c^2.

Uploaded by

compstudent2024
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)
619 views18 pages

UNIT 5 - Procedure and MACRO

This document discusses procedures and macros in assembly language programs. It provides examples of programs that use procedures to perform operations like finding the smallest number in an array or counting the number of 1s in a binary number. It also gives an example of a program that uses a macro to compute squares in order to calculate y=a^2 + b^2 + c^2.

Uploaded by

compstudent2024
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/ 18

UNIT V: Assembly Language Program using

Procedure and MACRO

What is Procedure?
Program : Write an ALP addition, subtraction, multiplication and division using
Procedure

Program: Write an ALP using procedure to solve equation such as Z =

(A+B) * (C+D)
OUTPUT:
Program: Write an ALP to find Smallest number from the array of 10 numbers
using procedure

CODE:

.MODEL SMALL

.DATA

ARRAY DW 134H,130H,65H,55H,84H,32H,110H,976H,88H,20H

SMALL_NUM DW 0

.CODE

MOV AX,@DATA

MOV DS,AX

CALL SMALLEST

MOV SMALL_NUM,AX

MOV AH,4CH

INT 21H

SMALLEST PROC

MOV CX,5

MOV SI,OFFSET ARRAY

MOV AX,[SI]

DEC CX

UP: INC SI

INC SI
CMP AX,[SI]

JC NEXT

MOV AX,[SI]

NEXT:

LOOP UP

RET

ENDP

ENDS

END

Program: Write an ALP to count number of ‘1’s in 8-bit number using

procedure

CODE:

.model small

.data

msg db 10,13, "Number of ones in the binary number is: $"

count db ?

.code

Proc1 proc

mov ax, @data

mov ds, ax

; Input 8-bit number

mov ah, 01h

int 21h ; DOS input


mov bl, al ; move input to bl register

; Call procedure to count '1's

call countOnes

; Display the result

mov dl, count ; move count to dl register

add dl, 30h ; convert count to ASCII

mov ah, 02h

int 21h ; DOS display

mov ah, 4Ch

int 21h ; DOS exit

proc1 endp

; Procedure to count '1's in an 8-bit number

countOnes proc

mov count, 0 ; Initialize count to 0

mov cl, 8 ; Initialize loop counter

countLoop:

shr bl, 1 ; Shift right to check each bit

jnc notSet ; Jump if carry flag is not set (bit is 0)

inc count ; Increment count if bit is 1

notSet:

loop countLoop ; Continue looping until all bits are checked

ret
countOnes endp

end
 What is Macro?
Program : Write an ALP addition, subtraction, multiplication and division.
Program: Write an ALP using MACRO to solve equation such as Z = (A+B)*(C+D).
OUTPUT:
Program: Write an ALP to perform Y = 𝑎2 + 𝑏2 + 𝑐2 using macro to
compute square.

CODE:

.model small

Sqr_num macro Num1, sqr

MOV AL, Num1

MUL Num1

MOV sqr, AX

ENDM

.DATA

A DB 03H

B DB 04H

C DB 10H

SA DW ?

SB DW ?

SC DW ?

P DW ?

.CODE

MOV DX,@DATA

MOV DS,DX

SQR_NUM A,SA

SQR_NUM B,SB
SQR_NUM C,SC

MOV AX,SA

MOV AX,SB

MOV AX,SC

MOV P,AX

ENDS

END

You might also like