News:

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

Adding al to edi?

Started by ThoughtCriminal, January 23, 2006, 03:22:37 PM

Previous topic - Next topic

ThoughtCriminal

add edi,al wont work. I tried.

Any ideas?

Thanks.

QvasiModo

The problem is EDI is 32 bits in size, and AL is 8 bits in size. But you can try this:

movzx eax, al
add edi, eax


The first instruction extends the 8-bit value of AL into EAX, the second adds EAX (32 bits) to EDI (32 bits).

ThoughtCriminal

Thanks. I forgot about those instructions.

I need to use movsx.


gabor

Hi!

You have to use movsx? Is this a misspelling or you really have to use a negative number (a value with sign bit set)?

As far as I know movsx and movzx are slow. Instead of movzx eax,al (the upper 12 bits are set to 0) use
and eax,0FFh
to clear the upper part of eax.
Or the best way is to clear the whole eax before getting a byte value into al:

xor eax,eax
...
; get value into al
add edi,eax


If you need to use movsx eax,al (the upper 12 bits are set to 1) You could make a
or eax,0FFFFFF00h
to set those bits.
Another way is to use cbw/cwd but these instructions are slow again.

Greets,Gábor

zooba

Quote from: gabor on January 24, 2006, 07:41:36 AM
If you need to use movsx eax,al (the upper 12 bits are set to 1) You could make a
or eax,0FFFFFF00h
to set those bits.

This method only works if you include a test (and al, 80h) and a jump. From my own testing, movsx is the cheapest way to sign-extend 8/16-bits to 32.

You are correct with your other points, but simply setting the upper 12 bits to 1 may make a negative out of a positive.

QvasiModo

I'd also like to add that, if I'm not wrong:

xor eax, eax
mov al, value

would actually be slower than movzx.