I’m working on a c programming question and need an explanation to help me understand better.
–write assembly language programs to:
-define procedures/functions and call them.
–create loops
-use syscall operations to display integers and strings on the console window
-use syscall operations to read integers from the keyboard.
Assignment Description:
Implement a MIPS assembly language program that defines main, readArray, printArray, and exchangeElements procedures/functions.
The readArray takes an array of integers as its parameter, then reads in integers from a user to fill the array.
The printArray takes an array of integers as its parameter, prints each integer of the array.
The exchangeElements procedure/function takes parameters of two arrays of integers, asks a user to specify how many integers to read, then calls the readArray function twice for each of two arrays, then exchanges two elements from two arrays when the index is even. (Please see the C program below), then print out the result contents for the two arrays. It also returns how many numbers are exchanged.
The main procedure/function calls exchangeElements function and print out the number of elements exchanged.
Please see the following C program to understand how it should work.
If your program causes an infinite loop, press Control and ‘C’ keys at the same time to stop it.
Name your source code file assignment6.s.
You can create an array in the following way:
numbers1: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
numbers2: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
The following shows how it looks like in a C program:
//The readArray procedure reads integers from user input and store them in the array void readArray(int array[], int length, int howMany, int number) { int num, i = 0; while (i < howMany && i < length) { printf("Enter an integer: n"); //read an integer from a user input and store it in num1 scanf("%d", &num); array[i] = num; i++; } printf("nThe array %d content:n", number); i = 0; while (i < howMany && i < length) { printf("%dn", array[i]); i++; } return; } //The printArray procedure prints integers of the array void printArray(int array[], int length, int howMany, int number) { int i; printf("nResult array %d Content:n", number); i = 0; while (i < howMany && i < length) { printf("%dn", array[i]); i++; } return; } //The exchangeElements calls readArray procedure to populate two arrays, //then exchange elements from two arrays at even indexes, then print the result arrays. int exchangeElements(int array1[], int array2[], int length) { int i, temp; int howMany, count; printf("Specify how many numbers should be stored in the arrays (at most 11):n"); scanf("%d", &howMany); readArray(array1, length, howMany, 1); readArray(array2, length, howMany, 2); i = 0; count = 0; //exchange two elements from two arrays at even indexes while (i < howMany && i < length) { if (i%2 == 0) { temp = array1[i]; array1[i] = array2[i]; array2[i] = temp; count++; } i++; } printArray(array1, length, howMany, 1); printArray(array2, length, howMany, 2); return count; } // The main calls the exchangeElements void main() { int arraysize = 11; int numbers1[arraysize], numbers2[arraysize]; int number = exchangeElements(numbers1, numbers2, arraysize); //print out how many elements are exchanged printf("%d element(s) exchangedn", number); return; }
The following is a sample output (user input is in bold):
Specify how many numbers should be stored in the arrays (at most 11):
8
Enter an integer:
1
Enter an integer:
-12
Enter an integer:
53
Enter an integer:
-4
Enter an integer:
5
Enter an integer:
32
Enter an integer:
1
Enter an integer:
7
The array 1 content:
1
-12
53
-4
5
32
1
7
Enter an integer:
1
Enter an integer:
7
Enter an integer:
1
Enter an integer:
5
Enter an integer:
1
Enter an integer:
-5
Enter an integer:
-2
Enter an integer:
3
The array 2 content:
1
7
1
5
1
-5
-2
3
Result array 1 Content:
1
-12
1
-4
1
32
-2
7
Result array 2 Content:
1
7
53
5
5
-5
1
3
4 element(s) exchanged
————————————————–
Each procedure/function needs to have a header using the following format:
############################################################################
# Procedure/Function readArray
# Description: —–
# parameters: $a0 = address of array1 , $a1 = addres of array2, $a3 = length
# return value: $v1 = count
# registers to be used: $s3 and $s4 will be used.
############################################################################
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
Ace Writing Center has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.
Essays
At Ace Writing Center, Nowadays, students normally have extremely busy schedules. You will note that some of them have to take on some evening or weekend jobs in order to get some income that can help them to sustain in college or in the university. This can deny them a chance to write all the essays given. Others usually get bombarded with a lot of work by their lecturers. This can still delay such students from working on all their essays. However, some of them usually try to work on all these essays but end up delivering their work late. This can prevent them from graduating since most lecturers are strict on deadlines. If you want to write a business essay, the wise way is to hire an outstanding essay writing service like us, so that you can get the best results. If you are keen, you will note that many companies usually overcharge their customers. Some of them are there only to make money. And in reality, they really don’t care to build a long term commitment with students. You should not choose such companies. You should take your time and choose a reliable company to work with. Ace Writing Center is the ultimate solution for you. We have been offering our writing service for more than 7 years. This is a clear indication that you will get quality essay writing service. We have a wide range of writers who can work on any business essay that you might have. We believe in doing extensive research so that we can provide quality work to all our clients. .
Admissions
Admission and Business Papers
Have you ever had to write an admission essay for college? The majority of students face the same issues when applying to a university or college and many in such situations decide they need professional help to cope with this matter. They get in a situation when the deadline keeps coming closer but lack motivation to start because they are just not sure if their writing skills are strong enough. We have a solution for you! Ace Writing Center is the best admission essay writing service with a large professional team and years of experience in providing high-quality papers to students of all levels and faculties. The mission of our team is to help students make their dreams of entering a good college come true and that’s what we offer!.
Editing
Editing and Proofreading
Sometimes all the words for your paper just flow out of your mind and into your fingers. You type quickly at your keyboard and there they are, your beautiful words right there on the screen. But you have no idea how to polish it up. You may be wishing there was a paper writing service that offered this type of writing service. Look no more! Here at Ace Writing Center, we offer you an editing and proofreading option that you can't find anywhere else..
Coursework
College Essay Writing
In case you are familiar Ace Writing Center, you know the way to distinguish a better company from a cheap one exactly. First of all, poor service website does not have a sufficient support. We think support team is an essential part of success; it has to answer all clients’ questions and be a connecting link between clients and their writers. On our web-service you will get answers about anything you need and your writer will receive all your instructions, assignments and requirements exactly and swiftly. A writing service that we run has got a flexible pricing system that will save you from senseless wastes and many bonus systems that let you sparing money for something important for you.