title: Using EMU8086, is there a direct way to print a variable's hex value?
body: <p>I'm using EMU8086 on a Windows 7 HP x64, Intel i3-2330m PC.</p>
  
  <p>I have spent about two weeks researching and tinkering with this Assembly language program in an effort to print the hex value of an integer entered by the user. I have found nothing about directly printing a value from a memory location. I can, if necessary, write the code to do the string conversion to hex. However, I am attempting to avoid the extra lines of code to do this. (I think that is called optimizing.)</p>
  
  <p>My research has lead me to a <a href="https://stackoverflow.com/questions/10777551/convert-decimal-to-hex-in-assembly">comment on this site by Corbin</a> which says: </p>
  
  <blockquote>
    <p>Very unpleasantly. You'll have to determine the value of the decimal
    string ("100"), then make a new string that is the same value in hex
    ("0x64"). It's the same algorithm that you use to do the conversion in
    your head; it's just a bit more complicated since you have to deal
    with ASCII encoding on top of things.</p>
  </blockquote>
  
  <p>None of this has directed me to a manner in which I desire to perform the task. </p>
  
  <p>I have written and tested the code incrementally, receiving the desired results. By watching the variable and viewing the CX register, I can confirm that their values are the values I want to print.</p>
  
  <p>I am including my code here. It is probably ugly and is definitely over-commented. The commenting is for my benefit to help me learn/remember what I have done as I progress. </p>
  
  <pre><code> ; program name: convert_decimal_to_hex
   ; by W K
   ; August, 2015
   ; This program accepts an integer between 1 and 10000 and
   ; prints the hexadecimal value to the console
   ;
   ;
   #MAKE_COM# ;instruct compiler to make COM file
   include emu8086.inc    ;use include file for macros
   ORG 100h   ;directive for COM program, set offset to 100h
   ;
   MOV DX, offset msg1    ;moves value of msg1 to the data register
   ;                       
   MOV AH, 9  ;moves the value 9 to the high accumulator register
              ;to be used with the interrupt
   INT 21h    ;invokes interrupt to print string to DOS window
   ;
   MOV DX,13  ;these lines
    MOV AH,2  ;create a
    INT 21h   ;newline
    MOV DX,10 ;and
    MOV AH,2  ;move the cursor
    INT 21h   ;to the newline
   ;
   CALL SCAN_NUM  ;calls macro to scan numeric keyboard input
                  ;error catching is included in macro
                  ;number is stored in CX 
    MOV DX,13 ;these lines
    MOV AH,2  ;create a
    INT 21h   ;newline
    MOV DX,10 ;and
    MOV AH,2  ;move the cursor
    INT 21h   ;to the newline
   ;  
   MOV DX, offset msg2    ;moves value of msg2 to the data register
   MOV AX, CX ;copies scanned number to AX to be printed
              ;as part of message
   ;MOV AH, 9  ;moves the value 9 to the high accumulator register
               ;to be used with the interrupt
   ;INT 21h    ;invokes interrupt to print string to DOS window 
  
  
   CALL PRINT_NUM_UNS  ;prints hexadecimal value at end of msg2
   MOV CONVERTEDNUMBER, CX
   ;                       
   MOV AH, 9  ;moves the value 9 to the high accumulator register
              ;to be used with the interrupt
   INT 21h    ;invokes interrupt to print string to DOS window
   ;
   MOV AX, 0  ;wait for any key
   INT 16h    ;prevents window from closing immediately
   ;
   msg1 db "Type an integer between 1 and 10000, and press enter. $"    
      ;declare string variable 
   msg2 db " in hexadecimal is: $" 
   ;
   DEFINE_SCAN_NUM    ;defines macro from include file
                      ;gets multidigit signed number from keyboard
   DEFINE_PRINT_NUM_UNS   ;defines macro from include file
                          ;prints unsigned number in AX
   ;                                                   
   CONVERTEDNUMBER DW 0   ;declare variable
   ;
   RET    ;return to operating system
   END    ;directive to stop compiler
  </code></pre>
  
  <p>Is there a procedure to directly print the variable value or CX register value without writing the lines of code to convert the string value input by the user? Any references to articles, code examples, or other helpful advice will be greatly appreciated.</p>