Sunday, 28 June 2015

Suppose DH Contains 8Ah And CL Contains 2. What Are The Values Of DH And Of CF After The Instruction SHR DH,CL Is Executed In Assembly Language Solution.

/*
  Suppose DH Contains 8Ah And CL Contains 2. What Are The Values Of DH And Of CF
  After The Instruction SHR DH,CL Is Executed In Assembly Language Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
  STR1 DB 'DH = '
  VAL1 DB ?
  STR2 DB 0AH,0DH,'CF = '
  VAL2 DB ?
  FINISH DB '$'


.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AL,8AH
    MOV CL,2    ;
    SHR AL,CL   ; RIGHTSHIFTING THE VALUE 2 TIMES
    MOV VAL1,AL ;
 
    JC ONE      ; JUMP IF CARRY ISEQUAL 1
 
    MOV BL,'0'  ;
    MOV VAL2,BL ;SET BL TO 0 IF CARRY 0
    JMP END_    ;
 
    ONE:
        MOV BL,'1'    ;
        MOV VAL2,BL   ;SET BL TO 1 IF CARRY 1
        JMP END_      ;
 
     
    END_:
 
    MOV AH,9      ;
    LEA DX,STR1   ;PRINTING THE FINAL RESULT
    INT 21H       ;
 
    MOV AH,4CH
    INT 21H
 
    MAIN ENDP
END MAIN

Suppose DH Contains 8Ah And CL Contains 3. What Are The Values Of DH And Of CF After The Instruction SHL DH,CL Is Executed In Assembly Language Solution.

/*
    Suppose DH Contains 8Ah And CL Contains 3. What Are The Values Of DH And Of CF
    After The Instruction SHL DH,CL Is Executed In Assembly Language Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
  STR1 DB 'DH = '
  VAL1 DB ?
  STR2 DB 0AH,0DH,'CF = '
  VAL2 DB ?
  FINISH DB '$'


.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AL,8AH
    MOV CL,3    ;
    SHL AL,CL   ; LEFTSHIFTING THE VALUE 3 TIMES
    MOV VAL1,AL ;
 
    JC ONE      ; JUMP IF CARRY ISEQUAL 1
 
    MOV BL,'0'  ;
    MOV VAL2,BL ;SET BL TO 0 IF CARRY 0
    JMP END_    ;
 
    ONE:
        MOV BL,'1'    ;
        MOV VAL2,BL   ;SET BL TO 1 IF CARRY 1
        JMP END_      ;
 
     
    END_:
 
    MOV AH,9      ;
    LEA DX,STR1   ;PRINTING THE FINAL RESULT
    INT 21H       ;
 
    MOV AH,4CH
    INT 21H
 
    MAIN ENDP
END MAIN

Check AL Contains Even Number Or Odd Number In Assembly Language Solution.

// Check AL Contains Even Number Or Odd Number In Assembly Language Solution.

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA

    STREVEN DB 0AH,0DH,'NUMBER IS EVEN$'
    STRODD DB 0AH,0DH,'NUMBER IS ODD$'
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,1
    INT 21H
 
    TEST AL,01H
    JZ EVEN
 
    MOV AH,9
    LEA DX,STRODD
    INT 21H
 
    JMP END_:
 
    EVEN:
        MOV AH,9
        LEA DX,STREVEN
        INT 21H
     
        JMP END_
     
    END_:
 
    MOV AH,4CH
    INT 21H
 
    MAIN ENDP
END MAIN

Converting A Lower Case Letter To Upper Case Letter Using And Operator In Assembly Language.

/*
  Converting A Lower Case Letter To Upper Case Letter Using And Operator In Assembly Language
  Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.CODE

MAIN PROC
 
 
    MOV AL,61H      ;       (a) 61h = 01100001b
    AND AL,0DFH     ;      AND  DFh = 11011111b
                    ;   ---------------------------
                    ;       (A) 41H = 01000001b
 
    MOV AH,2        ;
    MOV DL,AL       ;  PRINTING THE UPPERCASE LETTER
    INT 21H         ;
                 
 
    MOV AH,4CH      ;
    INT 21H         ;
 
    MAIN ENDP
END MAIN

Converting A Upper Case Letter To Lower Case Letter Using Or Operator In Assembly Language.

/*
 Converting A Upper Case Letter To Lower Case Letter Using Or Operator In Assembly Language
 Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.CODE

MAIN PROC
 
 
    MOV AL,41H      ;       (A)  41h = 01000001b
    OR AL,20H       ;    OR(spa) 20h = 00100000b
                    ;   ---------------------------
                    ;       (a)  61H = 01100001b
 
    MOV AH,2        ;
    MOV DL,AL       ;  PRINTING THE LOWERCASE LETTER
    INT 21H         ;
                 
 
    MOV AH,4CH      ;
    INT 21H         ;
 
    MAIN ENDP
END MAIN

Set The Most Significant Bit ( MSB ) And Lest Significant Bit ( LSB ) Of AL While Preserving The Other Bits Assembly Language Solution.

/*
   Set The Most Significant Bit ( MSB ) And Lest Significant Bit ( LSB ) Of AL While
   Preserving The Other Bits Assembly Language Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H

.CODE

MAIN PROC
 
 
    MOV AL,1h   ;     01h = 00000001b
                ;  OR 81h = 10000001b
    OR AL,81h   ;  ---------------------    THIS CODE WILL SET
                ;     81h = 10000001b                MSB AND LSB TO '1'
 
    MOV AH,2    ;
    MOV DL,AL   ;  PRINTING THE RESULT
    INT 21H     ;
 
    MOV AH,4CH
    INT 21H
    MAIN ENDP
END MAIN

Clear The Sign Bit Of AL While Leaving The Other Bits Unchanged In Assembly Language Solution.

/*
  Clear The Sign Bit Of AL While Leaving The Other Bits Unchanged In Assembly Language
  Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H

.CODE

MAIN PROC
 
    MOV AL,86h   ;      86h = 10000110b
                 ;  AND 7Fh = 01111111b
    AND AL,7Fh   ;  ---------------------    THIS CODE WILL CLEAR
                 ;      06H = 00000110b                  THE SIGN BIT '1' TO '0'
 
    MOV AH,2     ;
    MOV DL,AL    ;  PRINTING THE RESULT
    INT 21H      ;
 
    MOV AH,4CH
    INT 21H
    MAIN ENDP
END MAIN

Sunday, 21 June 2015

Write A Program That Will Prompt The User To Enter A Hex Digit Character ("0"..."9" or "A".."B"),Display It On The Next Line In Decimal Repeated Assembly Language Solution.

/*
  Write a program that will prompt the user to enter a hex digit character ("0"..."9" or "A".."B"),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.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    FPROMPT DB 0AH,0DH,'ENTER A HEX DIGIT: $'
    INPUTVAL DB ?
    ONE DB 0AH,0DH,'1$'
    MSG DB 0AH,0DH,'SO YOU WANT TO DO IT AGAIN? $'
    IL DB 0AH,0DH,'ILLEGAL CHARACTER-ENTER 0..9 OR A..F: $'
 
.CODE

MAIN PROC
     MOV AX,@DATA
     MOV DS,AX
     TOP:
         MOV AH,9
         LEA DX,FPROMPT
         INT 21H
       
         MOV AH,1
         INT 21H
         MOV INPUTVAL,AL
   
         CMP AL,30H
         JNGE CHARACTER
         CMP AL,39H
         JNLE CHARACTER
       
         MOV AH,2
         MOV DL,0AH
         INT 21H
         MOV DL,0DH
         INT 21H
         MOV DL,INPUTVAL
         INT 21H
       
         MOV AH,9
         LEA DX,MSG
         INT 21H
       
         MOV AH,1
         INT 21H
     
         CMP AL,'Y'
         JE TOP
     
         CMP AL,'y'
         JE TOP
     
         JMP END_
       
     LOOP TOP  
   
     CHARACTER:
        MOV BL,INPUTVAL
     
        CMP BL,'A'
        JNGE ILLIGAL
        CMP BL,'F'
        JNLE ILLIGAL
     
        SUB BL,11H
        MOV AH,9
        LEA DX,ONE
        INT 21H
     
        MOV AH,2
        MOV DL,BL
        INT 21H
   
        MOV AH,9
        LEA DX,MSG
        INT 21H
     
        MOV AH,1
        INT 21H
     
        CMP AL,'Y'
        JE TOP
     
        CMP AL,'y'
        JE TOP
     
        JMP END_
     
    ILLIGAL:
        MOV AH,9
        LEA DX,IL
        INT 21H
     
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
     
        JMP TOP
     
    END_:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

Display The Extended ASCII Characters (ASCII Codes 80h To FF h) 10 Characters Per Line Assembly Language Solution.

/*
   Write a program to display the extended ASCII characters (ASCII codes 80h to FF h). Display 10 characters per line , separated by blanks. Stop after the extended characters have been displayed.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA

     FIRST DB 80H
     COUNTER DB 1
     NUMBER  DB 10
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    TOP:
        MOV BL,NUMBER
        CMP COUNTER,BL
        JE NEWLINE
     
        MOV AH,2
        MOV DL,FIRST
        INT 21H
        MOV DL,20H
        INT 21H
     
        CMP FIRST,0FFH
        JE END_
     
        MOV BL,FIRST
        INC BL
        MOV FIRST,BL
     
        MOV BL,COUNTER
        INC BL
        MOV COUNTER,BL
     
    LOOP TOP
 
    NEWLINE:
     
        MOV AL,NUMBER
        ADD AL,10
        MOV NUMBER,AL
     
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
     
        JMP TOP
         
    END_:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

Saturday, 20 June 2015

Read Two Capital Letters And Display Them On The Next Line In Alphabetical Order Assembly Language Solution.

/* Write a program to display a ''?",read two capital letters and display
   them on the next line in alphabetical order.

 */

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
 

.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,1      ;  INPUT FINCTION
                  ;
    INT 21H       ;  INPUT FIRST CHARACTER
    MOV BL,AL     ;
                  ;
    INT 21H       ;  INPUT SECOND CHARACTER
    MOV CL,AL
 
    MOV AH,2      ;
    MOV DL,0AH    ;
    INT 21H       ;  PRINTING NEW LINE
    MOV DL,0DH    ;
    INT 21H       ;
                  ;
    CMP BL,CL     ;
    JLE FIRST     ;  COMPARE TWO CHARACTER IF FIRST INPUT IS
                  ;      SMALLER THAN SECOND INPUT THAN GOTO FIRST:
                  ;
    MOV AH,2      ;
    MOV DL,CL     ;  PRINT SECOND CHARACTER
    INT 21H       ;
                  ;
    JMP END_      ;  UNCONDITIONAL JUMP
                  ;
    FIRST:        ;
                  ;
        MOV AH,2  ;
        MOV DL,BL ; PRINT SECOND CHARACTER
        INT 21H   ;
                  ;
                  ;
    END_:
 
    MOV AH,4CH    ;
    INT 21H       ;
       
    MAIN ENDP
END MAIN

Read Character And Display It Until A Blank Character Is Read In Assembly Language Solution.

/*
    Read Character And Display It Until A Blank Character Is Read Assembly Language
    Solution.
*/

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA

.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    REPEAT:
 
        MOV AH,1         ;
        INT 21H          ;    INTPUT A CHARACTER
                         ;
        CMP AL,20H       ;
        JE END_          ;    COMPARE IF INPUT ISEQUALTO SPACE THAN PROGRAM WILL BE TERMINATE
                         ;
        MOV AH,2         ;
        MOV DL,AL        ;    DOSPALY THE NUMBER
        INT 21H
                         ;
        JMP REPEAT       ;    JUMP TO THE REPEAT
 
    END_:                ;    PROGRAM END HERE
 
    MOV AH,4CH
    INT 21H
   
    MAIN ENDP
END MAIN

Wednesday, 17 June 2015

Program to display inverted Floyd's Triangle In Assembly Language (Solution).

// Program to display inverted Floyd's Triangle In Assembly Language (Solution).
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    COUNTER DB 0
    NEW DB 9
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV CX,45
 
 
    TOP:
        CMP CX,0
        JE END_
     
        MOV AL,NEW
        CMP COUNTER,AL
        JE NEWLINE
        MOV AH,2
        MOV DL,'*'
        INT 21H
        MOV BL,COUNTER
        INC BL
        MOV COUNTER,BL
 
    LOOP TOP
 
    NEWLINE:
     
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
     
        MOV BL,NEW
        ADD BL,-1
        MOV NEW,BL
        MOV COUNTER,0
        JMP TOP
         
    END_:
 
    MAIN ENDP
END MAIN

Program to display Floyd's Triangle In Assembly Language (Solution).

// Program to display Floyd's Triangle In Assembly Language
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    COUNTER DB 0
    NEW DB 1
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV CX,45
 
 
    TOP:
        CMP CX,0
        JE END_
     
        MOV AL,NEW
        CMP COUNTER,AL
        JE NEWLINE
        MOV AH,2
        MOV DL,'*'
        INT 21H
        MOV BL,COUNTER
        INC BL
        MOV COUNTER,BL
 
    LOOP TOP
 
    NEWLINE:
     
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
     
        MOV BL,NEW
        ADD BL,1
        MOV NEW,BL
        MOV COUNTER,0
        JMP TOP
         
    END_:
 
    MAIN ENDP
END MAIN

Printing Capital Letter And Display it In Assembly Language. (Solution)

// Printing Capital Letter And Display it In Assembly Language. Solution.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    STR DB 'IT IS NOT A CAPITAL LETTER'
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,1  ;
    INT 21H   ;INPUT THE CHARACTER
    MOV BL,AL ;
 
    CMP AL,'A' ; COMPARE AL GEATHER THAN 'A' IF NOT GOTO END_
    JNGE END_  ;
    CMP AL,'Z' ; COMPARE AL LESS THAN 'Z' IF NOT GOTO END_
    JNLE END_  ;
               ;
    MOV AH,2   ;
    MOV DL,BL  ; PRINTING THE CAPITAL LETTER
    INT 21H    ;
 
    END_:
       
    MAIN ENDP
END MAIN

Display The One That Comes First In The Character Sequence In Assembly Language Solution.

// Display The One That Comes First In The Character Sequence In Assembly Language Solution.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA

.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,1
    INT 21H
    MOV BL,AL
 
    INT 21H
    MOV CL,AL
 
    CMP BL,CL
    JNLE DISPLAY
 
    MOV AH,2
    MOV DL,BL
    INT 21H
    JMP END_
     
    DISPLAY:
        MOV AH,2
        MOV DL,CL
        INT 21H
    END_:
       
    MAIN ENDP
END MAIN

Display The Biggest Number Between Two Number In Assembly Language Solution.

// Display The Biggest Number Between Two Number In Assembly Language Solution.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    VAL DB ?
    FIRST DB 20H,'FIRST NUMBER.$'
    SECOND DB 20H,'SECOND NUMBER.$'
.CODE

MAIN PROC
 
    MOV AX,@DATA ; DATA SET
    MOV DS,AX    ;
 
    MOV AH,1     ;
    INT 21H      ;  INTPUT FIRST NUMBER AND SAVE IT TO VAL
    MOV VAL,AL   ;
 
    INT 21H      ;  INPUT SECOND NUMBER
    MOV CL,AL    ;
 
    CMP CL,VAL   ; COMPARE 2 NUMBER IF
    JLE PRINT    ;
 
    MOV AH,2
 
    MOV DL,0AH   ;
    INT 21H      ;
    MOV DL,0DH   ;   PRINTING NEW LINE
    INT 21H      ;
 
    MOV DL,CL    ;
    INT 21H      ;PRINTING SECOND VALUE
 
    MOV AH,9     ;
    LEA DX,SECOND; PRINTING SECOND MSG
    INT 21H      ;
     
    JMP END_     ;UNCONDITIONAL JUMP
 
    PRINT:
        MOV CL,VAL
        MOV AH,2
     
        MOV DL,0AH  ;
        INT 21H     ;   PRINTING NEW LINE
        MOV DL,0DH  ;
        INT 21H     ;
 
        MOV DL,CL   ;
        INT 21H     ; PRINTING FIRST VALUE
     
        MOV AH,9     ;
        LEA DX,FIRST ;   PRINTING FIRST MSG
        INT 21H      ;
     
    END_:  
    MOV AH,4CH
    INT 21H
 
    MAIN ENDP
END MAIN

Display The Entire IBM Character Set. 10 Character In A Line in Assembly language Solution.

// Display The Entire IBM Character Set. 10 Character In A Line in Assembly language Solution.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

Solution:

.MODEL SMALL
.STACK 100H
.DATA
   COUNTER DB 10
.CODE

MAIN PROC
 
    MOV AX,@DATA        ;
    MOV DS,AX           ;data set
 
    MOV AH,2            ;display character function
    MOV CX,256          ;256 character to display
    MOV BL,0            ;BL has ASCII code of null character( 0 = null)
 
    PRINTLOOP:
        CMP CX,0        ;if CX = 0 than jump to the END_
        JE END_
        CMP BL,COUNTER
        JE PRINTNEWLINE
        MOV AH,2
        MOV DL,BL
        INT 21H         ;instruction to display
        INC BL          ;increment BL ASCII code by 1
        DEC CX          ;decrement CX counter by 1
        JNZ PRINTLOOP   ;JNZ = Jump if not zero.if CX not zero than it's jump to the PRINTLOOP
     
    PRINTNEWLINE:
     
     
        MOV AH,2        ;
        MOV DL,0AH      ;
        INT 21H         ;  Printing NEWLINE
        MOV DL,0DH      ;
        INT 21H         ;
     
        ADD COUNTER,10  ;COUNTER incremented by 10
     
        JMP PRINTLOOP   ;without condition jump to the PRINTLOOP
 
    END_:
         
        MOV AH,4CH
        INT 21H
     
    MAIN ENDP
END MAIN