I've used xlat many times in 16 bit programs without any problems, now this is the first time I've used it in 32 bit. I copied the code directly from a working program, it assembles OK but crashes at the xlat instruction. here is the code with labels changed to make it readable :-
lea bx,table-1
mov al,contents of variable
xlat
Any suggestions ?
Yes, use the following:
mov ebx,table-1
movzx eax,WORD PTR (contents of variable)
xlat
The entire contents of eax and ebx are used in xlat to access the lookup table. The upper half of eax and ebx probably had data
Solved, should be ebx not bx. The opcode help in Masm only mentions bx maybe this is incorrect or am i reading it wrong?
eil,
The address in 32 bit code must always be a 32 bit address, BX is simply not a valid address in 32 bit. XLAT? works OK but its usually faster to manually code the extraction from the 256 member lookup table than to use XLAT.
hutch do you mean something like this :-
lea ebx,table
movzx eax,variable contents
mov al byte ptr,[ebx+eax]
Quote from: Neil on July 04, 2010, 02:25:56 PM
hutch do you mean something like this :-
lea ebx,table
movzx eax,variable contents
mov al byte ptr,[ebx+eax]
I bet that what he mean.
mov ebx,offset table
movzx eax,byte ptr variable_contents
movzx eax,byte ptr [ebx+eax]
even better...
movzx eax,byte ptr variable_contents
movzx eax,byte ptr table[eax]
will work if it's always the same table
Yes Dave, that's what i meant to write but it didn't quite turn out that way :bg time for a lie down :lol
i just got up, Neil
i am good for another 3 or 4 hours :lol
That second piece of code you posted looks good but i have a minor problem with it. The variable never contains zero so the offset will be 1 out in the table.
This won't assemble:-
movzx eax,byte ptr variable
movzx eax,byte ptr table-1[eax]
This will :-
movzx eax,byte ptr variable
movzx eax,byte ptr table[eax]
So to use it I have to put a padding byte at the start of the table, unless you've got a better suggestion.
movzx eax,byte ptr table[eax-1]
now, you've got a 255 byte table
might be better to add the extra byte to the table, just for the sake of alignment
Quote from: dedndave on July 04, 2010, 03:13:08 PM
movzx eax,byte ptr table[eax-1]
now, you've got a 255 byte table
might be better to add the extra byte to the table, just for the sake of alignment
Nice one, I didn't think of that.
You could be right about alignment, i'll play with it a bit.
Something sounds wrong here, you should align the 256 item table to a boundary of 4 then when you use 1 characters as the reference you simply add the character value to the table offset to get its replacement. Range is 0 to 255 like normal, there should not be anything added to it.
he said the index value to be translated is never 0, so he is considering eliminating that entry in the table
i can see that, if you put the table in the string area of the data segment
you may only have 5 possible values (say, 6-10)
the table only needs to be 5 bytes long
movzx eax,byte ptr Table[eax-6]
I've slept on this one, literally :bg & decided it would be better if I made the variable range 0 to whatever rather than start at 1. This would solve any offset problem, got to look into it as I'm not sure how it will affect any other code.
movzx eax,byte ptr Table[eax-6]
movzx eax,byte ptr Table[eax]
the assembler generates the same instruction, either way
movzx eax,byte ptr [eax+nnnnnnnn]
the only difference is the immediate offset value