Alex Larose

Generation

linuxTue, 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.

.code32 .global count count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl $0, %ecx movl $0, %esi loop: movl (%eax), %ebx cmpl %edx, %ebx je increment addl $4, %eax cmpl $0, (%eax) je done jmp loop increment: incl %ecx addl $4, %eax cmpl $0, (%eax) je done jmp loop done: popl %ebp ret

Questions about programming?Chat with your personal AI assistant