Alex Larose

Generation

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your assembly code in count.s. Then build the executable using the provided makefile by invoking “make A=count”. Capture a run of your program in the script file mp2_part1_typescript. The file is captured in the vserver VM and later transferred to your cs341/mp2/part1/ homework directory for grading. Please provide the script showing a run with a breakpoint set using either Tutor or remote gdb where the count is incremented, showing the count (in a register) each time the breakpoint is hit, just before the increment is made. In the script, show how you determined where to set the breakpoint, i.e., how you determined where the increment instruction is located in memory

make A=count make run A=count make script A=count

Questions about programming?Chat with your personal AI assistant