Alex Larose

Generation

linuxWed, 08 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.

.section .rodata prompt: .string "Enter a string: " prompt2: .string "Enter a character: " .section .text .globl _start .type _start, @function _start: nop nop nop nop nop nop nop nop call read_string call read_char call count call print_int call exit .type count, @function count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl $0, %ecx jmp loop loop: movl (%eax), %ebx cmpl %edx, %ebx jne skip addl $1, %ecx skip: addl $1, %eax

Questions about programming?Chat with your personal AI assistant