; THIS IS MY 4TH-4 PROGRAM will convert a charcter to binary ascii; = comment .model small ; --> small memory allocation .386 ; --> for use of 32 bits .stack 100h ; 100H = 256(10) .data ; to declare variables MSG1 DB 13, 10, "Enter any key --> ", "$" MSG2 DB " The ASCII code is --> ", "$" MSG3 DB 13, 10, " One more Character to convert to ASCII? If yes type Y ", "$" MSG4 DB 13, 10, " The Number of 1's in the above binary is ", "$" MSG5 DB 13, 10, " The Number of 0's in the above binary is ", "$" XYZ DB ? ; This is a numeric variable for 8 bits with no initial assign value My_Counter DB ? ;This is a numeric variable for 8 bits with no initial assign value One_counter db ? .code ; the code for the program main proc mov ax,@data ; set up data segment DS mov ds,ax ; DS = Data segment L0: ; location in the program mov One_counter, 0 mov dx,offset msg1 Call DispTXT Call KeyIN ; call the keyin proc (function) the AL register has the key value mov dx,offset msg2 Call DispTXT MOV XYZ, AL ; SAVING THE KEY PRESSED into the XYZ variable MOV My_Counter, 9 ; V = 9 THE COUNTER L1: DEC My_Counter ; My_Counter = My_Counter-1 JZ SHORT FIN SHL XYZ, 1 ; Shift lefte the variable XYZ JC SHORT DISP1 DISP0: MOV DL, 30H ; this routine displays 0 on the screen call display JMP L1 ; unconditonal jump DISP1: inc one_counter MOV DL, 31H ; this routine displays 1 on the screen call display JMP L1 ; unconditonal jump FIN: mov dx,offset msg5 call DispTXT mov dl, 8 sub dl, one_counter add dl, 30h call display mov dx,offset msg4 call DispTXT mov dl, one_counter add dl, 30h call Display mov dx,offset msg3 call DispTXT Call KeyIn CMP AL, 59h ; ASCII for Capital Y JZ L0 CMP AL, 79h ; ASCII for Lower Case y JZ L0 mov ax, 4c00h ; ENDING THE PROGRAM int 21h ; library call DispTXT proc MOV AH, 9 ; Displays a string to the screen int 21h ret DispTXT endp KeyIn proc ; enter key MOV AH, 1 ; enter key by user INT 21H ; the ascii value of the key pressed is being deposited into AL RET KeyIN endp Display proc MOV AH, 6 INT 21H ret display endp main endp end main