CS3843 Programming Assignment #4: Assembly Coding with Arrays (50 points)

In this program, you will do the following:

  1. Complete the code for the function, duplicate(szSource[], szResult[] , iLength), which is passed the address of a source array of characters (zero terminated),the address of a resulting array of characters (should be zero terminated by you), and a count of the number of characters (not including the zero byte) in that source array. dulicate should return an array where every character in the source array has been duplicated.

Example: duplicate("abcdefg", szResult, 7) returned value via szResult is "aabbccddeeffgg".

  1. To help limit your creative use of the gcc compiler to generate the assembly languge, I have provided skeletal code for duplicate.s. You must use the registers in the way they are described in the header comments.
  2. The array element reference must use pointer advancement.
  3. Use dumpRegs and hexDump at the beginning of duplicate (after stack memory has been allocated).

Byte Movement and Comparison

  • Use movbaddress, %dl to move a byte at the specified address to the one byte register %dl. The address is probably in a register.
  • Use movb %dl, addressto move a byte from the one byte register %dl to the specified address which is probably in a register.
  • Use cmpbvalue, %dl to compare a value with the one byte register %dl.

Bonus (no bonus if turned in late)

  1. Complete code for the function, countMatch(szString[], szMatch[], iLength), which returns a count of the number of occurrences of the match string in the first string. Assume the match string has exactly 3 characters. If the match string isn't found, return 0.

Example: countMatch("rain in Spain", "ain", 13 ) returns 2

  1. If your code is correct according to all requirements, well documented, and not late, you will receive 10 points + 100 points / n where n is the number of people who meet all requirements.
  2. To help limit your creative use of the gcc compiler to generate the assembly languge, I have provided skeletal code for countMatch.s. You must use the registers in the way they are described in the header comments.
  3. The array element reference must use pointer advancement.

I have provided the following files in /usr/local/courses/cs3843/clark:

  1. cs3843p4Driver.o - the driver which invokes duplicate and countMatch.
  2. duplicate.s - a bare minimum skeleton for duplicate. You will be coding and documenting this function. After you copy this to your directory, you might need to chmod +w
  3. dumpRegs.o - dumpRegs writes the contents of the 8 major registers to stdout. It does not receive any parameters.
  4. hexDump.o - a hexDump function (as described in assignment #1). It also prints the address being dumped.
  5. countMatch.s - a bare minimum skeleton for countMatch. For bonus credit, you will be coding and documenting this function. After you copy this to your directory, you might need to chmod +w

Turn In:

  1. Your fully coded and documented duplicate.s. Please refer to the Assembler documentation standards which is on my website under Programming Assignments.
  2. Your output which must include one call of both dumpRegs and hexDump immediately after memory is reserved on the stack.
  3. If you do the bonus, include your code for countMatch.s.

Assembling and linking

  1. When you want to assemble a file, use:

gcc -c filename.s

  1. When you want to link your code to produce the p4 executable, use:

gcc -o p4 cs3843p4Driver.o duplicate.o countMatch.o dumpRegs.o hexDump.o

  1. To execute it, use:

./p4

Note: even if you don't code countMatch.s, you must include countMatch.o in the link step.