I wrote this simple algo in PowerBASIC recently and it ported directly to MASM with no problems. Its an algo to convert byte data in relation to a table of characters that are passed to the algo.

; ?????????????????????????????????????????????????????????????????????????

xlat_string proc src:DWORD,ln:DWORD,tbl:DWORD

push ebx

mov edx, src ; string address in ESI
mov ebx, tbl ; character table in EBX
mov ecx, ln ; string length in ECX
add edx, ecx ; add length to ESI
neg ecx ; invert sign and use ECX as index

mov al, [edx+ecx] ; get byte
xlatb ; swap it with byte in table
mov [edx+ecx], al ; write it back to the same place
inc ecx
jnz @B ; jump back if less than zero

pop ebx


xlat_string endp

; ?????????????????????????????????????????????????????????????????????????

I tested it with this code to make sure it worked OK in MASM.

STRING tststr,"This is a test !!!!"

jmp @F

align 4

db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
db 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
db 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47
db 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
db 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79
db 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95
db 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
db 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127

lea eax, The_Table
invoke xlat_string,ADDR tststr,19,eax

invoke MessageBox,hWin,ADDR tststr,
ADDR szDisplayName,MB_OK


Posted on 2002-10-12 09:07:54 by hutch--