Question

Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...

Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives:

1. using register indirect addressing
2. passing parameters
3. generating “random” numbers
4. working with arrays

Description: Write and test a MASM program to perform the following tasks:

1. Introduce the program.
2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200. HINT: Use Irvine’s “RandomRange” and “Randomize” and code from the textbook/slides to generate each random number.
3. Display the list of integers before sorting, 20 numbers per line with two spaces between each value.
4. Sort the list in ascending order (i.e., smallest first). Do not use any textbook-provided sorts.
5. Calculate and display the median value, rounded to the nearest integer.
6. Display the sorted list, 20 numbers per line with two spaces between each value.
7. Generate an array counts which holds the number of times each value [10, 29] is seen in array. For example, counts[0] should equal the number instances of the value ‘10’ in array. counts[14] should equal the number of instances of the value ‘24’ in array.
8. Display the array counts, 20 numbers per line with two spaces between each value.

Requirements
1. The title, programmer's name, and brief instructions must be displayed on the screen.
2. LO, HI,and ARRAYSIZE must be declared and used as global constants.
3. Strings must be passed by reference.
4. The program must be constructed using procedures. At least the following procedures are required:
A. main
B. introduction {parameters: string1 (reference), string2 (reference), ..)
C. fillArray {parameters: array (reference), LO (value), HI (value), ARRAYSIZE (value)}
D. sortList {parameters: array (reference), ARRAYSIZE (value)} i. exchangeElements (for most sorting algorithms): {parameters: array[i] (reference), array[j] (reference), where i and j are the indexes of elements to be exchanged}
E. displayMedian {parameters: array (reference), ARRAYSIZE (value)}
F. displayList {parameters: someArray (reference), ARRAYSIZE (value), someTitle (reference)}
G. countList {parameters: array (reference), ARRAYSIZE (value), list (reference), LO (value), ...}
5. Parameters must be passed on the system stack by value or by reference as noted above.
6. There must be just one procedure to display arrays. This procedure must be called three times: once to display the unsorted array, once to display the sorted array, and once to display counts.
7. All lists must be identified when they are displayed (use the title parameter for the displayList procedure).
8. Procedures (except main) should not reference .data segment variables by name. request, array, counts, and titles for the sorted/unsorted lists should be declared in the .data segment, but procedures must have them passed by reference. Procedures may use local variables when appropriate. Global constants must only be used in main.
9. The program must use register indirect addressing for array elements.
10. The program must be fully documented. This includes a complete header block for the program (in your own words) and for each procedure, and a comment outline to explain each section of code.
11. The code and the output must be well-formatted.

Example: Sorting and Counting Random integers! Programmed by Charles This program generates 200 random numbers in the range [10 ... 29], displays the original list, sorts the list, displays the median value, displays the list sorted in ascending order, then displays the number of instances of each generated value.
Your unsorted random numbers:
11 24 18 19 26 10 19 15 11 20 16 21 21 19 24 18 12 10 19 20
12 13 13 21 13 21 15 20 28 24 28 14 16 20 28 21 29 24 11 19
24 13 22 19 20 10 12 13 13 15 13 26 27 24 17 17 27 21 21 18
15 15 24 25 13 17 26 27 29 27 27 15 29 18 20 21 23 20 12 13
22 15 19 20 22 18 13 16 20 22 15 23 18 22 12 29 18 18 12 24
20 14 16 14 18 18 14 22 18 11 12 21 15 16 21 21 29 13 26 16
17 15 13 21 10 20 12 24 28 10 18 18 19 28 20 26 23 15 16 16
13 22 28 24 24 12 23 15 24 12 18 24 22 15 19 23 13 27 16 24
29 15 24 28 18 23 28 21 16 23 22 10 24 12 20 16 25 17 25 12
23 22 18 15 23 16 13 24 12 13 24 24 14 15 19 13 25 18 28 13

List Median: 19
Your sorted random numbers:
10 10 10 10 10 10 11 11 11 11 12 12 12 12 12 12 12 12 12 12
12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13
13 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15
15 15 16 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 18
18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 19
19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 21
21 21 21 21 21 21 21 21 21 21 21 21 22 22 22 22 22 22 22 22
22 22 23 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24 24 24 25 25 25 25 26 26 26 26 26 27
27 27 27 27 27 28 28 28 28 28 28 28 28 28 29 29 29 29 29 29


Your list of instances of each generated number, starting with the number of 10s:
6 4 13 18 5 16 12 5 17 10 13 13 10 9 19 4 5 6 9 6

Goodbye, and thanks for using my program!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The whole code is being answered using the C Programming Language. The complete code is given below with comments to help the student get better insights of the program.

#include <stdio.h>
#include<stdlib.h>
#include<time.h>// to use the rand() and srand() function

#define lo 10
#define hi 29
#define size 200

void fill_array(int a[],int l,int r,int n)
{
int i;
  
for(i=0;i<n;i++)
{
int num=(rand()%(r-l+1))+l;
a[i]=num;
}
  
}

void displayList(int a[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(20%i==0)
printf("\n");

printf("%2d",a[i]);
  
}
}

void sortList(int a[],int n)
{
int i,j,swap;
  
for (i=0;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (a[j] > a[j+1])
{
swap = a[j];
a[j] = a[j+1];
a[j+1]= swap;
}
}
}
  
}

void displayMedian(int a[],int n)
{
int median=0;
  
// if number of elements are even
if(n%2 == 0)
median = (a[(n-1)/2] + a[n/2])/2;
// if number of elements are odd
else
median = a[n/2];
  
printf("\n The median of the given array is: %d",median);
}

void countList(int a[],int l,int h,int n)
{
int i,j=0,count=0;
int b[20]; //to store the count of elements occuring
int c=a[0];
for(i=0;i<n;i++)
{
if(a[i]==c)
{
count++;
}
else
{
b[j]=count;// to store the count of the first m similar elements at the jth index
count=1;//to store the count of the next element wich has come now so count=1 has been made
c=a[i];// store the next element for checking
j++;
}
}
  
displayList(b,20);
}


int main()
{
  
int a[size];// declaring array of size='200'
srand(time(0)); // using this function so that the list of random numbers generated is different each time the code is executed
  
printf("\n Calling the fill array function:");
fill_array(a,lo,hi,size);
  
printf("\n The array before sorting is:");
displayList(a,size);
  
printf("\n Sorting the input array:");
sortList(a,size);
  
printf("\n Calculating the median of the given array:");
displayMedian(a,size);
  
printf("\n The sorted array is:");
displayList(a,size);
  
printf("\n Calculating and displaying the number of times an element occured in the array:");
countList(a,lo,hi,size);
  
}

Add a comment
Know the answer?
Add Answer to:
Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT