Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » GeneralRSS Feeds

Program that prompts the user to enter a character, and prints the ASCII code of the character in hex on the next line. Repeat this process ......

Posted By: Easy Tutor     Category: Assembly Language     Views: 5982

An AL program that prompts the user to enter a character, and prints the ASCII code of the character in hex on the next line. Repeat this process untill the user types a carriage return.

Code for Program that prompts the user to enter a character, and prints the ASCII code of the character in hex on the next line. Repeat this process ...... in Assembly Language

 .MODEL SMALL
 .STACK 100H

 .DATA
   PROMPT_1  DB  0DH,0AH,'Enter the character : $'
   PROMPT_2  DB  0DH,0AH,'The ASCII code of the given number in HEX form is : $'

 .CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS  
     MOV DS, AX

     @START:                      ; jump label 
       LEA DX, PROMPT_1           ; load and display the string PROMPT_1
       MOV AH, 9
       INT 21H

       MOV AH, 1                  ; read a character
       INT 21H

       MOV BL, AL                 ; move AL to BL

       CMP BL, 0DH                ; compare BL with CR
       JE @END                    ; jump to label @END if BL=CR

       LEA DX, PROMPT_2           ; load and display the string PROMPT_2
       MOV AH, 9
       INT 21H

       XOR DX, DX                 ; clear DX
       MOV CX, 4                  ; move 4 to CX

       @LOOP_1:                   ; loop label
         SHL BL, 1                ; shift BL towards left by 1 position
         RCL DL, 1                ; rotate DL towards left by 1 position
                                  ; through carry
       LOOP @LOOP_1               ; jump to label @LOOP_1 if CX!=0

       MOV CX, 4                  ; move 4 to CX

       @LOOP_2:                   ; loop label
         SHL BL, 1                ; shift BL towards left by 1 position
         RCL DH, 1                ; rotate DH towards left by 1 position
                                  ; through carry
       LOOP @LOOP_2               ; jump to label @LOOP_2 if CX!=0

       MOV BX, DX                 ; move DX to BX
       MOV CX, 2                  ; initialize loop counter

       @LOOP_3:                   ; loop label
         CMP CX, 1                ; compare CX wiht 1
         JE @SECOND_DIGIT         ; jump to label @SECOND_DIGIT if CX=1
         MOV DL, BL               ; move BL to DL
         JMP @NEXT                ; jump to label @NEXT

         @SECOND_DIGIT:           ; jump label
           MOV DL, BH             ; move BH to DL

         @NEXT:                   ; jump label

         MOV AH, 2                ; set output function

         CMP DL, 9                ; compare DL with 9
         JBE @NUMERIC_DIGIT       ; jump to label @NUMERIC_DIGIT if DL<=9
         SUB DL, 9                ; convert it to number i.e. 1,2,3,4,5,6
         OR DL, 40H               ; convert number to letter i.e. A,B...F
         JMP @DISPLAY             ; jump to label @DISPLAY

         @NUMERIC_DIGIT:          ; jump label
           OR DL, 30H             ; convert decimal to ascii code

         @DISPLAY:                ; jump label
           INT 21H                ; print the character
       LOOP @LOOP_3               ; jump to label @LOOP_3 if CX!=0

       JMP @START                 ; jump to label @START

     @END:                        ; jump label

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP
 END MAIN
  
Share: 



Easy Tutor
Easy Tutor author of Program that prompts the user to enter a character, and prints the ASCII code of the character in hex on the next line. Repeat this process ...... is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!