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

Addition

The document contains multiple assembly language programs demonstrating various operations such as addition, subtraction, and factorial calculation of 16-bit numbers, as well as string manipulation including palindrome checking and displaying strings. Each program is structured with a .model, .data, and .code section, and uses DOS interrupts for input and output. The programs illustrate basic programming concepts in assembly language and provide examples of loops, conditionals, and arithmetic operations.

Uploaded by

Dattaraj Naik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Addition

The document contains multiple assembly language programs demonstrating various operations such as addition, subtraction, and factorial calculation of 16-bit numbers, as well as string manipulation including palindrome checking and displaying strings. Each program is structured with a .model, .data, and .code section, and uses DOS interrupts for input and output. The programs illustrate basic programming concepts in assembly language and provide examples of loops, conditionals, and arithmetic operations.

Uploaded by

Dattaraj Naik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

Average of elements of array


.MODEL small
.STACK 100h
.DATA
ary1 DW 4, 1, 3, 2
sum DW 0
r DB ?
q DB ?

Subtraction of two 16 bit numbers .CODE


.model small main PROC
.stack 100h mov ax, @data
.data mov ds, ax
.code lea si, ary1
main PROC mov cx, 4
mov ax, @data
mov ds, ax l1:
mov bl, 3 mov ax, [si]
mov cl, 1 add sum, ax
sub bl, cl add si, 2
mov dl, bl loop l1
add dl, 48 mov ax, sum
mov ah, 2 xor dx, dx
int 21h mov bx, 4
mov ax, 4C00h div bx
int 21h mov q, al
main ENDP mov r, ah
end main mov dl, al
mov ah, 2
int 21h
mov ah, 4Ch
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

Checking if a string is palindrome or not


.model small
.stack 100h
.data
Entering a string and displaying it without 09h string db 'abba', '$'
.model small string1 db 'string is palindrome', '$'
.data string2 db 'string is not palindrome', '$'
var1 db 100 dup('$')
.code .code
main PROC main proc far
mov ax, @data mov ax, @data
mov ds, ax mov ds, ax
mov si, offset var1 call palindrome
mov ah, 4ch
l1: int 21h
mov ah, 1 main endp
int 21h palindrome proc
cmp al, 13 mov si, offset string
je programend loop1:
mov [si], al mov ax, [si]
inc si cmp al, '$'
jmp l1 je label1
inc si
jmp loop1
programend: label1:
mov si, offset var1 mov di, offset string
next_char: dec si
mov dl, [si] loop2:
cmp dl, '$' cmp si, di
je done jl output1
mov ah, 02h mov ax, [si]
int 21h mov bx, [di]
inc si cmp al, bl
jmp next_char jne output2
dec si
done: inc di
mov ah, 4Ch jmp loop2
int 21h output1:
main ENDP lea dx, string1
end main 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