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

Array Task

This document is an assembly language program that allows users to manage an array of integers. Users can input the size of the array, enter values, and perform various operations such as displaying the array, updating values, and finding the minimum and maximum values. The program includes error handling for invalid inputs and provides a menu-driven interface for user interaction.

Uploaded by

logostride
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Array Task

This document is an assembly language program that allows users to manage an array of integers. Users can input the size of the array, enter values, and perform various operations such as displaying the array, updating values, and finding the minimum and maximum values. The program includes error handling for invalid inputs and provides a menu-driven interface for user interaction.

Uploaded by

logostride
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

.

386
INCLUDE [Link]

.model small
.stack 100h

.data

arr DD 100 dup (?)


arrSize DD ?
pos DD ?
newVal DD ?
min DD 0
max DD 0

msgGetSize DB "How much of array do you want to use? (1-100): " , 0


msgLessSize DB "You cannot use less than one index of array, try again" , 0
msgGreaterSize DB "You cannot use more than 100 indices of array, try
again" , 0

msgEnterArray DB "Enter data in your array: ", 0


msgEnterArrayDone DB "Your data has entered...", 0

msgChoice DB "Enter your choice: ", 0


msgMenu DB "Menu", 0
msgChoice1 DB "1. Display the array", 0
msgChoice2 DB "2. Display the array in reverse order", 0
msgChoice3 DB "3. Update the array", 0
msgChoice4 DB "4. Find the minimum number", 0
msgChoice5 DB "5. Find the maximum number", 0
msgChoice6 DB "6. Quit", 0
msgChoiceInvalid DB "Invalid Choice...", 0

msgQuit DB "Program Quited...",0


msgDisplay DB "Array Data: ", 0
msgDisplayReverse DB "Array Data in reverse order: ", 0
msgSpace DB " ",0

msgPos DB "Enter position to be changed: ", 0


msgInvalidPos DB "Entered position is out of the bound, try again..."
msgNewVal DB "Enter new value: ", 0
msgUpdatedDisplay DB "Updated array: ", 0

msgMin DB "Minimum Number: ", 0


msgMax DB "Maximum Number: ", 0

.code
main proc

GetChoice:
mov edx, offset msgGetSize
call writestring
call readint
call crlf
cmp eax, 0
jle ChoiceLessthan1

cmp eax, 100


jg ChoiceGreaterthan100

jmp isvalidNumber

ChoiceLessthan1:
mov edx, offset msgLessSize
call writestring
call crlf
jmp GetChoice

ChoiceGreaterthan100:
mov edx, offset msgGreaterSize
call writestring
call crlf
jmp GetChoice

isValidNumber:
mov arrSize, eax

GetData:
mov edx, offset msgEnterArray
call writestring
mov ebx, offset arr
mov ecx, arrSize
GetDataLoop:
call readint
mov [ebx], eax
add ebx, 4
loop GetDataLoop

mov edx, offset msgEnterArrayDone


call writestring
call crlf
call crlf

DisplayChoice:
mov edx, offset msgMenu
call writestring
call crlf
mov edx, offset msgChoice1
call writestring
call crlf
mov edx, offset msgChoice2
call writestring
call crlf
mov edx, offset msgChoice3
call writestring
call crlf
mov edx, offset msgChoice4
call writestring
call crlf
mov edx, offset msgChoice5
call writestring
call crlf
mov edx, offset msgChoice6
call writestring
call crlf
mov edx, offset msgChoice
call writestring

call readint
cmp eax, 1
je choice1_Display

cmp eax, 2
je choice2_DisplayReverse

cmp eax, 3
je choice3_Update

cmp eax, 4
je choice4_FindMin

cmp eax, 5
je choice5_FindMax

cmp eax, 6
je choice6_Quit

jmp invalidChoice

invalidChoice:
mov edx, offset msgChoiceInvalid
call writestring
call crlf
jmp DisplayChoice

choice1_Display:
mov edx, offset msgDisplay
call writestring
display:
mov ebx, offset arr
mov ecx, arrSize
DisplayDataLoop:
mov eax, [ebx]
call writeint
mov edx, offset msgSpace
call writestring
add ebx, 4
loop DisplayDataLoop
call crlf
jmp DisplayChoice

choice2_DisplayReverse:
mov edx, offset msgDisplayReverse
call writestring
mov ebx, offset arr
mov eax, 4
mul arrSize
sub eax,4
add ebx, eax
mov ecx, arrSize
DisplayReverseLoop:
mov eax, [ebx]
call writeint
mov edx, offset msgSpace
call writestring
sub ebx, 4
loop DisplayReverseLoop
call crlf
jmp DisplayChoice

choice3_Update:
getPos:
mov edx, offset msgPos
call writestring
call readint
cmp eax, 0
jle invalidPos
cmp eax, arrSize
jg invalidPos
jmp validPos

invalidPos:
mov edx, offset msgInvalidPos
call writestring
call crlf
jmp getPos

validPos:
mov pos, eax
getVal:

mov edx, offset msgNewVal


call writestring
call readint
mov newVal, eax

mov eax, 4
mul pos
sub eax, 4
mov ebx, offset arr
add ebx, eax

mov eax, newVal


mov [ebx], eax

mov edx, offset msgUpdatedDisplay


call writestring
jmp display

choice4_FindMin:
mov ebx, offset arr
mov eax, [ebx]
mov min, eax
mov ecx, arrSize
findMin:
mov eax, [ebx]
cmp min, eax
jg updateMin
jmp updateBase

updateMin:
mov min, eax
updateBase:
add ebx, 4
loop findMin
mov edx, offset msgMin
call writestring
mov eax, min
call writeint
call crlf
jmp DisplayChoice

choice5_FindMax:
mov ebx, offset arr
mov eax, [ebx]
mov max, eax
mov ecx, arrSize
findMax:
mov eax, [ebx]
cmp max, eax
jg updateBaseForMax

mov max, eax

updateBaseForMax:
add ebx, 4
loop findMax
mov edx, offset msgMax
call writestring
mov eax, max
call writeint
call crlf
jmp DisplayChoice

choice6_Quit:
mov edx, offset msgQuit
call writestring
exit

invoke ExitProcess,0
main endp
end main

You might also like