Exam 2 Lab


Even though you can use the C compiler to peek at the assembly language you need, do not just try to translate the compiler code. You should look for clues into how to add some program feature you understand, not just try to deal with error messages from code you do not understand. This assignment is not too hard, if you take it slowly. Commit often so I can see how you work through this. I will give extra credit for slow coding. Nothing extra for only one commit.

This exercise involves building a single file program using three functions:

  • main - the main program
  • print_data - an output function
  • convert_data - a function that modifies data

Build your code in baby steps style, and commit often. Work it through slowly, and make sure you have things running as best as you can before you stop working (after a final commit). Add comments to your code indicating what you are trying to do – especially if you do not get it running. Partial credit will be given for showing the thinking at least!

Here is the process you should follow:

# Data Setup: Create a data array holding 5 strings in the initialized data section. Each string has exactly 4 characters - three ‘0’ (zero) characters followed by a single lower case letter (“000a”, “000b”, etc). Note that there is no zero byte at the end of any of these strings.

# Main function: Create a main function that calls a simple print_data procedure, passing the address of your data area in a register. You will add more to this in a later step.

# print_data: Create the print_data procedure next. This procedure sets up a loop that runs five times. Inside the loop, you should set up another loop that runs four times. Each time through this inner loop, print one of the characters from the data. (You can use the C putchar function to do the output.) After each string has been output, end the string with a newline. This procedure should print out the set of strings as created in the above section, one string per line.

# convert_data: Set up a convert_data procedure that will receive the address of the data array on the stack and convert the lower case letter to an upper case letter without modifying any of the ‘0’ characters in each string. You can use any scheme you can think of to do this. The modifications should happen in place - that is the original data elements are changed after your procedure is called. This function does not print anything, and returns nothing.

# Main function: Back in the main function, add code to call the convert_data procedure from step 4. Then call the print_data procedure you constructed in step 3 to print out the array again as you did earlier. You should see the same output with the letter capitalized.

None of these steps take much code. The hardest part is figuring out how to print the data in the array (in the loop) and finding the character you want to modify in the convert_data function (another loop?). There are many approaches to doing these tasks available.

When is this Due?

This program should be in an Exam2Lab folder in your Homework repository by the last day of the term (but do not wait until then. We will be working on other things!)