0% found this document useful (0 votes)
28 views

Addition of Two 16 Bit Numbers

The document contains multiple assembly language programs for basic operations such as addition, subtraction, string manipulation, calculating averages, checking for palindromes, finding factorials, and displaying Fibonacci series. Each program is structured with a small model, data segment, and code segment, demonstrating various functionalities using interrupts and registers. The programs are designed to run in a DOS environment using INT 21h for input and output operations.

Uploaded by

Dattaraj Naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Addition of Two 16 Bit Numbers

The document contains multiple assembly language programs for basic operations such as addition, subtraction, string manipulation, calculating averages, checking for palindromes, finding factorials, and displaying Fibonacci series. Each program is structured with a small model, data segment, and code segment, demonstrating various functionalities using interrupts and registers. The programs are designed to run in a DOS environment using INT 21h for input and output operations.

Uploaded by

Dattaraj Naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Addition of two 16 bit numbers

.model small
.stack 100h
.data
.code
main PROC
mov ax, @data
mov ds, ax
mov bl, 3
mov cl, 1
add bl, cl
mov dl, bl
add dl, 48
mov ah, 2
int 21h
mov ax, 4C00h
int 21h
main ENDP
end main

Subtraction of two 16 bit numbers


.model small
.stack 100h
.data
.code
main PROC
mov ax, @data
mov ds, ax
mov bl, 3
mov cl, 1
sub bl, cl
mov dl, bl
add dl, 48
mov ah, 2
int 21h
mov ax, 4C00h
int 21h
main ENDP
end main

Entering a string and displaying a string using 09h


.model small
.data
var1 db 100 dup('$')
.code
main PROC
mov ax, @data
mov ds, ax
mov si, offset var1
l1: mov ah, 1
int 21h
cmp al, 13
je programend
mov [si], al
inc si
jmp l1
programend: mov dx, offset var1
mov ah, 09h
int 21h
mov ah, 4Ch
int 21h
main ENDP
end main

Entering a string and displaying it without 09h


.model small
.data
var1 db 100 dup('$')
.code
main PROC
mov ax, @data
mov ds, ax
mov si, offset var1
l1:
mov ah, 1
int 21h
cmp al, 13
je programend
mov [si], al
inc si
jmp l1

programend:
mov si, offset var1
next_char:
mov dl, [si]
cmp dl, '$'
je done
mov ah, 02h
int 21h
inc si
jmp next_char

done:
mov ah, 4Ch
int 21h
main ENDP
end main
Average of elements of array
.MODEL small
.STACK 100h
.DATA
ary1 DW 4, 1, 3, 2
sum DW 0
r DB ?
q DB ?

.CODE
main PROC
mov ax, @data
mov ds, ax
lea si, ary1
mov cx, 4

l1:
mov ax, [si]
add sum, ax
add si, 2
loop l1
mov ax, sum
xor dx, dx
mov bx, 4
div bx
mov q, al
mov r, ah
mov dl, al
mov ah, 2
int 21h
mov ah, 4Ch
int 21h
main ENDP
END main
Checking if a string is palindrome or not
.model small
.stack 100h
.data
string db 'abba', '$'
string1 db 'string is palindrome', '$'
string2 db 'string is not palindrome', '$'

.code
main proc far
mov ax, @data
mov ds, ax
call palindrome
mov ah, 4ch
int 21h
main endp
palindrome proc
mov si, offset string
loop1:
mov ax, [si]
cmp al, '$'
je label1
inc si
jmp loop1
label1:
mov di, offset string
dec si
loop2:
cmp si, di
jl output1
mov ax, [si]
mov bx, [di]
cmp al, bl
jne output2
dec si
inc di
jmp loop2
output1:
lea dx, string1
mov ah, 09h
int 21h
ret
output2:
lea dx, string2
mov ah, 09h
int 21h
ret
palindrome endp
end main
Find the Factorial
.Model small
.STACK 100h

.data
n dw 5
result db 0

.code
main PROC
mov ax, @data
mov ds, ax
mov cx, n
mov ax, 1

@fact:
mul cx
loop @fact

mov bx, 10
xor cx, cx

convert_to_string:
xor dx, dx
div bx
push dx
inc cx
test ax, ax
jnz convert_to_string
print_digits:
pop dx
add dl, '0'
mov ah, 2
int 21h
loop print_digits

mov ah, 4ch


int 21h
main endp
end main

Display Fibonacci series


.model small
.stack 100h
.data
newline db 0Dh, 0Ah, '$'
.code
main PROC
mov ax, @data
mov ds, ax

mov ax, 0
mov bx, 1
mov cx, 8

print_fib:
mov dx, ax
mov bx, 10
xor cx, cx

convert:
xor dx, dx
div bx
push dx
inc cx
test ax, ax
jnz convert
print_loop:
pop dx
add dl, '0'
mov ah, 02h
int 21h
loop print_loop
mov ah, 09h
lea dx, newline
int 21h
add ax, bx
xchg ax, bx
loop print_fib
mov ah, 4ch
int 21h
main endp
end main

You might also like