Professional Documents
Culture Documents
MPMC EXP 08 Code & Output Print
MPMC EXP 08 Code & Output Print
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
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
Output:
EXP 08[c]. Write an assembly language program to count number of odd and even numbers in an
array.
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
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
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