---
title: "8086 ALP: count vowels, consonants, numerals"
subject: "Microprocessor"
chapter: 3
key: "semester_4/microprocessor:alp-8086-count-vowels-consonants-numerals"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-count-vowels-consonants-numerals
site: BCT Engineering
---

# 8086 ALP: count vowels, consonants, numerals

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2068 Bhadra, 8 marks
- Video: [Assembly program of Counting Vowel](https://www.youtube.com/watch?v=BeFkAqcQUos) — study online school
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-count-vowels-consonants-numerals
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write a program in 8086 to read a string and count the number of vowels, consonants, numerals and other characters and display the count.

## Short answer

Use four counters NV, NC, ND, NO. Classify each character as vowel, consonant, or not a letter; for non-letters, test '0' to '9' as a numeral, otherwise count as other. Display all four counts in decimal using PRINT_DEC.

## Answer

**Method:** four counters (`NV`, `NC`, `ND`, `NO`) hold vowels, consonants, numerals and other characters. For each character `CLASSIFY` returns 1 (vowel), 2 (consonant) or 0 (not a letter); for 0 the character is tested for '0'..'9', otherwise it is counted as "other" (space, punctuation, symbols). The four counts are displayed in decimal.

```asm
.MODEL SMALL
.STACK 100H

DISPSTR MACRO MSG            ; display a '$'-terminated string
        LEA  DX,MSG
        MOV  AH,09H
        INT  21H
        ENDM

CLRSCR  MACRO                ; clear screen and home the cursor
        MOV  AX,0600H        ; scroll whole window (AL=0 -> blank it)
        MOV  BH,07H          ; normal attribute
        MOV  CX,0000H        ; upper-left corner (row 0, col 0)
        MOV  DX,184FH        ; lower-right corner (row 24, col 79)
        INT  10H
        MOV  AH,02H          ; set cursor position
        MOV  BH,00H          ; page 0
        MOV  DX,0000H        ; row 0, col 0
        INT  10H
        ENDM

.DATA
    MSG1  DB 'Enter a string: $'
    MV    DB 13,10,'Vowels     = $'
    MC    DB 13,10,'Consonants = $'
    MD    DB 13,10,'Numerals   = $'
    MO    DB 13,10,'Others     = $'
    NV    DB 0
    NC    DB 0
    ND    DB 0
    NO    DB 0
    BUF   DB 80, ?, 80 DUP(0)   ; DOS buffered-input area (max, actual, chars)
    CRLF  DB 13,10,'$'

.CODE
MAIN PROC
    MOV  AX,@DATA
    MOV  DS,AX

    DISPSTR MSG1           ; prompt
    LEA  DX,BUF            ; read the string with DOS function 0Ah
    MOV  AH,0AH
    INT  21H

    LEA  SI,BUF+2
    MOV  CL,BUF+1
    MOV  CH,0
    JCXZ SHOW
NEXT:
    MOV  DL,[SI]
    CALL CLASSIFY
    CMP  AL,1
    JE   ISV
    CMP  AL,2
    JE   ISC
    CMP  DL,'0'            ; not a letter: digit?
    JB   ISO
    CMP  DL,'9'
    JA   ISO
    INC  ND                ; numeral
    JMP  SKIP
ISV:INC  NV                ; vowel
    JMP  SKIP
ISC:INC  NC                ; consonant
    JMP  SKIP
ISO:INC  NO                ; other character
SKIP:
    INC  SI
    LOOP NEXT
SHOW:
    DISPSTR MV
    MOV  AL,NV
    XOR  AH,AH
    CALL PRINT_DEC
    DISPSTR MC
    MOV  AL,NC
    XOR  AH,AH
    CALL PRINT_DEC
    DISPSTR MD
    MOV  AL,ND
    XOR  AH,AH
    CALL PRINT_DEC
    DISPSTR MO
    MOV  AL,NO
    XOR  AH,AH
    CALL PRINT_DEC
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

; ---- classify the character in DL
;      returns AL = 1 vowel, 2 consonant, 0 not a letter (DL unchanged)
CLASSIFY PROC
    MOV  AL,DL
    OR   AL,20H            ; fold to lower case (valid for letters)
    CMP  AL,'a'
    JB   NOTLET
    CMP  AL,'z'
    JA   NOTLET
    CMP  AL,'a'
    JE   VOW
    CMP  AL,'e'
    JE   VOW
    CMP  AL,'i'
    JE   VOW
    CMP  AL,'o'
    JE   VOW
    CMP  AL,'u'
    JE   VOW
    MOV  AL,2              ; consonant
    RET
VOW:MOV  AL,1              ; vowel
    RET
NOTLET:MOV AL,0            ; not a letter
    RET
CLASSIFY ENDP

; ---- print the unsigned number in AX in decimal (registers preserved)
PRINT_DEC PROC
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX
    MOV  BX,10
    XOR  CX,CX             ; digit counter
PD1:XOR  DX,DX
    DIV  BX                ; AX = quotient, DX = remainder (digit)
    PUSH DX
    INC  CX
    OR   AX,AX
    JNZ  PD1
PD2:POP  DX                ; digits come out in correct order
    ADD  DL,30H            ; to ASCII
    MOV  AH,02H
    INT  21H
    LOOP PD2
    POP  DX
    POP  CX
    POP  BX
    POP  AX
    RET
PRINT_DEC ENDP

END MAIN
```

**Example:** `Room 101 !` → Vowels = 2, Consonants = 2, Numerals = 3, Others = 3 (the 2 blanks and `!` are the 3 others).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How are characters classified?
   A. By CLASSIFY into vowel (1), consonant (2) or non-letter (0), then non-letters are tested for '0'..'9'
   B. By comparing with 'a' only
   C. By the ASCII parity
   D. By the length of the string
   Answer: A. Letters are handled by CLASSIFY; when it returns 0 the digit test decides numeral versus other. (Key point: Four counters)

2. Which characters go into the 'other' count?
   A. Digits
   B. Vowels
   C. Anything that is not a letter and not a digit, such as spaces and symbols
   D. Capital letters
   Answer: C. Spaces, punctuation and symbols fail the letter and digit tests. (Key point: Other characters)

3. How is a numeral recognised?
   A. It is above 'z'
   B. It lies between '0' and '9' after CLASSIFY returned 0
   C. AL = 3
   D. It is below 20H
   Answer: B. The program compares DL with '0' and '9'; in range means numeral. (Key point: Digit test)

4. For Room 101 ! what are the counts of vowels, consonants, numerals and others?
   A. 2, 2, 3, 3
   B. 2, 3, 3, 2
   C. 3, 2, 3, 3
   D. 2, 2, 3, 2
   Answer: A. Vowels o,o = 2; consonants R,m = 2; digits 1,0,1 = 3; two spaces and ! = 3 others. (Key point: Example)

## Related in Microprocessor

- [8086 ALP: count vowels and display string](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-count-vowels-display) — Microprocessor, chapter 3
- [8086 ALP: vowels and consonants separately](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-vowels-consonants-separately) — Microprocessor, chapter 3
- [8086 ALP: display only alphabetic characters](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alphabetic-only) — Microprocessor, chapter 3
- [8086 ALP: vowels to uppercase, counts](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-vowels-uppercase-count) — Microprocessor, chapter 3
- [8086 ALP: words on lines and word count](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-words-lines-count) — Microprocessor, chapter 3
- [8086 ALP: alternate case display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alternate-case) — Microprocessor, chapter 3

## Related in other subjects

- [Display N characters using default arguments](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3An-chars-default-args-program) — Object Oriented Programming, chapter 3
