Answered step by step
Verified Expert Solution
Link Copied!

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]([15,50] for default constant values) is seen in randArray, even if the number of times a value is seen is zero.
For example with LO=15, counts[0] should equal the number of instances of the value `15` in array. counts[14] should equal the number of instances of the value `29` 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, 20 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 Irvine32.inc
; Constants
ARRAYSIZE =200
LO =15
HI =50
.data
intro BYTE "Generating, Sorting, and Counting Random integers! ",0
intro2 BYTE "Programmed by Mayaal Khan", 0
intro3 BYTE "This program generates 200 random numbers in the range "
BYTE "15 and 50, 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.", 0
unsort BYTE "Your unsorted random numbers: ",0
sort BYTE "Your sorted random numbers:", 0
medianIntro BYTE "This median value of array: ",0
spaces BYTE "",0
cList BYTE "Your list of instances of each generated number, starting with the smallest value: ",0
goodbye BYTE "Goodbye, and thanks for using my program!", 0
randArray DWORD ARRAYSIZE DUP(?)
countArray DWORD HI - LO +1 DUP(?)
.code
main PROC
call Randomize
; Introduction
push OFFSET intro
push OFFSET intro2
push OFFSET intro3
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 +1 ; 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, intro2 and intro3
;registers changed: ebp, edx
;------------------------------------------------------
introduction PROC
push ebp
mov ebp, esp
mov edx, [ebp+16]
call WriteString
call CrLf
mov edx, [ebp+12]
call WriteString
call CrLf
call CrLf
mov edx, [ebp+8]
call WriteString
call CrLf
pop ebp
ret 12
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+20] ; address of array
mov ecx, [ebp+16] ; arraySize
getNumber:
; generate a random number within our range
mov eax, [ebp+12] ; hi
sub eax, [ebp+8] ; lo
inc eax
call RandomRange
add eax, [ebp+8] ; lo
; store the random number in our next array position
mov [esi], eax
add esi, 4
loop getNumber
pop ebp
ret 16
fillArray EdisplayTitle PROC
push ebp
mov ebp, esp
mov edx, [ebp+8] ; (whichever string we pushed in main)
call WriteString
pop ebp
ret 4
displayTitle ENDP
;----------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Define offboarding. Why is it important?

Answered: 1 week ago