News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

xlat problem

Started by Neil, July 04, 2010, 01:37:02 PM

Previous topic - Next topic

Neil

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 ?

KeepingRealBusy

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

Neil

Solved, should be ebx not bx. The opcode help in Masm only mentions bx maybe this is incorrect or am i reading it wrong?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Neil

hutch do you mean something like this :-

lea ebx,table
movzx eax,variable contents
mov al byte ptr,[ebx+eax]

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

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

Neil

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

dedndave

i just got up, Neil
i am good for another 3 or 4 hours   :lol

Neil

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.

dedndave

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

Neil

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.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

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]

Neil

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.