An Assembly Language Program that reads a string of capital letters, ending with a carriage return, and display the longest sequence of consecutive alphabetically increasing capital letters read .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
.MODEL SMALL .STACK 100H .DATA PROMPT_1 DB 'Enter a string of Capital Letters : $' PROMPT_2 DB 0DH,0AH,'The longest consecutive increasing string is : $' INVALID DB 0DH,0AH,'Invalid string of Capital Letters. Try again : $' .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX LEA DX, PROMPT_1 ; load and display the string PROMPT_1 MOV AH, 9 INT 21H JMP @START ; jump to label @START @TRY_AGAIN: ; jump label LEA DX, INVALID ; load and display the string INVALID MOV AH, 9 INT 21H @START: ; jump label MOV AH, 1 ; set input function INT 21H ; read a character CMP AL, 0DH ; compare AL with CR JE @TRY_AGAIN ; jump to label @TRY_AGAIN if AL=CR CMP AL, 41H ; compare AL with 41H JB @TRY_AGAIN ; jump to label @TRY_AGAIN if AL<41H CMP AL, 5AH ; comapre AL with 5AH JA @TRY_AGAIN ; jump to label @TRY_AGAIN if AL>5AH MOV BL, AL ; set BL=AL MOV BH, AL ; set BH=AL MOV DH, AL ; set DH=AL MOV DL, 1 ; set DL=1 MOV CL, 1 ; set CL=1 @INPUT: ; loop label INT 21H ; read a character CMP AL, 0DH ; compare AL with CR JE @END_INPUT ; jump to label @END_INPUT if AL=CR CMP AL, 41H ; compare AL with 41H JB @TRY_AGAIN ; jump to label @TRY_AGAIN if AL<41H CMP AL, 5AH ; comapre AL with 5AH JA @TRY_AGAIN ; jump to label @TRY_AGAIN if AL>5AH INC BL ; set BL=BL+1 CMP AL, BL ; compare AL with BL JNE @CHECK_AND_REPLACE ; jump to label @CHECK_AND_REPLACE if AL!=BL INC CL ; set CL=CL+1 JMP @INPUT ; jump to label @INPUT @CHECK_AND_REPLACE: ; jump label CMP CL, DL ; compare CL with DL JLE @SKIP_UPDATION_1 ; jump to label @SKIP_UPDATION_1 if CL<=DL MOV DH, BH ; set DH=BH MOV DL, CL ; set DL=CL @SKIP_UPDATION_1: ; jump label MOV BH, AL ; set BH=AL MOV BL, AL ; set BL=AL MOV CL, 1 ; set CL=1 JMP @INPUT ; jump to label @INPUT @END_INPUT: ; jump label CMP CL, DL ; compare CL with DL JLE @SKIP_UPDATION_2 ; jump to label @SKIP_UPDATION_2 if CL<=DL MOV DH, BH ; set DH=BH MOV DL, CL ; set DL=CL @SKIP_UPDATION_2: ; jump label MOV BX, DX ; set BX=DX LEA DX, PROMPT_2 ; load and display the string PROMPT_2 MOV AH, 9 INT 21H XOR CX, CX ; clear CX MOV CL, BL ; set CL=BL MOV DL, BH ; set DL=BH MOV AH, 2 ; set output function @OUTPUT: ; loop label INT 21H ; print a character INC DL ; set DL=DL+1 LOOP @OUTPUT ; jump to label @OUTPUT if CX!=0 MOV AH, 4CH ; return control to DOS INT 21H MAIN ENDP END MAIN |