Nahid8195

Problem 1

Dec 9th, 2021 (edited)
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .MODEL SMALL
  2. .STACK 100H
  3.  
  4.  .DATA
  5.    PROMPT_1  DB  'Enter a line of text : $'
  6.    PROMPT_2  DB  0DH,0AH,'Output : $'
  7.    PROMPT_4  DB  0DH,0AH,' *****  No Capital Letters  *****$'
  8.  
  9.    FLAG          DB  0
  10.    FIRST_LETTER  DB  5BH
  11.    LAST_LETTER   DB  40H
  12.  
  13.  .CODE
  14.    MAIN PROC
  15.      MOV AX, @DATA                ; initialize DS
  16.      MOV DS, AX
  17.  
  18.      LEA DX, PROMPT_1             ; load and display the string PROMPT_1
  19.      MOV AH, 9
  20.      INT 21H
  21.  
  22.      MOV AH, 1                    ; set input function
  23.  
  24.      @INPUT:                      ; jump label
  25.        INT 21H                    ; read a character
  26.  
  27.        MOV BL, AL                 ; set BL=AL
  28.  
  29.        CMP BL, 0DH                ; compare BL with CR
  30.        JE @END_INPUT              ; jump to label @END_INPUT if BL=CR
  31.  
  32.        CMP BL, "A"                ; compare BL with "A"
  33.        JL @INPUT                  ; jump to label @INPUT if BL<A
  34.  
  35.        MOV FLAG, 1                ; set FLAG=1
  36.  
  37.        CMP BL, "Z"                ; compare BL with "Z"
  38.        JG @INPUT                  ; jump to label @INPUT if BL>Z
  39.  
  40.        CMP BL, FIRST_LETTER       ; compare BL with variable FIRST_LETTER
  41.        JG @NEXT                   ; jump to label @NEXT if BL>FIRST_LETTER
  42.        MOV FIRST_LETTER, BL       ; set FIRST_LETTER=BL
  43.  
  44.        @NEXT:                     ; jump label
  45.          CMP BL, LAST_LETTER      ; compare BL with variable LAST_LETTER
  46.          JL @INPUT                ; jump to label @INPUT if BL<LAST_LETTER
  47.          MOV LAST_LETTER, BL      ; set LAST_LETTER=BL
  48.  
  49.      JMP @INPUT                   ; jump to label @INPUT
  50.  
  51.      @END_INPUT:                  ; jump label
  52.  
  53.      CMP FLAG, 1                  ; compare FLAG with 1            
  54.      JE @DISPLAY                  ; jump to label @DISPLAY if FLAG=1
  55.  
  56.      LEA DX, PROMPT_4             ;  load and display the string PROMPT_4
  57.      MOV AH, 9                    
  58.      INT 21H
  59.  
  60.      JMP @END                     ; jump to label @END
  61.  
  62.      @DISPLAY:                    ; jump label
  63.        LEA DX, PROMPT_2           ; load and display the string PROMPT_2
  64.        MOV AH, 9                  
  65.        INT 21H                    
  66.  
  67.        MOV AH, 2                  ; set output function
  68.        MOV DL, FIRST_LETTER       ; set DL=FIRST_LETTER
  69.        INT 21H                    ; print a character
  70.                    
  71.  
  72.        MOV AH, 2                  ; set output function
  73.        MOV DL, LAST_LETTER        ; set DL=LAST_LETTER
  74.        INT 21H                    ; print a character
  75.        
  76.  
  77.      @END:                        ; jump label
  78.  
  79.      MOV AH, 4CH                  ; return control to DOS
  80.      INT 21H
  81.    MAIN ENDP
  82.  END MAIN
Add Comment
Please, Sign In to add comment