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

Assembly Language Basic Programs

Uploaded by

awaissaqiaspire1
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 views5 pages

Assembly Language Basic Programs

Uploaded by

awaissaqiaspire1
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 Programs

1. Write a program to add two numbers.


section .data
num1 db 5
num2 db 10
result db 0

section .text
global _start
_start:
mov al, [num1]
add al, [num2]
mov [result], al
mov eax, 1
int 0x80

2. Write a program to subtract two numbers.


section .data
num1 db 15
num2 db 5
result db 0

section .text
global _start
_start:
mov al, [num1]
sub al, [num2]
mov [result], al
mov eax, 1
int 0x80

3. Write a program to multiply two numbers.


section .data
num1 db 4
num2 db 3
result dw 0

section .text
global _start
_start:
mov al, [num1]
mov bl, [num2]
mul bl
mov [result], ax
mov eax, 1
int 0x80

4. Write a program to divide two numbers.


section .data
num1 db 20
num2 db 4
quotient db 0
remainder db 0

section .text
global _start
_start:
mov al, [num1]
mov bl, [num2]
div bl
mov [quotient], al
mov [remainder], ah
mov eax, 1
int 0x80

5. Write a program to find the factorial of a number.


section .data
num db 5
result dw 1

section .text
global _start
_start:
mov cx, [num]
mov ax, 1
factorial:
mul cx
loop factorial
mov [result], ax
mov eax, 1
int 0x80

6. Write a program to find the largest of two numbers.


section .data
num1 db 8
num2 db 12
largest db 0

section .text
global _start
_start:
mov al, [num1]
cmp al, [num2]
jg num1_larger
mov al, [num2]
num1_larger:
mov [largest], al
mov eax, 1
int 0x80

7. Write a program to check if a number is even or odd.


section .data
num db 7
result db 'Even', 0

section .text
global _start
_start:
mov al, [num]
and al, 1
jz is_even
mov [result], 'Odd'
is_even:
mov eax, 1
int 0x80

8. Write a program to swap two numbers.


section .data
num1 db 15
num2 db 25
section .text
global _start
_start:
mov al, [num1]
mov bl, [num2]
xchg al, bl
mov [num1], al
mov [num2], bl
mov eax, 1
int 0x80

9. Write a program to reverse a string.


section .data
str db 'HELLO', 0
rev db 5 dup(0)

section .text
global _start
_start:
lea si, [str]
lea di, [rev+4]
mov cx, 5
reverse:
lodsb
stosb
loop reverse
mov eax, 1
int 0x80

10. Write a program to calculate the length of a string.


section .data
str db 'ASSEMBLY', 0
length db 0

section .text
global _start
_start:
lea si, [str]
xor cx, cx
count:
lodsb
cmp al, 0
je done
inc cx
jmp count
done:
mov [length], cl
mov eax, 1
int 0x80

You might also like