- 2075 Baisakh · 8 marks
8086 ALP: alternate case display
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'.
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.
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.
.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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- 8086 ALP: vowels to uppercase, counts · Microprocessor, chapter 3
- 8086 ALP: words on lines and word count · Microprocessor, chapter 3
- 8086 ALP: convert text to uppercase · Microprocessor, chapter 3
- 8086 ALP: count vowels and display string · Microprocessor, chapter 3
- 8086 ALP: largest and smallest, display · Microprocessor, chapter 3
- 8086 ALP: display only alphabetic characters · Microprocessor, chapter 3
- Convert case based on first character · Computer Programming, chapter 7
- First and second order finite difference schemes · Computational Techniques in Civil Engineering, chapter 5 · asked 2×
- Townsend's first and second coefficients from data · High Voltage Engineering, chapter 6
- First and second stage BOD · Sanitary Engineering, chapter 5