How to convert a character to hexadecimal in Assembly

Asked

Viewed 295 times

0

My code should receive a character and print the code in ASCII, but it doesn’t work and I can’t find where the error is. Edit: is giving 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

1 answer

1

Where did this "12" ???

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 consists of the 2 AH and AL sub-registers.

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

      .code                              
      Main   proc
main: mov    ax, @data
  • still giving error. Error: Code cannot be assembled. One or more support file for this Assembly code is Missing.

  • by the content of the message, it may be that the file "Equal-01.inc is missing"

  • now you’re saying: (41) Unexpected end of file encountered

Browser other questions tagged

You are not signed in. Login or sign up in order to post.