Hello, I am writing an assembler program that encodes (converts) a binary number into a two-digit hexadecimal number. Wrote this code:

.model small .data HEXDIGIT DB "0123456789ABCDEF" VAR1 DB 10011001b .stack 256 .code main: mov ax, @data mov ds, ax MOV AL , VAR1 MOV BX , OFFSET HEXDIGIT XLAT MOV DL , AL MOV AH , 02H INT 21H mov ax,4c00h int 21h end main 

But I suffer a fiasco:

enter image description here

  • 3
    you take the whole number as an offset, and it certainly can be more than 16. You must first take the high 4 bits of the number ( shr al,4 ) - get the xlat first character, then return the original number in al and leave the low 4 bits from it ( and al,0Fh ) and get the second character - Mike
  • @Mike, it is a bit tricky and earned. Very grateful for the help. - nait123321

1 answer 1

Thanks to Mike for the answer. Here is a ready-made solution, can someone come in handy ...

 .model small .data HEXDIGIT DB "0123456789ABCDEF" VAR1 DB 0110111b .stack 256 .code main: mov ax, @data mov ds, ax MOV AL , VAR1 shr al,4 MOV BX , OFFSET HEXDIGIT XLAT MOV DL , AL MOV AH , 02H INT 21H XOR AL,AL MOV AL , VAR1 and al,0Fh XLAT MOV Dl, AL MOV AH , 02H INT 21H mov ax,4c00h int 21h end main