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

# 8086 ALP: count vowels and display string

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2069 Poush, 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-display
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write an assembly language program for 8086 to read a string, count number of vowels in the string and display the string and its vowels count in a clear screen.

## Short answer

Read the string, classify each character with CLASSIFY, and increment VCNT whenever AL=1 (vowel). Clear the screen, terminate the string with '$', display it, then print the vowel count in decimal. For 'education', the count is 5.

## Answer

**Method:** read the string, count its vowels with `CLASSIFY` (AL = 1 means vowel) in the variable `VCNT`, then clear the screen and display the string followed by the vowel count 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: $'
    MSG2  DB 'String : $'
    MSG3  DB 'Number of vowels = $'
    VCNT  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          ; AL = 1 if vowel
    CMP  AL,1
    JNE  SKIP
    INC  VCNT              ; count vowel
SKIP:
    INC  SI
    LOOP NEXT
SHOW:
    MOV  BL,BUF+1
    MOV  BH,0
    MOV  BYTE PTR BUF[BX+2],'$'   ; terminate string
    CLRSCR
    DISPSTR MSG2
    LEA  DX,BUF+2
    MOV  AH,09H            ; display the string
    INT  21H
    DISPSTR CRLF
    DISPSTR MSG3
    MOV  AL,VCNT
    XOR  AH,AH
    CALL PRINT_DEC         ; display count
    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
```

**Output for `education`:** `String : education` and `Number of vowels = 5`.

## Check yourself

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

1. How is a vowel detected and counted?
   A. CLASSIFY returns AL = 1 and VCNT is incremented
   B. Each character is compared with 'a' only
   C. The string length minus consonants
   D. BUF+1 stores the vowel count
   Answer: A. Every character goes through CLASSIFY; AL = 1 means vowel, and INC VCNT counts it. (Key point: Counting)

2. Why is BUF[BX+2] set to '$' before display?
   A. To count the characters
   B. To end the string for function 09h
   C. To clear the buffer
   D. To convert to upper case
   Answer: B. Function 09h needs a '$' terminator, placed after the last typed character (index BUF+1 + 2). (Key point: Terminating string)

3. What does the program show after clearing the screen?
   A. Only the count
   B. The count first, then the string
   C. The string, then the vowel count on a new line
   D. Nothing until a key is pressed
   Answer: C. It prints 'String : ', the string, CRLF, and then 'Number of vowels = ' with the count. (Key point: Output order)

4. For education, what is the vowel count?
   A. 4
   B. 6
   C. 3
   D. 5
   Answer: D. e, u, a, i, o are the five vowels. (Key point: Example)

## Related in Microprocessor

- [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: 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: vowels to uppercase, counts](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-vowels-uppercase-count) — 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: largest and smallest, display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-largest-smallest-display) — 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

## Related in other subjects

- [Count number of 1s in ROM data](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-count-ones-asm) — Embedded System, chapter 9, asked 2×
- [Count number of 0s in ROM data](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-count-zeros-asm) — Embedded System, chapter 9, asked 2×
