CS/COE 447: Spring 2010 Programming Assignment 1 YOUR NAME: Your solutions to this assigment must be your own individual work. Programming assignments should be uploaded to courseweb at http://courseweb.pitt.edu. Click on course tools, then digital dropbox. Please name the file, for example, PA1part1 (for programming assignment 1 part 1), followed by your first and last name. *******Part 1: Write and call a function "minimum" which, given an array of non-negative integers, finds and returns the minimum value in the array. Your array should be stored as a data structure where the first word is the number of elements in the array, followed by the elements of the array. Each element is a 1-word integer. EXAMPLE: An array A with the 5 elements 1, 4, 15, 100, and 102 is stored like this (24 total bytes): A: .word 5, 1, 4, 15, 100, 102 Your program should create an array data structure such as the one above, call your minimum function, and then print the returned value. For the minimum function, a pointer to the array data structure (e.g., the address where the 5 is stored in the example above) should be passed in $a0. The returned value should be returned in $v0. *******Part 2: ASCII is a standard character encoding used, for example, for transmission of information over communication lines between computers. Even numbers are encoded, so that 0x31, for example, is sent rather than a 1. (A table of ASCII values is available on the course webpage). The task in Part 2 is to write procedure translate: #******* #Procedure Translate # Translates the 8 hex digits in $a0 into ascii, and stores them # as a null-terminated string in memory, starting at the address #stored in $a1. # # The values are stored so that the most significant hex digit in $a0 # is stored first (at the byte whose address is contained in $a1). # To make your string a "null-terminated string", store a 0 after the # last character of the string. # # The hex values A-F should be translated into uppercase letters. # # For example, if $a0 contains 0xA5432BDE and $a1 contains 0x10010000, then # 0x41 is stored in location 0x10010000, 0x35 is stored in 0x10010001, 0x34 # is stored in 0x10010002, and so on. # The program should place values in $a0 and $a1, call procedure translate, and then print the string stored in memory. Assuming that "string" is a label for the string's address, here is how you print the string (see B-42 and B-43 in appendix B): addi $v0,$zero,4 la $a0,string syscall Below are some hints for writing the procedure. [We've left some space here in case you don't want to be spoiled.] Here are a couple hints (more hints are below): Use andi to copy the most-significant digit of $a0 into another register, say $t1 Then, shift both $a0 and $t1 (using srl and sll) to get values where you want them Full hints [write examples down on paper as you read through this, to make sure you understand] The main loop is a for-loop that will execute 8 times, since we know that $a0 contains exactly 8 hex digits. How to translate a hex digit: Note that the ascii values of the numbers are 0x30 through 0x39, and the ascii values of the letters are 0x41 through 0x46. So, if the hex digit is between 0x0 and 0x9, the ascii value is between 0x30 and 0x39 (so, add 0x30 to the hex digit to get the ascii digit). If the hex digit is between 0xA and 0xF, there is another number you should add to get the ascii digit (we'll leave that detail to you). How to extract the hex digits: We are translating starting with the most-significant hex digit first (the one on the left). So: 1. copy the leftmost hex digit into another register, say $t1 Note that performing bitwise "and" between a number and 1 copies that number, since 0 and 1 is 0; 1 and 1 is 1. We want to copy the leftmost 4 bits. So, anding $a0 with 0xF0000000 will copy the leftmost hex digit of $a0 2. shift $t1 right 28 bits, so that $t1 contains the number we want to translate into ascii. Use the procedure above to translate it. 3. shift $a0 left by 4 bits, so that the next digit to translate will be the most significant hex digit of $a0. Repeat for all 8 hex digits in $a0