i am trying to write a subroutine in assembly that removes all occurrences of a given character in a string. The subroutine takes two parameters: the string pointer, and the character to be removed. Write a C code that calls this subroutine. The string is defined in the C source code file as global. Assume the assembly and C code are in separate files. Use Keil/uVision to test your program where the C code should ask the assembly subroutine to remove all occurrences of character “o” from the following global string: char str[] = “The Quick Brown Fox Jumps Over a Lazy Dog”;
// here is the full code
?// output is attached
?// plz comment if you need any clarification
// hit like if you liked it
// CODE
?// MAIN CODE : Chegg149.c
// This code initializes both the string and character
// If you want to take input from the user you can do it by
// using the code in the comments
#include<stdio.h>
#include<string.h>
// Declare the remove function as extern function
extern void removeAll(char *, int, const char);
char str[] = "The Quick Brown Fox Jumps Over a Lazy Dog"; // global
string
// main program
int main() {
//char str[101]; // string
char c = 'o'; // char to remove
int len;
// read the string
//printf("Enter any string(of len at most 100):
");
//scanf("%[^\n]", &str);
len = strlen(str);
// read the char to remove
printf("\nEnter character to remove from string:
");
//getc(stdin);
//c = getc(stdin);
printf("\nbefore : %s", str);
removeAll(str, len, c); // call the
function
printf("\nafter removing '%c': %s", c, str);
return 0;
}
?// Func.c
#include<stdio.h>
// Function to remove all occurrences of a character from the
string.
void removeAll(char * str, int len, const char toRemove) {
printf("\nIn The Function : ");
printf("\nString : %s", str);
printf("\nChar to be removed : '%c' ", toRemove);
for(int i = 0; i<len; i++) {
//If the character to
remove is found then shift all characters to one
//place left and
decrement the length of string by 1.
if(str[i] == toRemove)
{
for(int j=i; j<len; j++) {
str[j] = str[j+1];
}
len--; // decrement the length
i--; // when a character is removed then i should not be
incremented
}
}
}
// Func.s : ASM File
.file "Func.c"
.text
.def _printf; .scl 3; .type 32; .endef
_printf:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $36, %esp
leal 12(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl 8(%ebp), %eax
movl %eax, (%esp)
call ___mingw_vprintf
movl %eax, %ebx
movl %ebx, %eax
addl $36, %esp
popl %ebx
popl %ebp
ret
.section .rdata,"dr"
LC0:
.ascii "\12In The Function : \0"
LC1:
.ascii "\12String : %s\0"
LC2:
.ascii "\12Char to be removed : '%c' \0"
.text
.globl _removeAll
.def _removeAll; .scl 2; .type 32; .endef
_removeAll:
pushl %ebp
movl %esp, %ebp
subl $56, %esp
movl 16(%ebp), %eax
movb %al, -28(%ebp)
movl $LC0, (%esp)
call _printf
movl 8(%ebp), %eax
movl %eax, 4(%esp)
movl $LC1, (%esp)
call _printf
movsbl -28(%ebp), %eax
movl %eax, 4(%esp)
movl $LC2, (%esp)
call _printf
movl $0, -12(%ebp)
jmp L4
L8:
movl -12(%ebp), %edx
movl 8(%ebp), %eax
addl %edx, %eax
movzbl (%eax), %eax
cmpb -28(%ebp), %al
jne L5
movl -12(%ebp), %eax
movl %eax, -16(%ebp)
jmp L6
L7:
movl -16(%ebp), %edx
movl 8(%ebp), %eax
addl %eax, %edx
movl -16(%ebp), %eax
leal 1(%eax), %ecx
movl 8(%ebp), %eax
addl %ecx, %eax
movzbl (%eax), %eax
movb %al, (%edx)
addl $1, -16(%ebp)
L6:
movl -16(%ebp), %eax
cmpl 12(%ebp), %eax
jl L7
subl $1, 12(%ebp)
subl $1, -12(%ebp)
L5:
addl $1, -12(%ebp)
L4:
movl -12(%ebp), %eax
cmpl 12(%ebp), %eax
jl L8
leave
ret
.ident "GCC: (tdm-1) 4.9.2"
.def ___mingw_vprintf; .scl 2; .type 32; .endef
?// OUTPUT
this image shows how to compile the code and how to run the
code
i am trying to write a subroutine in assembly that removes all occurrences of a given...
C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Submit your completed source (.cpp) file. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator:...
IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the...
I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...
//Write a recursive function that, given an input string str, replaces all occurrences of a character a by a character b in str. (C++) void replace_chr(char *str, char a, char b){ }
Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below: Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it. Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42),...
Write a procedure, bfind( ), in C code using pointer-based and convert it into MIPS assembly language with clear and necessary comments. The procedure should take a single argument that is a pointer to a null-terminated string in register $a0. The bfind procedure should locate the first character b in the string and return its address. If there are no b’s in the string, then bfind should return a pointer to the null character at the end of the string....
Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...
‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...
In Python
1 2 Write a function that removes all occurrences of a given letter from a string: test (remove_letter ("a", "apple") "pple") test (remove_letter ("a", "banana") "bnn") test (remove_letter (2", "banana") "banana") test (remove_letter ("i", "Mississippi") "Msssspp") test (remove letter (",) "") test (remove_letter("b","0"> MO) 4 5 ### Run the following lines. # If you get "Correct" you # did it right. if remove_letter("a", "banana") == "nn": print("Correct!") else: print("Incorrect :(")
Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...