Alex Larose

Generation

translateTue, 07 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

#include <stdio.h> int count(char *str, char c){ int count = 0; int index = 0; while(str[index] != '\0'){ if(str[index] == c){ count++; } index++; } return count; } int main(){ char str[100]; printf("Please input a string : "); scanf("%[^\n]", str); char c; printf("Please input a char : "); scanf(" %c", &c); int ret = count(str, c); printf("The char %c appears %d times in the string %s\n", c, ret, str); return 0; }

Questions about programming?Chat with your personal AI assistant