News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

xlat, xlatb

Started by endrodyp, June 15, 2019, 10:25:44 PM

Previous topic - Next topic

endrodyp

Has anyone experienced This? When compiling with options .286 and otion expr16 the xlatb opcodes doesnt seem to work. I was trying to make an Word to hexadecimal translator using xlatb but had to find another way.

original:
;-------------------------------------------------------------------------------------------
; szam konvertalasa hex ascii kodokka , hextable    db "0123456789ABCDEF","$" a progi elejére
;
; AX= konvertalando szám
; di = puffer címe (7 bájt)
;-------------------------------------------------------------------------------------------
wtohex:
.data
wtohex_hextable   db "0123456789abcdef"

.code
push bx

lea bx, wtohex_hextable
push ax
and ax,0f000h
shr ax,12
xlat
mov byte ptr [di],al
pop ax
push ax
and ax, 00f00h
shr ax,8
xlat
mov byte ptr [di+1],al
pop ax
push ax
and ax, 000f0h
shr ax,4
xlat
mov byte ptr [di+2],al
pop ax
and ax, 0000fh
xlat
mov byte ptr [di+3],al
mov byte ptr [di+4],'h'
mov byte ptr [di+5],"%"
mov byte ptr [di+6],"%"

pop bx
ret
;-------------------------------------------------------------

modified:

;-------------------------------------------------------------------------------------------
; szam konvertalasa hex ascii kodokka , hextable    db "0123456789ABCDEF","$" a progi elejére
;
; AX= konvertalando szám
; di = puffer címe (7 bájt)
;-------------------------------------------------------------------------------------------
wtohex:

push bx

push ax
and ax,0f000h
shr ax,12
cmp al,10
jge letter1
add al, 48
jmp next
letter1:
add al, 65
next:
mov byte ptr [di],al
pop ax
push ax
and ax, 00f00h
shr ax,8
cmp al, 10
jge letter2
add al, 48
jmp next2
letter2:
add al, 65
next2:
mov byte ptr [di+1],al
pop ax
push ax
and ax, 000f0h
shr ax,4
cmp al, 10
jge letter3
add al, 48
jmp next3
letter3:
add al, 65
next3:
mov byte ptr [di+2],al
pop ax
push ax
and ax, 0000fh
cmp al, 10
jge letter4
add al, 48
jmp next4
letter4:
add al, 65
next4:
mov byte ptr [di+3],al
pop ax
mov byte ptr [di+4],'h'
mov byte ptr [di+5],"%"
mov byte ptr [di+6],"%"

pop bx
ret
;-------------------------------------------------------------

jj2007

What exactly doesn't work? These three instructions assemble just fine on my machine, using ML version 6.14 or UAsm:
  .186
  xlat table
  xlat [bx]
  xlatb

Which assembler are you using, which errors do you get?

endrodyp

It seems to compile fine without errors, however the result is an empty string Masm ver. 5.12.

jj2007

You should at least use Masm 6.14, which comes with the Masm32 SDK (installation instructions); UAsm is much better. Your code as 32-bit version works, although I am not sure whether the result 6364h%% pleases you:
include \masm32\include\masm32rt.inc  ; standard includes for a plain Masm32 project
.code
wtohex:

.data
wtohex_hextable   db "0123456789abcdef"
buffer db 1000 dup(?)

.code
push ebx
mov edi, offset buffer
lea ebx, wtohex_hextable
push eax

and eax,0f000h
shr eax,12
xlat
mov byte ptr [edi],al
pop eax
push eax
and eax, 00f00h
shr eax,8
xlat
mov byte ptr [edi+1],al
pop eax
push eax
and eax, 000f0h
shr eax,4
xlat
mov byte ptr [edi+2],al
pop eax
and eax, 0000fh
xlat
mov byte ptr [edi+3],al
mov byte ptr [edi+4],'h'
mov byte ptr [edi+5],"%"
mov byte ptr [edi+6],"%"

pop ebx
ret
start:
  mov eax, "abcd"
  call wtohex
  inkey offset buffer
  exit
end start


aw27

Try to post the whole program. Building for .286 is not the same as building for .386.

endrodyp

Yes the point is that I can only use it in 16 bit environment. I, too, tested it in 32 bit environment it Works fine, which I cannot say to 16 bit DOS.

sinsi

Have you initialised DS to point to the data segment? For a .com program DS=ES=CS=SS but an EXE you need to load DS.

endrodyp

it is a .com program. Compiled with ml /AT filename.asm and link16 /TINY filename.obj.
Anyway Thanks guys I simply use the second algorythm for my project. No big deal.

aw27

#8

;\masm32\bin\ml614 -c test.asm
;\masm32\bin\link16 test.obj, test.exe,0,0,nul.def
.286
.model small

.stack 100h

.data
wtohex_hextable   db "0123456789abcdef",0
myWord db "Word to Hex=$",0
buffer db 64 dup (0)
Sixteen db 16

.code

.startup
push di
push si
push bx
push es
mov ax, ds
mov es, ax

lea     dx, myWord
mov     ah,09
int     21h

mov si, offset myWord
mov di, offset buffer
mov bx, offset wtohex_hextable
mov cx, sizeof myWord
sub cx,3
next:
mov ah,0
lodsb
div Sixteen ;(result in AH:AL, not DX:AX)
xlatb
stosb
mov al, ah
xlatb
stosb
loop next

mov al, 'h'
stosb
mov al, '$'
stosb

lea     dx, buffer
mov     ah,09
int     21h

pop es
pop bx
pop si
pop di
.EXIT
end



Word to Hex=576f726420746f20486578h


PS: I don't think there is any MASM version 5.12, it exists a LINK with that version number.  :skrewy:

jj2007

Quote from: endrodyp on June 16, 2019, 04:54:42 PM
it is a .com program. Compiled with ml /AT filename.asm and link16 /TINY filename.obj.
Anyway Thanks guys I simply use the second algorythm for my project. No big deal.

You can use the first algo, it's fine. This works like a charm:
.186
.model tiny
.code
org 100h

start:
  mov ax, 0AB12h ; test string
  call wtohex
  ret

wtohex_hextable   db "0123456789abcdef"

wtohex:
sub sp, 100 ; create a buffer
mov di, sp
push bx
lea bx, wtohex_hextable
push ax
and ax,0f000h
shr ax,12
xlat
mov byte ptr [di],al
pop ax
push ax
and ax, 00f00h
shr ax,8
xlat
mov byte ptr [di+1],al
pop ax
push ax
and ax, 000f0h
shr ax,4
xlat
mov byte ptr [di+2],al
pop ax
and ax, 0000fh
xlat
mov byte ptr [di+3],al
mov byte ptr [di+4],'h'
mov byte ptr [di+5],"$"
mov byte ptr [di+6],"%"
pop bx
mov ah, 09h ; write string to STDOUT
mov dx, di
int 21h
add sp, 100
ret

end start

endrodyp

This last one look sympathetic, I Will try This one. Thanks a lot.

aw27

This version will build with MASM 5.1.2 (requires a 16-bit environment) and runs in DOS and OS/2
This is not at the level of the original question, obviously.


.model small
.stack 100h
.286

.data
wtohex_hextable   db "0123456789abcdef",0
myWord db "Word to Hex=$",0
buffer db 64 dup (0)
Sixteen db 16

.code

start:
mov ax, @data
mov ds, ax
mov es, ax

lea     dx, myWord
mov     ah,09
int     21h

mov si, offset myWord
mov di, offset buffer
mov bx, offset wtohex_hextable
mov cx, offset buffer-offset myWord
sub cx,3
next:
mov ah,0
lodsb
div Sixteen ;(result in AH:AL, not DX:AX)
xlatb
stosb
mov al, ah
xlatb
stosb
loop next

mov al, 'h'
stosb
mov al, '$'
stosb

lea     dx, buffer
mov     ah,09
int     21h

mov ah, 4ch
int 21h

end start