CMSC313, Computer Organization & Assembly Language Programming, Spring 2013

Project 7: String Functions in Assembly

Due: Tuesday April 16, 2013, 11:59pm


Objective

The objective of this programming exercise is to practice writing assembly language programs that use the C function call conventions.


Assignment

Your assignment is to implement two functions in assembly language program that use the C function call conventions. If you missed class when C function call conventions were discussed, you should read the write up on C Function Call Conventions before asking any questions. (Yes, it's complicated.)

The two functions that you must implement in assembly language have the following prototypes:

void strrev(char *str) ; int strrepl(char *str, int c, int (* isinsubset) (int c) ) ;

The strrev() function reverses the characters in the memory location addressed by the pointer str. For example, if strrev() is given the string "Hello World", then the string is changed to "dlroW olleH" after calling strrev(). In the call strrev(ptr), the pointer ptr must point to a memory location that can be modified. The call strrev("abcd") will result in a segmentation fault because "abcd" is a constant string.

The strrepl() function replaces each occurrence of a subset of characters in string addressed by str with the character c. The subset is specified by the third parameter, a function pointer, isinsubset(). The return value of strrepl() is the number of characters that were replaced.

For example, the following call to strrepl()

str1 = strdup("ABC 123 779 Hello World") ; r = strrepl(str1, '#', &isdigit) ;

will change the string addressed by str1 to "ABC ### ### Hello World" and will return the value 6. Here isdigit() is a standard C Library function that returns non-zero if given a digit character ('0' – '9') and returns zero otherwise.

Similarly, the call

str3 = strdup("ABC 123 779 Hello World") ; r = strrepl(str3, '_', &isvowel) ; will changed the string addressed by str3 to "_BC 123 779 H_ll_ W_rld", assuming that isvowel() is a function that identifies vowels.

The function pointers passed as the third parameter to strrepl() must have the function signature:

int function_name (int c) ;

Even though the intention is to pass a character to these functions, the parameter is nevertheless an int. This is because the end-of-file character (EOF) is often represented as -1, and C has traditionally allowed EOF to be passed to functions such as isdigit. (See man pages for ctype.)

A test program, main7.c, has been provided for you along with its output: main7.txt. As usual, testing is your responsibility and you should exercise your functions with your own test programs.


Implementation Notes:


Turning in your program

Use the UNIX submit command on the GL system to turn in your project. When you are done, use the script Unix command to record yourself running your program. You do not have record yourself using gdb for this project.

You should submit 4 files: strrev.asm, strrepl.asm, test7.c and typescript. The UNIX command to submit should look like:

submit cs313 proj7 strrev.asm strrepl.asm test7.c typescript


Last Modified: 8 Apr 2013 22:57:53 EDT by Richard Chang
to Spring 2013 CMSC 313 Homepage