Wednesday, 29 July 2015

Reverse Input String in assembly Language Solution.


Reverse Input String in assembly Language Solution.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 8 , PROGRAMMING EXERCISE ,
 ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 8.

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    OUTPUT_MSG DB 0AH,0DH,'OUTPUT IS: $'
.CODE

MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,2
    MOV DL,3FH
    INT 21H
 
    MOV CL,0
    TOP:
        MOV AH,1
        INT 21H
     
        CMP AL,0DH
        JE END_INPUT
     
        PUSH AX
        INC CL
        JMP TOP
    END_INPUT:
 
    MOV AH,9
    LEA DX,OUTPUT_MSG
    INT 21H
 
    OUTPUT:
        CMP CL,0
        JE END_OUTPUT
     
        MOV AH,2
        POP BX
        MOV DX,BX
        INT 21H
        DEC CL
        JMP OUTPUT
    END_OUTPUT:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

Write a program that prompts the user to enter a character, and on subsequent lines prints its ASCII code in binary, and the number of 1 bits In Its ASCII code In Assembly Language Solution Using Function / Procedure.

Write a program that prompts the user to enter a character, and
on subsequent lines prints its ASCII code in binary, and the number of 1 bits In Its ASCII code.
Sample execution:
TYPE A CHARACTER: A
THE ASCII CODE OF A IN BINARY IS 010'00001
THE NUMBER OF l BITS IS 2

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

TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 7 , PROGRAMMING EXERCISE ,
 FUNCTION/PROCEDURE ,ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 7.

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    INPUT_MSG DB 'TYPE A CHARACTER: $'
    OUTPUT_MSG_1 DB 0AH,0DH,'THE ASCII CODE OF '
    OUTPUT DB ?
    OUTPUT_MSG_2 DB ' IN BINARRY IS $'
    COUNT_MSG_1 DB 0AH,0DH,'THE NUMBER OF 1 BIT IS '
    COUNT DB ?
    COUT_MSH_2 DB '$'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX

    CALL INPUT_FUNC
    CALL CALCULATION_FUNC
    CALL OUTPUT_FUNC
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP

INPUT_FUNC PROC
 
    MOV AH,9
    LEA DX,INPUT_MSG
    INT 21H
 
    MOV AH,1
    INT 21H
    MOV BL,AL
    MOV OUTPUT,AL
    RET
 
    INPUT_FUNC ENDP

CALCULATION_FUNC PROC
 
    MOV CL,0
    MOV CH,0
    MOV AH,9
    LEA DX,OUTPUT_MSG_1
    INT 21H
 
    TOP:
        CMP CL,8
        JE END_
        INC CL
        SHL BL,1
        JC COUNTONE
        MOV AH,2
        MOV DL,30H
        INT 21H
     
        JMP TOP
    COUNTONE:
        MOV AH,2
        MOV DL,31H
        INT 21H
     
        INC CH
        JMP TOP
    END_:
    ADD CH,30H
    MOV COUNT,CH
    RET
 
    CALCULATION_FUNC ENDP

OUTPUT_FUNC PROC
 
    MOV AH,9
    LEA DX,COUNT_MSG_1
    INT 21H
    RET
 
    OUTPUT_FUNC ENDP
 
END MAIN

Write a program that prompts the user to enter a character, and on subsequent lines prints its ASCII code in binary, and the number of 1 bits In Its ASCII code In Assembly Language Solution.

Write a program that prompts the user to enter a character, and
on subsequent lines prints its ASCII code in binary, and the number of 1 bits In Its ASCII code.
Sample execution:
TYPE A CHARACTER: A
THE ASCII CODE OF A IN BINARY IS 010'00001
THE NUMBER OF l BITS IS 2

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

TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 7 , PROGRAMMING EXERCISE ,
 ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 7 .

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    INPUT_MSG DB 'TYPE A CHARACTER: $'
    OUTPUT_MSG_1 DB 0AH,0DH,'THE ASCII CODE OF '
    OUTPUT DB ?
    OUTPUT_MSG_2 DB ' IN BINARRY IS $'
    COUNT_MSG_1 DB 0AH,0DH,'THE NUMBER OF 1 BIT IS '
    COUNT DB ?
    COUT_MSH_2 DB '$'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    MOV AH,9
    LEA DX,INPUT_MSG
    INT 21H
 
    MOV AH,1
    INT 21H
    MOV BL,AL
    MOV OUTPUT,AL
    MOV CL,0
    MOV CH,0
    MOV AH,9
    LEA DX,OUTPUT_MSG_1
    INT 21H
 
    TOP:
        CMP CL,8
        JE END_
        INC CL
        SHL BL,1
        JC COUNTONE
        MOV AH,2
        MOV DL,30H
        INT 21H
     
        JMP TOP
    COUNTONE:
        MOV AH,2
        MOV DL,31H
        INT 21H
     
        INC CH
        JMP TOP
    END_:
    ADD CH,30H
    MOV COUNT,CH
 
    MOV AH,9
    LEA DX,COUNT_MSG_1
    INT 21H
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

Do programming exercise 10, except that if the user fails to enter a hex-digit character In three tries, display a message and terminate the program In Assembly Language Solution.

Do programming exercise 10, except that if the user fails to enter
a hex-digit character In three tries, display a message and terminate the program.

/*
    *
    * 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 .


Solution:

.MODEL SMALL
.STACK 100H
.DATA
    PROMPT_TRY_MSG DB 0AH,0DH,'TRY AGAIN.$'
    PRMPT_MSG_1 DB 'ENTER A HEX DIGIT "0"..."9"  OR "A".."F": $'
    OUTPUT_PRMPT DB 0AH,0DH,'OUTPUT: $'
    ASK_PROMPT DB 0AH,0DH,'DO YOU WANT ANOTHER INPUT: $'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
    MOV CL,0
    TOP:
        CMP CL,3
        JE END_
     
        MOV AH,9
        LEA DX,PRMPT_MSG_1
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BL,AL

        CMP BL,30H
        JL  TRY_MSG
     
        CMP BL,46H
        JG  TRY_MSG
     
        CMP BL,39H
        JLE DIGIT
     
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        SUB BL,11H
     
        MOV AH,2
        MOV DL,31H
        INT 21H
        MOV DL,BL
        INT 21H
             
    AGAIN:
        MOV AH,9
        LEA DX,ASK_PROMPT
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BH,AL
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
        MOV CL,0
         
        CMP BH,'Y'
        JE TOP
        CMP BH,'y'
        JE TOP
        JMP END_
    DIGIT:
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        MOV AH,2
        MOV DL,BL
        INT 21H
        MOV CL,0
        JMP AGAIN
    TRY_MSG:
        MOV AH,9
        LEA DX,PROMPT_TRY_MSG
        INT 21H
        INC CL
        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

Write a program that will prompt the user to enter a hex digit character ("0"·... "9" or "A" ... "F"), display it on the next line in decimal, and ask the user i.i 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 In Assembly Language Solution.

Write a program that will prompt the user to enter a hex digit
character ("0"·... "9" or "A" ... "F"), display it on the next line
in decimal, and ask the user i.i 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)
    *
*/

TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 6 , PROGRAMMING EXERCISE ,
 ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 6 .

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    PROMPT_TRY_MSG DB 'TRY AGAIN.$'
    PRMPT_MSG_1 DB 'ENTER A HEX DIGIT "0"..."9"  OR "A".."F": $'
    OUTPUT_PRMPT DB 0AH,0DH,'OUTPUT: $'
    ASK_PROMPT DB 0AH,0DH,'DO YOU WANT ANOTHER INPUT: $'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    TOP:
        MOV AH,9
        LEA DX,PRMPT_MSG_1
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BL,AL
     
        CMP BL,30H
        JL  TRY_MSG
     
        CMP BL,46H
        JG  TRY_MSG
     
        CMP BL,39H
        JLE DIGIT
     
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        SUB BL,11H
     
        MOV AH,2
        MOV DL,31H
        INT 21H
        MOV DL,BL
        INT 21H      
    AGAIN:
        MOV AH,9
        LEA DX,ASK_PROMPT
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BH,AL
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
         
        CMP BH,'Y'
        JE TOP
        CMP BH,'y'
        JE TOP
        JMP END_
    DIGIT:
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        MOV AH,2
        MOV DL,BL
        INT 21H
     
        JMP AGAIN
    TRY_MSG:
        MOV AH,9
        LEA DX,PROMPT_TRY_MSG
        INT 21H
        JMP TOP      
    END_:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

Write a program to display the extended ASCII characters (ASCII codes 80h to FFh). Display 10 characters per line, separated by blanks. Stop after the extended characters have been displayed once In Assembly Language Solution Using Function/Procedure.

Write a program to display the extended ASCII characters (ASCII
codes 80h to FFh). Display 10 characters per line, separated by
blanks. Stop after the extended characters have been displayed
once.
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 6 , PROGRAMMING EXERCISE ,
 FUNCTION/PROCEDURE ,ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 6 .

Solution:

.MODEL SMALL
.STACK 100H
.CODE

MAIN PROC

    CALL INITIALIZE_FUNC
    TOP:
        CMP CL,10
        JE NEWLINE
        CALL DISPLAY_FUNC
       
        JMP TOP
    NEWLINE:
        CALL NEWLINE_FUNC
        JMP TOP  

    MAIN ENDP        

INITIALIZE_FUNC PROC
 
    MOV BL,80H
    MOV CL,0
    RET
 
    INITIALIZE_FUNC ENDP

DISPLAY_FUNC PROC
 
    INC CL
     
    MOV AH,2
    MOV DL,BL
    INT 21H
    INC BL
     
    CMP BL,0FFH
    JE END_
 
    RET
    END_:
        CALL END_FUNC
        RET
     
    DISPLAY_FUNC ENDP

NEWLINE_FUNC PROC  
 
    MOV AH,2
    MOV DL,0AH
    INT 21H
    MOV DL,0DH
    INT 21H
    MOV CL,0
    RET
     
    NEWLINE_FUNC ENDP

END_FUNC PROC  
 
    MOV AH,4CH
    INT 21H
    RET
 
    END_FUNC ENDP

END MAIN

Write a program to display the extended ASCII characters (ASCII codes 80h to FFh). Display 10 characters per line, separated by blanks. Stop after the extended characters have been displayed once In Assembly Language Solution.

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

/*
    *
    * 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 .

Solution:

.MODEL SMALL
.STACK 100H

.CODE

MAIN PROC

    MOV BL,80H
    MOV CL,0
    TOP:
        CMP CL,10
        JE NEWLINE
     
        INC CL
     
        MOV AH,2
        MOV DL,BL
        INT 21H
        INC BL
     
        CMP BL,0FFH
        JE END_
     
        JMP TOP
    NEWLINE:
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
        MOV CL,0
        JMP TOP
    END_:
 
    MOV AH,4CH
    INT 21H
         
    MAIN ENDP
END MAIN