.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'Enter the First character : $'
STR2 DB 'Enter the Second character : $'
STR3 DB ' is first$'
Mistake DB 13,10,"Only letter is accepted",13,10,'$'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
@@:
MOV DX,offset STR1 ; load and print STR1
MOV AH, 9
INT 21H
CALL GetLetter
JC @B
MOV BL, AL ; save the input character into BL
MOV AH, 2 ; carriage return
MOV DL, 0DH
INT 21H
MOV DL, 0AH ; line feed
INT 21H
@@:
MOV DX,offset STR2 ; load and print STR2
MOV AH, 9
INT 21H
CALL GetLetter
JC @B
MOV BH, AL ; save the input character into BH
MOV AH, 2 ; carriage return
MOV DL, 0DH
INT 21H
MOV DL, 0AH ; line feed
INT 21H
PUSH BX
OR BX,2020h ; force lower case
CMP BL, BH ; compare the BL and BH
POP BX
JNBE @ELSE ; jump to label @ELSE if BL>BH
MOV DL, BL ; move first character into DL
JMP @DISPLAY ; jump to label @DISPLAY
@ELSE: ; jump label
MOV DL, BH ; move second character into DL
@DISPLAY: ; jump label
MOV AH, 2 ; print the character
INT 21H
MOV DX,offset STR3 ; load and print STR3
MOV AH, 9
INT 21H
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
GetLetter PROC NEAR
MOV AH, 1 ; read a character
INT 21H
CMP AL,41h ;'A'
JB ErrorMsg
CMP AL,5Ah ;'Z'
JBE Done
CMP AL,61h ;'a'
JB ErrorMsg
CMP AL,7Ah ;'z'
JA ErrorMsg
Done:
CLC
RET
ErrorMsg:
MOV DX,offset Mistake
MOV AH, 9
INT 21H
STC
RET
GetLetter ENDP
END MAIN
Edited by Alexander, 28 January 2011 - 11:14 PM.
bb [code] tags


Sign In
Create Account

Back to top









