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

# 8086 ALP: alternate case display

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2075 Baisakh, 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-alternate-case
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write an ALP in 8086 to read a word and display all the alphabets in alternate case (first alphabet in lowercase, second in uppercase, third in lowercase and so on) in a clear window.

## Short answer

Read a string via DOS function 0Ah, clear screen, then process characters. Toggle a flag to force letters to lowercase then uppercase alternately (OR 20h to lowercase, AND 0DFh to uppercase). Non-letters are displayed unchanged and do not toggle. Example input 'Microprocessor' produces 'mIcRoPrOcEsSoR'.

## Answer

**Method:** read the word with DOS function 0Ah, clear the screen with INT 10h (function 06h), then scan each character. Letters are forced to lower case for the 1st, 3rd, ... letter and to upper case for the 2nd, 4th, ... letter; BL toggles between 0 (next is lower) and 1 (next is upper). Non-letters are displayed unchanged and do not change the toggle.

```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 word: $'
    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
    LEA  DX,BUF            ; read string (function 0Ah)
    MOV  AH,0AH
    INT  21H
    CLRSCR                 ; clear window

    LEA  SI,BUF+2          ; SI -> first character
    MOV  CL,BUF+1          ; CL = number of characters typed
    MOV  CH,0
    JCXZ EXIT              ; nothing typed
    MOV  BL,0              ; BL=0: next letter must be lower case
NEXT:
    MOV  DL,[SI]           ; get character
    CMP  DL,'A'
    JB   SHOW              ; below 'A' : not a letter
    CMP  DL,'Z'
    JBE  LETTER            ; 'A'..'Z'
    CMP  DL,'a'
    JB   SHOW              ; between 'Z' and 'a'
    CMP  DL,'z'
    JA   SHOW              ; above 'z'
LETTER:
    OR   DL,20H            ; make it lower case
    CMP  BL,0
    JE   FLIP              ; lower case wanted
    AND  DL,0DFH           ; upper case wanted
FLIP:
    XOR  BL,1              ; toggle for next letter
SHOW:
    MOV  AH,02H            ; display character in DL
    INT  21H
    INC  SI
    LOOP NEXT
EXIT:
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

END MAIN
```

**Example:** input `Microprocessor` → output `mIcRoPrOcEsSoR`.

## Check yourself

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

1. What is the role of BL in the alternate-case program?
   A. It stores the number of characters typed
   B. It holds the current character being converted
   C. It toggles between 0 (next letter lower) and 1 (next letter upper)
   D. It stores the screen row for display
   Answer: C. BL is a flag flipped with XOR BL,1 after each letter, so letters alternate between lower and upper case. (Key point: Toggle register)

2. What happens to a non-letter such as a digit or space?
   A. It is displayed unchanged and the toggle is not flipped
   B. It is skipped and not displayed
   C. It is displayed and the toggle is flipped
   D. It is converted to lower case
   Answer: A. Non-letters jump straight to SHOW, bypassing the XOR BL,1, so they do not affect the alternation. (Key point: Non-letters)

3. How does the program force a letter to lower case first and then to upper case when needed?
   A. SUB 20H for lower, ADD 20H for upper
   B. OR DL,20H for lower, then AND DL,0DFH for upper
   C. AND DL,0DFH for lower, then OR DL,20H for upper
   D. XOR DL,20H in both cases
   Answer: B. Setting bit 5 (OR 20H) gives lower case; clearing bit 5 (AND 0DFH) gives upper case. (Key point: Case conversion)

4. Which services read the word and clear the screen?
   A. INT 21h function 01h and INT 10h function 02h
   B. INT 21h function 09h and INT 10h function 0Eh
   C. INT 21h function 0Ah and INT 10h function 06h
   D. INT 21h function 02h and INT 21h function 4Ch
   Answer: C. Function 0Ah is buffered string input and INT 10h function 06h scrolls/blanks the window. (Key point: Input and clear)

## Related in Microprocessor

- [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: convert text to uppercase](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-uppercase-text) — Microprocessor, chapter 3
- [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: 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

- [Convert case based on first character](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswap-case-first-char-word) — Computer Programming, chapter 7
- [First and second order finite difference schemes](https://www.bctengineer.com/question.md?key=semester_8%2Fcomputational_techniques_in_civil_engineering%3Afd-first-second-order-schemes) — Computational Techniques in Civil Engineering, chapter 5, asked 2×
- [Townsend's first and second coefficients from data](https://www.bctengineer.com/question.md?key=semester_8%2Fhigh_voltage_engineering%3Atownsend-first-second-coefficients) — High Voltage Engineering, chapter 6
- [First and second stage BOD](https://www.bctengineer.com/question.md?key=semester_6%2Fsanitary_engineering%3Afirst-second-stage-bod-400) — Sanitary Engineering, chapter 5
