Professional Documents
Culture Documents
PROGRAMS:
EXP 04 [a]. Write an assembly language program to find largest of the two numbers.
Code:
section .data int 80h
string1 db 'Enter the number 1: ',
string1len equ $-string1 mov eax, 4
string2 db 'Enter the number 2: ', mov ebx, 1
string2len equ $-string2 mov ecx, newline
string3 db 'The largest number is: ', mov edx, newlinelen
string3len equ $-string3 int 80h
newline db '', 10
newlinelen equ $-newline mov eax, 4
mov ebx, 1
section .bss mov ecx, string3
num1 resb 5 mov edx, string3len
num2 resb 5 int 80h
Output:
PROGRAMS:
EXP 04 [b]. Write an assembly language program to find the largest of three numbers.
Code:
section .data mov eax, 4
string1 db 'Enter the number 1: ', mov ebx, 1
string1len equ $-string1 mov ecx, string3
string2 db 'Enter the number 2: ', mov edx, string3len
string2len equ $-string2 int 80h
string3 db 'Enter the number 3: ',
string3len equ $-string3 mov eax, 3
string4 db 'The largest number is: ', mov ebx, 2
string4len equ $-string4 mov ecx, num3
newline db '', 10 mov edx, 5
newlinelen equ $-newline int 80h
mov ebx, 1
mov ecx, num1 N3:
mov edx, 5 mov eax, 4
int 80h mov ebx, 1
mov ecx, num3
jmp L3 mov edx, 5
int 80h
N2:
mov eax, 4 jmp L3
mov ebx, 1
mov ecx, num2 L3:
mov edx, 5 mov eax, 1
int 80h mov ebx, 0
int 80h
jmp L3
Output:
PROGRAMS:
EXP 04 [c]. Write an assembly language program to find the smallest of 2 numbers.
Code:
section .data mov ebx, 1
string1 db 'Enter the number 1: ', mov ecx, string1
string1len equ $-string1 mov edx, string1len
string2 db 'Enter the number 2: ', int 80h
string2len equ $-string2
string3 db 'Enter the number 3: ', mov eax, 3
string3len equ $-string3 mov ebx, 2
string4 db 'The smallest number is: ', mov ecx, num1
string4len equ $-string4 mov edx, 5
newline db '', 10 int 80h
newlinelen equ $-newline
mov eax, 4
section .bss mov ebx, 1
num1 resb 5 mov ecx, string2
num2 resb 5 mov edx, string2len
num3 resb 5 int 80h
Output:
EXP 04 [d]. Write an assembly language program to check if the given number is greater than 5
or lesser than 5.
Nidhi Shanbhag 211105036 |Page
EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23
Code:
section .data L1:
string1 db 'Enter the number: ', mov eax, 4
string1len equ $-string1 mov ebx, 1
string2 db 'The number is greater mov ecx, string2
than 5.', mov edx, string2len
string2len equ $-string2 int 80h
string3 db 'The number is less
than 5.', mov eax, 4
string3len equ $-string3 mov ebx, 1
string4 db 'The number is equal to mov ecx, newline
5.', mov edx, newlinelen
string4len equ $-string4 int 80h
newline db '', 10 jmp L4
newlinelen equ $-newline
L2:
section .bss mov eax, 4
num resb 5 mov ebx, 1
mov ecx, string3
section .text mov edx, string3len
global _start int 80h
EXP 04 [e]. Write an assembly language program to check whether the entered number is even
or odd.
Code:
section .data int 80h
string1 db 'Enter the number: ',
string1len equ $-string1 mov al, [num]
string2 db 'The number is an even number.', sub al, '0'
string2len equ $-string2 mov bl, '2'
string3 db 'The number is not an even sub bl, '0'
number.', DIV bl
string3len equ $-string3 add al, '0'
newline db '', 10 add ah, '0'
newlinelen equ $-newline mov [quo], al
mov [rem], ah
section .bss
num resb 5 mov eax, [rem]
quo resb 5 cmp eax, '0'
rem resb 5 je L1
jne L2
section .text
global _start L1:
mov eax, 4
_start: mov ebx, 1
mov eax, 4 mov ecx, string2
mov ebx, 1 mov edx, string2len
mov ecx, string1 int 80h
mov edx, string1len
int 80h mov eax, 4
mov ebx, 1
mov eax, 3 mov ecx, newline
mov ebx, 2 mov edx, newlinelen
mov ecx, num int 80h
mov edx, 5
int 80h jmp L3
Output:
CONCLUSION:
All the programs were executed successfully.