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.

.data str: .string "hello" char: .byte 'o' len: .long 5 .text .globl count count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl (%eax), %ecx movl 4(%ebp), %ebx loop: cmpl $0, %ecx je done movb (%edx), %al cmpl %al, (%ebx) je increment addl $1, %edx subl $1, %ecx jmp loop increment: addl $1, %edx addl $1, %ecx incl %eax jmp loop done: movl %ebp, %esp popl %ebp ret

Questions about programming?Chat with your personal AI assistant