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.
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 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:
unsigned long int pringlechar;
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.
Examples
Lets first see some examples of what this function can do Assume we have the following code in C:
unsigned long int arr;
pringle "Print an array: a
arr, ;
where a is the specifier for our pringle function. The output will look like this:
Print an array:
Another example:
unsigned long int arr;
unsigned long int arr;
pringleFirst array: a
Second array: a
arr arr;
The output will look like this:
First array:
Second array:
As you see from the examples above, one specifier a corresponds to two parameters: the array pointer, and the length of the array:
pringlechar formattedstr
unsigned long int ptrarr unsigned long int lenarr
unsigned long int ptrarr unsigned long int lenarr;
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:
We will only work on unsigned long int arrays;
The maximal number of a in one pringle call is see extra credits;
The number of arrays passed to pringle always matches the number of as in the string;
The maximal length of outputted string is the number used in the starter code;
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.
Description
Task 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 In this task, you can assume all the numbers are unsigned so no need to consider negative numbers. The function is declared as follows:
char itoasciiunsigned long int number;
Task pts: Returning a String of Numbers
The procedure of is declared as follows:
char concatarrayunsigned 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
unsigned long int arr;
char ret concatarrayarr;
will return a string of the following
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.
Task pts: Counting Specifiers
Because pringle is variadic, theres uncertain number of parameters, and itll be difficult to retrieve them from registersstack 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:
unsigned long int countspecschar 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
