This is an attempt to increase the letter mark, which is incorrect. Also, your location in STRING allocates only one byte (char) instead of a larger number to accommodate the size of the line that you intend.
STRING: db 0 inc STRING ;THIS WON'T WORK mov [STRING], ah ;append the new character to a string of bytes inc STRING ;THIS WON'T WORK mov [STRING], al ;append the new character to the string of bytes
Neutral Comment: The character table used for xlat
should not be zero terminated.
I would also recommend saving and restoring some registers as a good asm programming practice. Thus, the calling function does not need to worry about the registers changing βbehindβ. Ultimately, you probably want something like this:
TABLE: db "0123456789ABCDEF", 0 hex_to_char: push ax push bx lea bx, [TABLE] mov ax, dx mov ah, al ;make al and ah equal so we can isolate each half of the byte shr ah, 4 ;ah now has the high nibble and al, 0x0F ;al now has the low nibble xlat ;lookup al contents in our table xchg ah, al ;flip around the bytes so now we can get the higher nibble xlat ;look up what we just flipped lea bx, [STRING] xchg ah, al mov [bx], ax ;append the new character to the string of bytes pop bx pop ax ret section .bss STRING: resb 50 ; reserve 50 bytes for the string
If you want the function to return the character that it just saved, you can skip push / pop ax
.
source share