0% found this document useful (0 votes)
7 views7 pages

Assembly Language Practical Programs

The document provides a list of practical assembly language programs, including tasks such as displaying 'Hello World', performing arithmetic operations, and converting between number systems. It includes code snippets for each program, demonstrating various operations like finding the largest number in an array, checking for prime numbers, and generating Fibonacci series. Each program is structured with a model, stack, data, and code sections, showcasing fundamental assembly language concepts.

Uploaded by

rafiqueusman258
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)
7 views7 pages

Assembly Language Practical Programs

The document provides a list of practical assembly language programs, including tasks such as displaying 'Hello World', performing arithmetic operations, and converting between number systems. It includes code snippets for each program, demonstrating various operations like finding the largest number in an array, checking for prime numbers, and generating Fibonacci series. Each program is structured with a model, stack, data, and code sections, showcasing fundamental assembly language concepts.

Uploaded by

rafiqueusman258
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

Assembly language practical programs

1. Hello World display program


2. Addition of two numbers
3. BCD to Binary conversion
4. Binary to BCD conversion
5. ASCII to Integer conversion
6. Find largest number between two numbers
7. Find largest number in an array
8. Find smallest number in an array
9. Count even and odd numbers in an array
10. Swap two numbers (using register / without register)
11. Reverse a string
12. Check whether a number is even or odd
13. Check whether a number is prime or not
14. Factorial of a number
15. Fibonacci series generation
16. Search an element in an array (Linear Search)

1) Hello World Display Program


.model small
.stack 100h

.data
msg db 'Hello World$'

.code
main proc
mov ax, @data
mov ds, ax

mov ah, 09h


lea dx, msg
int 21h

mov ah, 4Ch


int 21h
main endp

end main

2) Addition of Two Numbers


.model small
.stack 100h

.data
num1 db 5
num2 db 3
result db ?

.code
main proc
mov ax, @data
mov ds, ax

mov al, num1


add al, num2
mov result, al

mov ah, 4Ch


int 21h
main endp

end main

3) BCD to Binary Conversion


.model small
.stack 100h
.data
bcd db 25h ; BCD value (25 decimal)
result db ?

.code
main proc
mov ax, @data
mov ds, ax

mov al, bcd


mov ah, al
and al, 0Fh ; lower digit
and ah, F0h ; upper digit
mov cl, 4
shr ah, cl ; shift right

mov bl, 10
mul bl ; AL = lower * 10
add al, ah ; add upper

mov result, al

mov ah, 4Ch


int 21h
main endp
end main

4) Binary to BCD Conversion


.model small
.stack 100h
.data
num db 45 ; binary number (decimal 45)
tens db ?
ones db ?

.code
main proc
mov ax, @data
mov ds, ax

mov al, num


mov bl, 10
div bl ; AL = quotient, AH = remainder

mov tens, al
mov ones, ah

mov ah, 4Ch


int 21h
main endp
end main

5) ASCII to Integer Conversion


.model small
.stack 100h
.data
char db '7'
num db ?

.code
main proc
mov ax, @data
mov ds, ax

mov al, char


sub al, 30h ; convert ASCII to integer

mov num, al
mov ah, 4Ch
int 21h
main endp
end main

6) Largest of Two Numbers


MOV AX, 5
MOV BX, 9

CMP AX, BX
JG AX_LARGER
MOV AX, BX

AX_LARGER:
; AX contains largest number
HLT

7) Largest in Array
MOV SI, OFFSET ARR
MOV CX, 5
MOV AL, [SI]

NEXT:
INC SI
CMP AL, [SI]
JGE SKIP
MOV AL, [SI]

SKIP:
LOOP NEXT

; AL = largest
HLT

ARR DB 3, 9, 2, 15, 7

8) Smallest in Array
MOV SI, OFFSET ARR
MOV CX, 5
MOV AL, [SI]

L1:
INC SI
CMP AL, [SI]
JLE SKIP
MOV AL, [SI]

SKIP:
LOOP L1

HLT
ARR DB 3,9,2,15,7

9) Count Even & Odd


MOV SI, OFFSET ARR
MOV CX, 5
MOV BL, 0 ; even count
MOV BH, 0 ; odd count

NEXT:
MOV AL, [SI]
AND AL, 1
JZ EVEN
INC BH
JMP SKIP

EVEN:
INC BL

SKIP:
INC SI
LOOP NEXT

HLT

ARR DB 1,2,3,4,5

10) Swap Two Numbers


MOV AX, 5
MOV BX, 10

XCHG AX, BX

HLT
11) Reverse String
MOV SI, OFFSET STR
MOV DI, SI
MOV CX, 5
ADD DI, CX
DEC DI

REV:
MOV AL, [SI]
MOV BL, [DI]
MOV [SI], BL
MOV [DI], AL

INC SI
DEC DI
LOOP REV

HLT

STR DB 'HELLO'

12) Even / Odd Check


MOV AX, 6
AND AX, 1
JZ EVEN

HLT

EVEN:
HLT

13) Prime Number Check


MOV AX, 7
MOV BX, 2

L1:
CMP BX, AX
JGE PRIME

MOV DX, 0
DIV BX
CMP DX, 0
JE NOTPRIME

INC BX
JMP L1
PRIME:
HLT

NOTPRIME:
HLT

14) Factorial
MOV CX, 5
MOV AX, 1

L1:
MUL CX
LOOP L1

HLT

15) Fibonacci Series


MOV AX, 0
MOV BX, 1
MOV CX, 5

FIB:
ADD AX, BX
XCHG AX, BX
LOOP FIB

HLT

16) Linear Search


MOV SI, OFFSET ARR
MOV CX, 5
MOV AL, 7

SEARCH:
CMP AL, [SI]
JE FOUND
INC SI
LOOP SEARCH

FOUND:
HLT

ARR DB 3,5,7,9,11

You might also like