You are on page 1of 7

EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

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

section .text mov eax, [num1]


global _start cmp eax, [num2]
jg L1
_start: jl L2
mov eax, 4
mov ebx, 1 L1:
mov ecx, string1 mov eax, 4
mov edx, string1len mov ebx, 1
int 80h mov ecx, num1
mov edx, 5
mov eax, 3 int 80h
mov ebx, 2
mov ecx, num1 jmp L3
mov edx, 5
int 80h L2:
mov eax, 4
mov eax, 4 mov ebx, 1
mov ebx, 1 mov ecx, num2
mov ecx, string2 mov edx, 5
mov edx, string2len int 80h
int 80h
jmp L3
mov eax, 3
mov ebx, 2 L3:
mov ecx, num2 mov eax, 1
mov edx, 5 mov ebx, 0
int 80h

Output:

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

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

section .bss mov eax, 4


num1 resb 5 mov ebx, 1
num2 resb 5 mov ecx, newline
num3 resb 5 mov edx, newlinelen
int 80h
section .text
global _start mov eax, 4
mov ebx, 1
_start: mov ecx, string4
mov eax, 4 mov edx, string4len
mov ebx, 1 int 80h
mov ecx, string1
mov edx, string1len mov eax, [num1]
int 80h cmp eax, [num2]
jg L1
mov eax, 3 jl L2
mov ebx, 2
mov ecx, num1 L1:
mov edx, 5 mov eax, [num1]
int 80h cmp eax, [num3]
jg N1
mov eax, 4 jl N3
mov ebx, 1
mov ecx, string2 L2:
mov edx, string2len mov eax, [num2]
int 80h cmp eax, [num3]
jg N2
mov eax, 3 jl N3
mov ebx, 2
mov ecx, num2 jmp L3
mov edx, 5
int 80h N1:
mov eax, 4

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

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

section .text mov eax, 3


global _start mov ebx, 2
mov ecx, num2
_start: mov edx, 5
mov eax, 4 int 80h
Nidhi Shanbhag 211105036 |Page
EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

cmp eax, [num3]


mov eax, 4 jl N2
mov ebx, 1 jg N3
mov ecx, string3
mov edx, string3len jmp L3
int 80h
N1:
mov eax, 3 mov eax, 4
mov ebx, 2 mov ebx, 1
mov ecx, num3 mov ecx, num1
mov edx, 5 mov edx, 5
int 80h int 80h

mov eax, 4 jmp L3


mov ebx, 1
mov ecx, newline N2:
mov edx, newlinelen mov eax, 4
int 80h mov ebx, 1
mov ecx, num2
mov eax, 4 mov edx, 5
mov ebx, 1 int 80h
mov ecx, string4
mov edx, string4len jmp L3
int 80h
N3:
mov eax, [num1] mov eax, 4
cmp eax, [num2] mov ebx, 1
jl L1 mov ecx, num3
jg L2 mov edx, 5
int 80h
L1:
mov eax, [num1] jmp L3
cmp eax, [num3]
jl N1 L3:
jg N3 mov eax, 1
mov ebx, 0
L2: int 80h
mov eax, [num2]

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

_start: mov eax, 4


mov eax, 4 mov ebx, 1
mov ebx, 1 mov ecx, newline
mov ecx, string1 mov edx, newlinelen
mov edx, string1len int 80h
int 80h jmp L4

mov eax, 3 L3:


mov ebx, 2 mov eax, 4
mov ecx, num mov ebx, 1
mov edx, 5 mov ecx, string4
int 80h mov edx, string4len
int 80h
mov eax, 4
mov ebx, 1 mov eax, 4
mov ecx, newline mov ebx, 1
mov edx, newlinelen mov ecx, newline
int 80h mov edx, newlinelen
int 80h
mov al, [num] jmp L4
cmp al, '5'
jg L1 L4:
jl L2 mov eax, 1
je L3 mov ebx, 0
int 80h
Output:

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

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

mov eax, 4 L2:


mov ebx, 1 mov eax, 4
mov ecx, newline mov ebx, 1
mov edx, newlinelen mov ecx, string3

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 4 JUMP AND COMPARISON INSTRUCTIONS Date:01/05/23

mov edx, string3len


int 80h jmp L3

mov eax, 4 L3:


mov ebx, 1 mov eax, 1
mov ecx, newline mov ebx, 0
mov edx, newlinelen int 80h
int 80h

Output:

CONCLUSION:
All the programs were executed successfully.

Nidhi Shanbhag 211105036 |Page

You might also like