Wednesday, 29 July 2015

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

No comments:

Post a Comment