title: Convert Char to ASCII Code (Decimal) in Assembly
body: <p>I'm very new to Assembly - less than one week of experience. I'm trying to receive in a character from a prompt, then display out the ASCII Code in decimal. I have been working on this for hours and decided to come here.</p>
  
  <p>When I put in 'a' into the prompt, my emulator shows that my char variable is storing 61 hexidecimal, which is correct. I just can't seem to get it to print to the screen (in hex or decimal).</p>
  
  <p>EDIT: CHANGED CODE TO LOOP THROUGH AND DIVIDE BY TEN. I HAVE THE CORRECT CHARS PRINTING OUT, BUT IN REVERSE. THE NUMBER 97 PRINTS OUT 79</p>
  
  <p>So far, this is what i've got: </p>
  
  <pre><code>; **************** MACROS *********************
  
  ; START PROGRAM
  START MACRO
  
      MOV AX, DATA ; Data Segment to AX Register
      MOV DS, AX   ; HAVE DS Point to Data Segment  
  ENDM          
  
  ; END PROGRAM
  END MACRO  
  
      MOV AH, 4CH  ; END Program
      INT 21H      ; Call DOS Service
  ENDM
  
  ; PRINT STRING TO OUTPUT        
  PSTRING MACRO STR
  
      MOV AH,09H
      LEA DX,STR
      INT 21H
  ENDM
  
  ; Creates a New Line
  NEWLINE MACRO 
      MOV DX, 0AH   ; Input of string to DX
      MOV AH, 02H   ; Write Char to standard output
      INT 21H        
  
      MOV DL, 0DH   ; 
      MOV AH, 02H   ; Carriage Return
      INT 21H       ;
  ENDM
  
  ; Get CHAR Input 
  GETINPUT MACRO INPUT
  
      MOV AH, 01H     ; Receive input          
      INT 21H         ; Call DOS Service
  
      MOV INPUT, AL   ; Store into Input Variable  
  ENDM 
  
  ; ********** END MACROS *******************
  
  
  .MODEL   
  .DATA   
  
     MSG1 db 'Choose A Char to Convert To ASCII: $' 
     CHAR db ?   ; Store Input Char
     REM  db ?   ; Remainder 8-bit storate
     QUOT db ?   ; Quotient  8-bit storage
  
  .CODE 
  
    MAIN PROC 
  
      START 
  
      PSTRING MSG1 
  
      GETINPUT CHAR
  
      NEWLINE       
  
      MOV AX, 0     ; Clear AX Register
      MOV AL, CHAR  ; Move input to AL 
  
      MOV DX, 0     ; Clear DX Register
      MOV DL, 10    ; Add 10 to DL Register
      DIV DL        ; Divide By Number of Students For Average   
  
      ; ********************** ;
      ; QUOTIENT  STORED IN AL ;
      ; REMAINDER STORED IN AH ;
      ; ********************** ;                                               
  
  
      myLoop:  
  
          MOV REM, AH   ; Move Remainder into REM  Variable
          MOV QUOT, AL  ; Move Quotient  into QUOT Variable
  
          MOV DL, REM  ; Move Data we want printed into DL
          ADD DL, '0'   ; Make into Ascii Char
  
          MOV AH,02H    ; Output Char Service
          INT 21H       ; Call DOS Service
  
  
          MOV AL, QUOT  ; Place Quotient Into AL
          MOV AH, 0     ; AH was altered, Zero it out
  
          MOV DL, 10    ; Set Divisor to 10
          DIV DL        ; Divide AX by 10
  
          CMP AH, 0     ; If No Quotient Remains we can exit 
  
      JNZ myLoop        ; Jump if NOT zero 
  
  
      MOV AH, 4CH       ; End Program
      INT 21H     
  
      END               
  
    MAIN ENDP   
  END MAIN
  </code></pre>