Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello! Please fix my code. I need to generate an array counts which holds the number of times each value in the range [ LO
Hello! Please fix my code. I need to generate an array counts which holds the number of times each value in the range LO HI for default constant values is seen in randArray, even if the number of times a value is seen is zero.
For example with LO counts should equal the number of instances of the value in array. counts should equal the number of instances of the value in randArray. Note that some value may appear zero times and should be reported as zero instances.
I then need to display the array counts, numbers per line with one space between each value. My code prints out $ signs instead of the array counts. Please fix it so that it prints out the array counts. I have attached a screenshot of my output and below is my code:
INCLUDE Irvineinc
; Constants
ARRAYSIZE
LO
HI
data
intro BYTE "Generating, Sorting, and Counting Random integers!
intro BYTE "Programmed by Mayaal Khan",
intro BYTE "This program generates random numbers in the range
BYTE and displays the original list, sorts the list,
BYTE "displays the median value, displays the list sorted in
BYTE "ascending order, then displays the number of instances
BYTE of each generated value.",
unsort BYTE "Your unsorted random numbers:
sort BYTE "Your sorted random numbers:",
medianIntro BYTE "This median value of array:
spaces BYTE
cList BYTE "Your list of instances of each generated number, starting with the smallest value:
goodbye BYTE "Goodbye, and thanks for using my program!",
randArray DWORD ARRAYSIZE DUP
countArray DWORD HI LO DUP
code
main PROC
call Randomize
; Introduction
push OFFSET intro
push OFFSET intro
push OFFSET intro
call introduction
call CrLf
; Fill the array
push OFFSET randArray
push ARRAYSIZE
push HI
push LO
call fillArray
call CrLf
; Display title of unsorted array
push OFFSET unsort
call displayTitle
call CrLf
; Display the unsorted list
push OFFSET randArray
push ARRAYSIZE
push OFFSET spaces
call displayArray
call CrLf
call CrLf
; Sort the array
push OFFSET randArray
push ARRAYSIZE
call sortList
; Display title of median
push OFFSET medianIntro
call displayTitle
; Display median
push OFFSET randArray
push ARRAYSIZE
call displayMedian
call CrLf
call CrLf
; Display title of sorted array
push OFFSET sort
call displayTitle
call CrLf
; Display sorted list
push OFFSET randArray
push ARRAYSIZE
push OFFSET spaces
call displayArray
call CrLf
; Display title for counted list
push OFFSET cList
call displayTitle
call CrLf
; Count the items in list and store them in countArray
push OFFSET randArray
push OFFSET countArray
push ARRAYSIZE
call countList
; Display the counted array
push OFFSET countArray
push HI LO ; Push the size of the counted array
push OFFSET spaces
call displayCountedArray
call CrLf
call CrLf
; Display goodbye message
push OFFSET goodbye
call farewell
exit ; exit to operating system
main ENDP
;
;introduces the program
;receives: addresses of intro, intro and intro
;registers changed: ebp, edx
;
introduction PROC
push ebp
mov ebp, esp
mov edx, ebp
call WriteString
call CrLf
mov edx, ebp
call WriteString
call CrLf
call CrLf
mov edx, ebp
call WriteString
call CrLf
pop ebp
ret
introduction ENDP
;
;fills the array with random numbers, within a specified range
;receives: address of array, array's size, low and high bounds
;registers changed: ebp, ecx, eax
;
fillArray PROC
push ebp
mov ebp, esp
mov esi, ebp ; address of array
mov ecx, ebp ; arraySize
getNumber:
; generate a random number within our range
mov eax, ebp ; hi
sub eax, ebp ; lo
inc eax
call RandomRange
add eax, ebp ; lo
; store the random number in our next array position
mov esi eax
add esi,
loop getNumber
pop ebp
ret
fillArray EdisplayTitle PROC
push ebp
mov ebp, esp
mov edx, ebp ; whichever string we pushed in main
call WriteString
pop ebp
ret
displayTitle ENDP
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started