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

# 8086 ALP: vowels and consonants separately

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2072 Asoj, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-vowels-consonants-separately
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write an assembly language program to read a string from the user and display vowels and consonants separately.

## Short answer

Read string using DOS 0Ah, classify each character as vowel, consonant, or other; display vowels then consonants on separate lines. Example Hello World gives vowels eoo and consonants HllWrld.

## Answer

**Method:** read the string with function 0Ah. The procedure `SHOWCLS` scans the string and displays only the characters whose class (returned by `CLASSIFY`) equals the class in BH: 1 for vowels, 2 for consonants. It is called twice, so vowels appear on the first line and consonants on the second. Spaces, digits and symbols are ignored.

```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: $'
    MSGV  DB 13,10,'Vowels     : $'
    MSGC  DB 13,10,'Consonants : $'
    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

    DISPSTR MSGV
    MOV  BH,1              ; class 1 = vowels
    CALL SHOWCLS
    DISPSTR MSGC
    MOV  BH,2              ; class 2 = consonants
    CALL SHOWCLS
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

; ---- display characters of the string whose class = BH
SHOWCLS PROC
    LEA  SI,BUF+2
    MOV  CL,BUF+1
    MOV  CH,0
    JCXZ SCEND
SC1:MOV  DL,[SI]
    CALL CLASSIFY          ; AL = class of DL
    CMP  AL,BH
    JNE  SC2
    MOV  AH,02H            ; display DL
    INT  21H
SC2:INC  SI
    LOOP SC1
SCEND:RET
SHOWCLS 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

END MAIN
```

**Example:** input `Hello World` → Vowels: `eoo`, Consonants: `HllWrld`.

## Check yourself

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

1. What does CLASSIFY return?
   A. 1 for consonant, 2 for vowel, 0 otherwise
   B. 1 for vowel, 2 for consonant, 0 for non-letter
   C. The ASCII code of the character
   D. 0 for vowel, 1 for consonant
   Answer: B. AL = 1 vowel, 2 consonant, 0 not a letter. (Key point: Class codes)

2. How does the program show vowels and consonants separately?
   A. It sorts the string first
   B. It uses two buffers
   C. It calls SHOWCLS twice with BH = 1 then BH = 2
   D. It reads the string twice
   Answer: C. SHOWCLS prints only characters whose class equals BH, so one call prints vowels and the second prints consonants. (Key point: Two passes)

3. Why does CLASSIFY do OR AL,20H before comparing?
   A. To convert digits to letters
   B. To clear the carry flag
   C. To make the letter upper case
   D. To treat upper and lower case letters alike
   Answer: D. Setting bit 5 turns capitals into lower case, so only 'a','e','i','o','u' need testing. (Key point: Case folding)

4. For input Hello World, what are the vowel and consonant outputs?
   A. Vowels eoo, consonants HllWrld
   B. Vowels eoo, consonants Hll Wrld
   C. Vowels eo, consonants HllWrld
   D. Vowels eoo, consonants hllwrld
   Answer: A. Spaces are ignored and original case is kept, giving eoo and HllWrld. (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: count vowels, consonants, numerals](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-count-vowels-consonants-numerals) — 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: largest and smallest, display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-largest-smallest-display) — 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
- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
