Question: PLEASE SOLVE IN ASSEMBLY: PLEASE SOLVE IN ASSEMBLY: 2 . 4 Task 4 ( 1 0 pts ) : Mingle and Pringle! Last task is

PLEASE SOLVE IN ASSEMBLY: PLEASE SOLVE IN ASSEMBLY:
2.4 Task 4(10 pts): Mingle and Pringle!
Last task is to complete pringle() function. After completing the three tasks above, you'll see the algorithm is very simple:
(1) Scan every character in the string;
(a) If there's a %a:
i. Fetch the corresponding array pointer and its length;
ii. Call concat_array();
iii. Copy the return of concat_array() into the destination string;
(b) Else copy the character from the pringle() parameter to the destination string;
(2) Return the number of characters printed (excluding null terminator).
We use the following flowchart to visualize the execution of pringle() function.
2.5 Extra Credits (20 pts)
If it's not challenging enough for you, an obvious opportunity to earn extra credits is to remove the limit ofparameters we can pass to pringle() function. We will grade this part manually. Please indicate if you want to be graded for EC at the top of pringle.s as a comment.
3 Testing
Another skill you will gain from this project is to link your C code with assembly code. From a practical aspect, for some functions the compiler cannot produce the most efficient assembly code, and that's where you, a radical and intelligent CS-382 student, rise and shine! You can implement the function in assembly, and call the function from your C code directly.
3.1 Individual Tests
The first test file we provide is indietest.c. From this file, you can see how we declare functions written in assembly, and how to call them. First of all, we declare those functions as extern, since they're only defined during the linking phase:
1 extern char* itoascii(unsigned long int);
2 extern char* concat_array(unsigned long int*, unsigned long int);
3 extern unsigned long int count_specs(char*);
4 extern unsigned long int pringle(char*,...);
We then provide a mini main function where we test all four tasks:
/* Test for task 1.
Output: 1234
*/
char* s = itoascii(1234);
puts(s);
/* Test for task 2
Output: 1020030
*/
unsigned long int arr[]={10,200,30};
char* x = concat_array(arr,3);
puts(x);
/* Test for task 3
Output: 3
*/
char* str = "Hello this is a test string for %a and %%%a and %% and %a.
";
unsigned long int c = count_specs(str);
char* count = itoascii(c);
puts(count);
/* Test for task 4
Output: Hello this is a test string for 1234567890 and %%12 and %% and 00005.
79
*/
unsigned long int arr1[]={123,456,7890};
unsigned long int arr2[]={12};
unsigned long int arr3[]={0,0,0,0,5};
unsigned long int ret = pringle(str, arr1,3, arr2,1, arr3,5);
char* newcount = itoascii(ret);
puts(newcount);
If you have finished task 1 and want to test it only, you can comment out the code for task 2,3, and 4, and run the following commands to compile:
$ aarch64-linux-gnu-gcc indietest.c itoascii.s -g
and run a.out:
$ qemu-aarch64-L /usr/aarch64-linux-gnu/ a.out
This file can be used as an example showing you how we call and test your functions in the tester, introduced below.
3.2 Tester
Ah, the (in)famous tester again! We highly recommend you use indietest.c first to make sure it's working before using the tester. The usage of the tester is the same as in previous two homework. Put this tester file in the same directory as your assembly code, and go ahead and run the tester:
$ qemu-aarch64-L /usr/aarch64-linux-gnu/ tester -t
{itoascii|concat_array|count_specs|pringlelall}
"Array is: %a
" unsigned long int arr[]={10,20,30}; "Array is: \%a
" unsigned long int arr[]=\{10,20,30\};
PLEASE SOLVE IN ASSEMBLY: PLEASE SOLVE IN

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!