Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given is the c program to count occurrences of word in a program . Please comment each line of this assembly program what it is

Given is the c program to count occurrences of word in a program .

Please comment each line of this assembly program what it is doing. (Code is already provided) . Comments needed for assembly code only

#include

int count(char *string, char c); int main(void) { char s[100]; char c; printf("Enter a string of characters and the character to count "); scanf("%s %c", s,&c);

printf(" The number of %c's in the string %s is %d ", c, s, count(s, c)); return 0; }

int count(char *string,char c) { int i,count=0; for (i = 0;string[i] != '\0';i++) { if (string[i] == c) count++; } return count; }

Assembly code . Please comment each line what it is doing !

// Comment whichever lines you understand

.file "countw.c" .section .rodata .align 8 .LC0: .string "Enter a string of characters and the character to count" .LC1: .string "%s %c" .align 8 .LC2: .string " The number of %c's in the string %s is %d " .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 addq $-128, %rsp movq %fs:40, %rax movq %rax, -8(%rbp) xorl %eax, %eax movl $.LC0, %edi call puts leaq -113(%rbp), %rdx leaq -112(%rbp), %rax movq %rax, %rsi movl $.LC1, %edi movl $0, %eax call __isoc99_scanf movzbl -113(%rbp), %eax movsbl %al, %edx leaq -112(%rbp), %rax movl %edx, %esi movq %rax, %rdi call count movl %eax, %ecx movzbl -113(%rbp), %eax movsbl %al, %eax leaq -112(%rbp), %rdx movl %eax, %esi movl $.LC2, %edi movl $0, %eax call printf movl $0, %eax movq -8(%rbp), %rcx xorq %fs:40, %rcx je .L3 call __stack_chk_fail .L3: leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .globl count .type count, @function count: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movq %rdi, -24(%rbp) movl %esi, %eax movb %al, -28(%rbp) movl $0, -4(%rbp) movl $0, -8(%rbp) jmp .L5 .L7: movl -8(%rbp), %eax movslq %eax, %rdx movq -24(%rbp), %rax addq %rdx, %rax movzbl (%rax), %eax cmpb -28(%rbp), %al jne .L6 addl $1, -4(%rbp) .L6: addl $1, -8(%rbp) .L5: movl -8(%rbp), %eax movslq %eax, %rdx movq -24(%rbp), %rax addq %rdx, %rax movzbl (%rax), %eax testb %al, %al jne .L7 movl -4(%rbp), %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1: .size count, .-count .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609" .section .note.GNU-stack,"",@progbits

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago