Bsef24m040 # 4
Bsef24m040 # 4
Pre lab # 4
1. Write a program to display a “?”, read two capital letters, and display them on the next
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC
;PRINT ?
MOV DL,'?'
MOV AH,02
INT 21H
;INPUT # 1
MOV AH,01
INT 21H
MOV BL,AL
;INPUT # 2
MOV AH,01
INT 21H
MOV BH,AL
;COMPARISON OF ALPHABETS
CMP BL,BH
JNLE DISPLAY_2ND
;DISPLAY_1ST_FIRST
DISPLAY_1ST:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
MOV DL,BL
MOV AH,02
INT 21H
MOV DL,BH
MOV AH,02
INT 21H
JMP END_
;DISPLAY_2ND_FIRST
DISPLAY_2ND:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
MOV DL,BH
MOV AH,02
INT 21h
MOV DL,BL
MOV AH,02
INT 21H
;END_PROGRAM
END_:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
2. Write a program to display the extended ASCII characters (ASCII codes 80h to FFh).
Display 10 characters per line, separated by blanks. Stop after the extended characters
.STACK 100H
.DATA
INCR DB 80H
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
WHILE:
CMP INCR,0FFH
JE EXIT
;PRINTS CHARACTER
MOV DL,INCR
MOV AH,02
INT 21H
;PRINTS SPACE
MOV AH,09H
INT 21H
;INCREASE CHARACTER
INC INCR
;JUMPS TO WHILE
JMP WHILE
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
3. Write a program that will prompt the user to enter a hex digit character ("0"..."9" or
"A"..."F"), display it on the next line in decimal, and ask the user if he or she wants to do
it again. If the user types "y" or "Y", the program repeats; if the user types anything else,
the program terminates. If the user enters an illegal character, prompt the user to try
again.
4. Do programming exercise 3, except that if the user fails to enter a hex-digit character
.MODEL SMALL
.STACK 100H
.DATA
CHOICE DB 0AH
.CODE
MAIN PROC
;MOVES DATA TO DS
MOV AX,@DATA
MOV DS,AX
MOV CX,03
START:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
;ENTRY PRINTER
MOV AH,09
INT 21H
;TAKES INPUT
MOV AH,01
INT 21H
MOV BL,AL
;CHECKS HEXA-DIGIT
CMP BL,'9'
JBE IS_DIGIT
CMP BL,'F'
JBE IS_ALPHABET
;CONFIRMS VALIDATION
DEC CX
CMP CX,0
JE TERMINATOR
JMP START
IS_DIGIT:
SUB BL,30H
ADD BL,30H
JMP DISPLAY
IS_ALPHABET:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
MOV AH,09
INT 21H
;PRINTS DECIMALS
MOV DL,31H
MOV AH,02
INT 21H
SUB BL,11H
;DISPLAY DECIMAL
MOV DL,BL
MOV AH,02
INT 21H
JMP GET_CHOICE
DISPLAY:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
MOV AH,09
INT 21H
;PRINTS DECIMALS
MOV DL,BL
MOV AH,02
INT 21H
GET_CHOICE:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
MOV AH,09
INT 21H
;GET CHOICE
MOV AH,01
INT 21H
MOV CHOICE,AL
CMP CHOICE,'Y'
JE START
CMP CHOICE,'y'
JE START
CMP CHOICE,'N'
JMP END_
CMP CHOICE,'n'
JMP END_
JMP END_
TERMINATOR:
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
;STRING PRINTER
MOV AH,09
INT 21H
END_:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
5. (hard) Write a program that reads a string of capital letters, ending with a carriage
return, and displays the longest sequence of consecutive alphabetically increasing capital
letters read.
.MODEL SMALL
.STACK 100H
.DATA
BUFFER DB 50
DB ?
DB 50 DUP(?)
.CODE
MAIN PROC
MOV DS, AX
INT 21H
;Input string
INT 21H
MOV DL,10
MOV AH,02
INT 21H
MOV DL,13
MOV AH,02
INT 21H
INT 21H
MOV CH, 0
PRINT_LOOP:
INT 21H
INC SI
LOOP PRINT_LOOP
; Exit program
INT 21H
MAIN ENDP
END MAIN