Assembly Program to Count Consonants in a String
The program will prompt the user to input a string and will count the number of consonants present in that string.
The program takes a string and stores the string in STRING and will start iteration if there is a vowel the program will continue without incrementing CONSONANTS and if there is a consonant the program will increment CONSONANTS. After counting the CONSONANTS the program simply prints the number of consonants.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | .MODEL SMALL .STACK 100H .DATA STRING DB 100 DUP(?) MSG1 DB "ENTER A STRING: $" MSG2 DB 0DH, 0AH, "NO. OF CONSONANTS_FOUNDS: $" CONSONANTS DW 0 .CODE MAIN PROC MOV AX, @DATA MOV DS, AX MOV ES, AX MOV AH, 9 LEA DX, MSG1 INT 21H LEA DI, STRING MOV AH, 1 READ: INT 21H CMP AL, 0DH JE ENDOFSTRING STOSB JMP READ ENDOFSTRING: MOV AL, "$" STOSB XOR BX, BX COUNT: MOV AL, STRING[BX] CMP AL, "$" JE EXIT CMP AL, "a" JE NOT_A_CONSONANT CMP AL, "e" JE NOT_A_CONSONANT CMP AL, "i" JE NOT_A_CONSONANT CMP AL, "o" JE NOT_A_CONSONANT CMP AL, "u" JE NOT_A_CONSONANT CMP AL, "A" JE NOT_A_CONSONANT CMP AL, "E" JE NOT_A_CONSONANT CMP AL, "I" JE NOT_A_CONSONANT CMP AL, "O" JE NOT_A_CONSONANT CMP AL, "U" JE NOT_A_CONSONANT MOV CX, CONSONANTS INC CX MOV CONSONANTS, CX INC BX JMP COUNT NOT_A_CONSONANT: INC BX JMP COUNT EXIT: MOV AH, 9 LEA DX, MSG2 INT 21H MOV AH, 2 MOV DX, CONSONANTS ADD DX, 30H INT 21H MAIN ENDP END MAIN |
No comments