Alex Larose

Generation

generate functionWed, 08 Mar 2023

I. OBJECTIVES: The purpose of this assignment is to gain some familiarity with writing C callable functions that use assembly language. Copy all files from /courses/cs341/s23/hefeiqiu/mp2/part1/ and /courses/cs341/s23/hefeiqiu/mp2/part2+3/ to your cs341/mp2/ directory. Use the provided makefile for all builds except where instructed otherwise. As in mp1, use the environment in users.cs.umb.edu to build all your .lnx executables and use the tutor-vserver and tutor VMs to run and debug your code. II. DESCRIPTION: Part 1: Program to count the occurrence of a user entered character in a string 1. 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

#include <stdio.h> int count(char *string, char c); int main(void) { char string[100]; char c; printf("Enter a string: "); scanf("%s", string); printf("Enter a character: "); scanf(" %c", &c); printf("The character '%c' occurs %d times in \"%s\"\n", c, count(string, c), string); }

Questions about programming?Chat with your personal AI assistant