Tuesday, 28 July 2015

(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 Assembly Language Solution.


(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.

Sample execution:
ENTER A STKING OF CAPITAL LETTERS:
FGHADEFGHC
THE LONGEST CONSECUTIVELY INCREASING STRING IS:
DEFGH
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 6 , PROGRAMMING EXERCISE ,
ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 6 , CONSECUTIVE ALPHABETICALLY INCREASING CAPITAL LETTERS .

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    INPUTMSG  DB  'ENTER A STRING OF CAPITAL LETTERS : $'
    OUTPUTMSG  DB  0DH,0AH,'THE LONGEST CONSECUTIVE INCREASING STRING IS : $'
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV CH,0
 
    MOV AH,9
    LEA DX,INPUTMSG
    INT 21H
 
    INPUT_1:
        MOV AH,1
        INT 21H
     
        CMP AL,0DH
        JE END_
        MOV CL,1
        MOV BL,AL
        MOV DH,AL
        INPUT_2:
            INT 21H
         
            CMP AL,0DH
            JE END_
         
            INC BL
            CMP BL,AL
            JNE INIT
            INC CL
            JMP INPUT_2
        INIT:
            CMP CH,CL
            JL UPDATE
         
            MOV CL,1
            MOV BL,AL
            MOV DH,AL
            JMP INPUT_2
         
            UPDATE:
                MOV CH,CL
                MOV BH,DH
             
                MOV CL,1
                MOV BL,AL
                MOV DH,AL
                JMP INPUT_2
        END_:
            CMP CH,CL
            JL REUPDATE
            JMP END_2
         
            REUPDATE:
                MOV CH,CL
                MOV BH,DH
                JMP END_2
        END_2:
       
        MOV AH,9
        LEA DX,OUTPUTMSG
        INT 21H
     
        MOV AH,2
        MOV DL,BH
        OUTPUT:
            CMP CH,0
            JE FINISH
         
            DEC CH
            INT 21H
            INC DL
            JMP OUTPUT
        FINISH:  
     
    MOV AH,4CH
    INT 21H
   
    MAIN ENDP
END MAIN

No comments:

Post a Comment