Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly program that will examine an input string. Assume that a strin

ID: 2085747 • Letter: W

Question

Write an assembly program that will examine an input string. Assume that a string does not
include more than one line. Assume the input string is “Welcome to Assembly Programming
@MSP430!”. Your program should count the number of total characters, number of uppercase
vowels, and number of special characters (other than characters and digits). Set the port P1 to
display the number of special characters, and port P2 to display the number of vowels. Store
the total number of characters in register R10. If you are using the sample string given above
for testing, the correct results are shown below (in decimal):
Total Characters: 40
Total Uppercase Vowels: 1
Total Special Characters: 6

Explanation / Answer

#include <stdio.h>

int main()
{
    char line[40];
    int i, vowels, consonants, digits, spaces;

    vowels = consonants = digits = spaces = 0;

    printf("Enter a line of string: ");
    scanf("%[^ ]", line);

    for(i=0; line[i]!=''; ++i)
    {
        if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
           line[i]=='o' || line[i]=='u' || line[i]=='A' ||
           line[i]=='E' || line[i]=='I' || line[i]=='O' ||
           line[i]=='U')
        {
            ++vowels;
        }
        else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
        {
            ++consonants;
        }
        else if(line[i]>='0' && line[i]<='9')
        {
            ++digits;
        }
        else if (line[i]==' ')
        {
            ++spaces;
        }
    }

    printf("Vowels: %d",vowels);
    printf(" Consonants: %d",consonants);
    printf(" Digits: %d",digits);
    printf(" White spaces: %d", spaces);

    return 0;
}


Program:

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
    char text[80], ch ;
    int vowel = 0, cons = 0, digit = 0, word = 0, special = 0, i = 0;
    clrscr() ;
    printf("Enter the text : ") ;
    gets(text) ;
    while((ch = tolower(text[i++])) != '')
    {
        if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
          vowel ;
        else if(ch >= 'a' && ch <= 'z')
          cons ;
        else if(ch >= '0' && ch <= '9')
          digit ;
        else if(ch == ' ')
          word ;
        else
          special ;
    }
       word ;
    printf(" The text contains : ") ;
    printf(" Number of vowels = %d", vowel) ;
    printf(" Number of consonants = %d", cons) ;
    printf(" Number of digits = %d", digit) ;
    printf(" Number of special characters = %d", special) ;
    printf(" Number of words = %d", word) ;
    getch() ;
}

Output:

Enter the text : Bhuvan was born in 2nd Nov 1977 !!!
The text contains :
Number of vowels = 6
Number of consonants = 14
Number of digits = 5
Number of special characters = 3
Number of words = 8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote