You are on page 1of 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