Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

EXPERIMENT NO: 8 ARRAYS Date:29/05/23

PROGRAMS:
EXP 08[a]. Write an assembly language program to enter elements in an array and display its
contents.

Code
section .data int 80h
string1 db 'Enter the number of
elements to be inserted in array: ' mov eax,4
string1len equ $-string1 mov ebx,1
string2 db 'Enter the elements: ',10 mov ecx,string2
string2len equ $-string2 mov edx,string2len
string3 db 'The array is: ' int 80h
string3len equ $-string3
newline db ' ',10 mov eax,[num]
newlinelen equ $-newline mov [i],eax
tab db ' '
tablen equ $-tab mov esi,array
mov eax,num
;array declaration and initialization
array dw 0,0,0,0,0,0,0,0,0 input_element:
arraylen equ 9 ; static array count mov eax,3
mov ebx,2
section .bss mov ecx,element
num resb 9 mov edx,2
element resb 9 int 80h
i resb 9
mov ebx,[element]
section .text mov [esi],ebx
global _start
dec byte[num]
_start: inc esi
mov eax,4
mov ebx,1 cmp byte[num],'0'
mov ecx,string1 jne input_element
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,9
int 80h mov eax,4
mov ebx,1
mov eax,4 mov ecx,string3
mov ebx,1 mov edx,string3len
mov ecx,newline int 80h
mov edx,newlinelen

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 8 ARRAYS Date:29/05/23

mov esi,array int 80h


mov eax,i
dec byte[i]
display_element: inc esi
mov eax,[esi]
mov [element],eax cmp byte[i],'0'
jne display_element
mov eax,4
mov ebx,1 mov eax,4
mov ecx,element mov ebx,1
mov edx,1 mov ecx,newline
int 80h mov edx,newlinelen
int 80h
mov eax,4
mov ebx,1 mov eax,1
mov ecx,tab mov ebx,0
mov edx,tablen int 80h

Output:

EXP 08[b]. Write an assembly language program to count number of positive and negative
numbers in an array.

Code:
section .data negative_count dw 0 ;negative number
count
string1 db 'Count the number of positive
and negative numbers in the array', 10 section .bss
string1len equ $-string1 dis_buffer resb 2
string2 db 'Positive Count: '
string2len equ $-string2
section .text
string3 db 'Negative Count: '
global _start
string3len equ $-string3
string4 db 'The array is: '
;HEX to ASCII procedure
string4len equ $-string4
HEX_ASCII:
newline db ' ',10
mov ecx,2
newlinelen equ $-newline
mov edi,dis_buffer
DUP: rol bl,04
;array declaration and initialisation
mov al,bl
array dw 10,-21,45,12,-25,43,78,96,-89
and al,0fh
array_count equ 9 ;static array count
cmp al,09h
positive_count dw 0 ;positive number
jbe NEXT
count
Nidhi Shanbhag 211105036 |Page
EXPERIMENT NO: 8 ARRAYS Date:29/05/23

add al,07h PSKIP: inc esi


NEXT: add al,30h inc esi
mov[edi],al loop UP
inc edi
loop DUP ;positive count message
mov eax,4
;display count mov ebx,1
mov eax,4 mov ecx,string2
mov ebx,1 mov edx,string2len
mov ecx,dis_buffer int 80h
mov edx,2
int 80h mov bl,[positive_count]
RET call HEX_ASCII
_start:
mov eax,4 mov eax,4
mov ebx,1 mov ebx,1
mov ecx,string4 mov ecx,newline
mov edx,string4len mov edx,newlinelen
int 80h int 80h

mov edx,arraylen ;negative count message


mov ecx,array mov eax,4
mov ebx,1 mov ebx,1
mov eax,4 mov ecx,string3
int 80h mov edx,string3len
int 80h
mov eax,4
mov ebx,1 mov bl,[negative_count]
mov ecx,string1 call HEX_ASCII
mov edx,string1len
int 80h mov eax,4
mov ebx,1
;initialising array start address mov ecx,newline
mov esi,array mov edx,newlinelen
mov ecx,array_count int 80h
UP:BT word[esi],15
JC NCXT mov eax,1
inc byte[positive_count] mov ebx,0
JMP PSKIP int 80h
NCXT: inc byte[negative_count]

Output:

EXP 08[c]. Write an assembly language program to count number of odd and even numbers in an
array.

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 8 ARRAYS Date:29/05/23

Code:
section .data mov ebx,1
string1 db 'Enter the number of elements mov ecx,string2
to be inserted in array: ' mov edx,string2len
string1len equ $-string1 int 80h
string2 db 'Enter the elements: ',10
string2len equ $-string2 mov eax,'0'
string3 db 'The number of elements which mov [even],eax
are odd: ',
string3len equ $-string3 mov eax,'0'
string4 db 'The number of elements which mov [odd],eax
are even: ',
string4len equ $-string4 mov eax,[num]
newline db ' ',10 mov [i],eax
newlinelen equ $-newline
tab db ' ' mov esi,array
tablen equ $-tab mov eax,num

;array declaration and initialization inputelement:


mov eax,3
mov ebx,2
array dw 0,0,0,0,0,0,0,0,0 mov ecx,element
arraylen equ 9 ; static array count mov edx,2
int 80h
section .bss
num resb 9 mov bx,[element]
element resb 9 mov [esi],bx
i resb 9
odd resb 9 dec byte[num]
even resb 9 inc esi
rem resb 9
cmp byte[num],'0'
section .text jne inputelement
global _start

_start: mov esi,array


mov eax,4 mov eax,i
mov ebx,1
mov ecx,string1 checkevenodd:
mov eax,[esi]
mov [element],eax
mov edx,string1len
int 80h mov eax,4
mov ebx,1
mov eax,3 mov ecx,''
mov ebx,2
mov ecx,num
mov edx,9 mov edx,0
int 80h int 80h

mov eax,4 mov al,[element]

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 8 ARRAYS Date:29/05/23

sub al,'0' mov eax,4


mov bl,'2' mov ebx,1
sub bl,'0' mov ecx,even
div bl mov edx,9
add ah,'0' int 80h
add al,'0'
mov [rem],ah mov eax,4
mov ebx,1
mov eax,[rem] mov ecx,newline
mov ebx,'0' mov edx,newlinelen
cmp eax,ebx int 80h
je EVEN
jne ODD mov eax,4
mov ebx,1
EVEN: mov ecx,string3
inc byte[even]
jmp CMP
mov edx,string3len
ODD: int 80h
inc byte[odd]
jmp CMP mov eax,4
mov ebx,1
CMP: mov ecx,odd
dec byte[i] mov edx,9
inc esi int 80h

cmp byte[i],'0' mov eax,4


jne checkevenodd mov ebx,1
mov ecx,newline
mov eax,4 mov edx,newlinelen
mov ebx,1 int 80h
mov ecx,string4
mov edx,string4len mov eax,1
int 80h mov ebx,0
int 80h

Output:

EXP 08[d]. Write an assembly language program to numbers in array above and below 50.
Code:
Nidhi Shanbhag 211105036 |Page
EXPERIMENT NO: 8 ARRAYS Date:29/05/23

section .data
string1 db 'Enter the number of elements to be mov eax,4
inserted in array: ' mov ebx,1
string1len equ $-string1 mov ecx,string2
string2 db 'Enter the elements: ',10 mov edx,string2len
string2len equ $-string2 int 80h
string3 db 'The number of elements above 50
are ', mov eax,[num]
string3len equ $-string3 mov [i],eax
string4 db 'The number of elements below 50
are ', mov esi,array
string4len equ $-string4 mov eax,num
newline db ' ',10
newlinelen equ $-newline input_element:
tab db ' ' mov eax,3
tablen equ $-tab mov ebx,2
mov ecx,element
;array declaration and initialization mov edx,2
array dw 0,0,0,0,0,0,0,0,0 int 80h
arraylen equ 9 ; static array count

section .bss mov ebx,[element]


num resb 9 mov [esi],ebx
element resb 9
i resb 9 dec byte[num]
above resb 9 inc esi
below resb 9
cmp byte[num],'0'
section .text jne input_element
global _start
mov eax,4
_start: mov ebx,1
mov eax,4 mov ecx,newline
mov ebx,1 mov edx,newlinelen
int 80h

mov ecx,string1 mov esi,array


mov edx,string1len mov eax,i
int 80h
mov byte[above],'0'
mov eax,3 mov byte[below],'0'
mov ebx,2
mov ecx,num ABOVE_BELOW:
mov edx,9 mov eax,[esi]
int 80h mov [element],eax

mov eax,4 mov al,[element]


mov ebx,1 mov bl,'5'
mov ecx,newline cmp al,bl
mov edx,newlinelen jl LESS
int 80h jg GREATER

Nidhi Shanbhag 211105036 |Page


EXPERIMENT NO: 8 ARRAYS Date:29/05/23

mov eax,4
LESS: mov ebx,1
inc byte[below] mov ecx,newline
jmp CMP mov edx,newlinelen
int 80h
GREATER:
inc byte[above] mov eax,4
jmp CMP mov ebx,1
mov ecx,string4
CMP: mov edx,string4len
dec byte[i] int 80h
inc esi
mov eax,4
cmp byte[i],'0' mov ebx,1
jne ABOVE_BELOW mov ecx,below
mov edx,9
mov eax,4 int 80h
mov ebx,1
mov ecx,string3 mov eax,4
mov edx,string3len mov ebx,1
int 80h mov ecx,newline
mov edx,newlinelen
mov eax,4 int 80h
mov ebx,1
mov ecx,above mov eax,1
mov edx,9 mov ebx,0
int 80h int 80h

Output:

Conclusion:
All programs were executed successfully

Nidhi Shanbhag 211105036 |Page

You might also like