Question: PLEASE SOLVE IN ASSEMBLY: PLEASE SOLVE IN ASSEMBLY: This project is designed to challenge you to be better. That being said, this is a difficult

PLEASE SOLVE IN ASSEMBLY: PLEASE SOLVE IN ASSEMBLY:
This project is designed to challenge you to be better. That being said, this is a difficult project, so please start early. Even though you should do your best to finish the project, we understand that some of you might not be able to, and its totally ok! Thats why we put more points on the basic tasks.
1 Background
In C language, when we want to print a variable out, we can simply use printf(). However, if we want to print an array out, that wouldnt be as easy as in Python, and we will have to use a loop to print each element individually. You, an ambitious and talented CS-382 student, decided to make a revolution on C language by
providing a new function that can print an array out with just one call. To play a twist on printf(), you call this function pringle().
We declare pringle() function as follows:
1 unsigned long int pringle(char*,...);
This is very similar to printf(), where the first parameter is always a string that contains zero or more format specifiers (such as %d). The rest of the parameters are denoted as ..., meaning it can have any number and anytype of parameters. In case youre wondering, this is called variadic function. Implementing this in C involves new knowledge and is not the purpose of this project. However, using all we have learned so far, we can easily implement this in assembly.
1.1 Examples
Lets first see some examples of what this function can do. Assume we have the following code in C:
1 unsigned long int arr[]={10,20,30};
2 pringle( "Print an array: %a
", arr, 3);
where %a is the specifier for our pringle() function. The output will look like this:
1 Print an array: 102030
Another example:
1 unsigned long int arr1[]={10,20,30,40};
2 unsigned long int arr2[]={100,200,300};
3 pringle("First array: %a
Second array: %a
", arr1,4, arr2,3);
The output will look like this:
1 First array: 10203040
2 Second array: 100200300
As you see from the examples above, one specifier %a corresponds to two parameters: the array pointer, and the length of the array:
1 pringle(char* formatted_str,
2 unsigned long int* ptr_arr1, unsigned long int len_arr1,
3 unsigned long int* ptr_arr2, unsigned long int len_arr2,...);
1.2 Assumptions
To make sure you understand the main points of the project without getting tangled in too much details, we make the following assumptions throughout the project:
(1) We will only work on unsigned long int arrays;
(2) The maximal number of %a in one pringle() call is 3(see extra credits);
(3) The number of arrays passed to pringle() always matches the number of %as in the string;
(4) The maximal length of outputted string is the number used in the starter code;
(5) No need for error checking. For example, the array length is always correct.
We split the project into four smaller parts, and grade them individually to maximize your points. Each task will be the building block of a complete pringle() function. Please write each task with correct calling conventions from the beginning, because itll save you a lot of time, headache, and tears when you put them
together.
2 Description
2.1 Task 1(30 pts): Number to ASCII
Lets start with the smallest task convert an integer to ASCII, the opposite operation of the one you wrote in homework 2. In this task, you can assume all the numbers are unsigned so no need to consider negative numbers. The function is declared as follows:
1 char* itoascii(unsigned long int number);
2.2 Task 2(30 pts): Returning a String of Numbers
The procedure of is declared as follows:
1 char* concat_array(unsigned long int* arr, unsigned long int len);
This procedure will concatenate all the elements in an array pointed by arr of length len , and return the pointer to this new string. For example, the following call
1 unsigned long int arr[]={10,20,30};
2 char* ret = concat_array(arr,3);
will return a string of the following
1102030
with a space between every two numbers (without newline at the end). To simplify implementation, you can certainly have an additional space after the last number.
Note that this function will use a loop and call itoascii() on each number. Also, it is highly recommended that you clear out the string in .data segment before you do anything in this procedure.
2.3 Task 3(30 pts): Counting Specifiers
Because pringle() is variadic, theres uncertain number of parameters, and itll be difficult to retrieve them from registers/stack. However, in our project, the first parameter is always a string with a certain number of format specifiers (%a). Thus, we can first count the numbers of specifiers in the string and to know how many
parameters.
Note that one %a needs two parameters: the pointer to the array, and the length of the array.
This procedure is declared as follows:
1 unsigned long int count_specs(char* str);
where the function will return the number of %as in str .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!