Alex Larose

Generation

generate functionTue, 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.

count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax decl %eax movl %eax, %ebx movl 12(%ebp), %eax decl %eax movl %eax, %ecx movl $0, %edx .L3: cmpl $0, %edx je .L2 movl (%ebx), %eax pushl %eax call getchar addl $4, %esp movl %eax, %edx movl (%ecx), %eax pushl %eax call getchar addl $4, %esp cmpl %edx, %eax jne .L4 inc %edx movl $1, %eax .L4: addl $1, %ebx

Questions about programming?Chat with your personal AI assistant