SPARC ASSEMBLY DRILLS Due Wednesday 5/1 0. Following sample code provided to you, write from scratch (no cutting and pasting!) a Sparc program that prints the first 40 numbers in the fibonacci sequence. This sequence is defined as: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) + fib(n-2) for all n>1 Thus, the first 10 numbers are 0 1 1 2 3 5 8 13 21 34 There are many ways to do this, including recursively and non-recursively. You should do it non-recursively (since you don't know how to create functions yet), by using two registers to keep track of the two latest fib values. 1. Type in the following C program, which prints the ascii characters from 0 to 255. Use gcc to generate an assembly file with gcc -O2 -S filename.c. You should get a file called filename.s if there are no errors. Now look at the .s file, and using comments, describe the operation of each line of code. Associate each line in C with a corresponding section in assembly. Describe in English what's happening - that is, how is the program being implemented at the machine level. Ignore the assembler directives that starts with ".", such as ".type". Also, don't worry about the save, ret, and restore operations for now. int main() { int i; char c; i = 0; while (i<256) { c = (char) i; printf("The ascii character for %d is %c\n",i,c); i++; } exit(0); } 1b: Now, change the range of values of i to 0-1024, and see what happens. Explain what exactly is happening at the machine level, when the instruction c = (char) i; is executed. 1c: regenerate the assembly code, this time without optimization (leave out the "O2"). Explain what the differences (don't have to be as precise as the first part but be meaningful). (don't spend too much time on this - concentrate on writing the programs!) 2. Write from scratch an assembly program that inputs a string (using the gets function from C - type "man gets" for info on how to use this function). Then determine if the string consist of only alphabetical characters. These have ascii values in the the ranges 65-90 (upper case), and 97-122 (lower case). The program should print "alphabetical" if it is, and "not alphabetical" if not. Note: this problem does NOT ask you to test if the string is sorted in alphabetical order - only that each char is a letter of the alphabet. 2b: The "ascii distance" between upper case chars and their lower case counterparts is always 32, which can be represented using a single bit in the right position. (Think about what this means!) modify your program so that (in addition to the above) the program will exclusive or (xor) each lower-case ascii value in the string with 32 (0x0020). Print out the resulting string. 3: (Optional) Advanced computer science students need to be able to figure things out on their own. Figure out on your own how to load the value 0x12345678 (or some other 32 bit constant) into a register. Write a short program to demonstrate. Paste output into your source code (as comments).