How to convert a hexadecimal character to Assembly

0

My code should get a character and print the code in ASCII, but it does not work and I can not figure out where the error is. Edit: is giving the error (41) Unexpected end of file encountered

model     small   
          stack     100h

$AsciiToHex  macro   asciiChar, hexStr2
          local  tableHex

          .data
tableHex  db   '0123456789ABCDEF'      

          .code                              
          Main      proc
          mov  ax, @data
          mov  ds, ax
          mov ah,01h
          int 21h
          mov  asciiChar, al
          $AsciiToHex  asciiChar, hexStr2
          mov  ax, word ptr [hexStr2] 
          mov   bx, offset  tableHex  
          mov   al, [asciiChar]        
          mov   ah, al                 
          and   al, 00001111b          
          xlat                          
          mov   [hexStr2 + 1], al     
          shr   ax, 8               
          xlat                         
          mov   hexStr2, al                    
          endp Main
          end  main
    
asked by anonymous 27.10.2018 / 23:11

1 answer

1

Where did this "12" come from?

shr ax, 12

The right is 8

shr ax, 8

Because 8 is the bit size of the AH and AL registers, and remembering, the AX register is composed of the 2 sub-registers AH and AL.

google: hello world masm
first link : apparently you need to have a "main:" label to match the "end main" directive, probably like this:

      .code                              
      Main   proc
main: mov    ax, @data
    
27.10.2018 / 23:20