Skip to main content

8086 ALP: vowels to uppercase, counts

Short answer

Read the string and convert each lower-case vowel to upper case by AND 0DFH. Replace the Enter with '$', display the converted string on a new line, then count all 'A' to 'Z' characters in a second pass. Display the count on another new line using PRINT_DEC.

Write a program in 8086 to convert the vowels to uppercase from a string entered by the user and display the converted string in a new line. Also count the number of uppercase letters in the converted string and display the count in a new line.

Method: read the string. For each character, CLASSIFY tells whether it is a vowel; a lower-case vowel is converted to upper case (AND 0DFH) and stored back. After conversion, the Enter code is replaced by $, the string is displayed on a new line, and a second pass counts the upper-case letters ('A' to 'Z', which includes original capitals) and displays the count on another new line.

.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 'Uppercase letters = $'
    UCNT  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
CONV:                      ; pass 1 : vowels -> upper case
    MOV  DL,[SI]
    CALL CLASSIFY
    CMP  AL,1
    JNE  NXT1              ; not a vowel
    AND  DL,0DFH           ; make upper case
    MOV  [SI],DL
NXT1:
    INC  SI
    LOOP CONV

    LEA  SI,BUF+2          ; pass 2 : count capital letters
    MOV  CL,BUF+1
    MOV  CH,0
CNT:MOV  AL,[SI]
    CMP  AL,'A'
    JB   NXT2
    CMP  AL,'Z'
    JA   NXT2
    INC  UCNT              ; 'A'..'Z'
NXT2:
    INC  SI
    LOOP CNT
SHOW:
    MOV  BL,BUF+1
    MOV  BH,0
    MOV  BYTE PTR BUF[BX+2],'$'  ; terminate the string
    DISPSTR CRLF           ; new line
    LEA  DX,BUF+2
    MOV  AH,09H            ; show converted string
    INT  21H
    DISPSTR CRLF           ; new line
    DISPSTR MSG2
    MOV  AL,UCNT
    XOR  AH,AH
    CALL PRINT_DEC         ; show 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

Example: Nepal is Nice → NEpAl Is NIcE; capitals N, E, A, I, N, I, E = 7 (the count shown is 7).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 3 questions →