News:

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

Sign Extension: Contraction and Saturation

Started by Xor Stance, July 14, 2005, 11:02:39 PM

Previous topic - Next topic

Xor Stance

I don't understand quite well, but if it's that when I use either MOVSX or Convert instruction depend on
the algorithmn it will affect what instruction it does.


Movsx( i32, al );


Will this saturate?


i8: uns8;

stdout.put( "Enter a hexadecimal value: $" ); //let's say I had input $80 so it will become
// with zero extend $FF80

stdin.get( i8 );

stdout.newln();

movsz( i8, ax  );

stdout.put( "Value in 16-bits", ax, nl ); //zero extend

movsx( i8, ah );

stdout.put( "Value in 8-bits again", ah );


Will this get contracted? Does zero extend applies the same rules that only either zero or $FF.

Sevag.K

Quote from: Xor Stance on July 14, 2005, 11:02:39 PM
I don't understand quite well, but if it's that when I use either MOVSX or Convert instruction depend on
the algorithmn it will affect what instruction it does.


Movsx( i32, al );


Will this saturate?

no, this won't compile.

Quote
i8: uns8;

stdout.put( "Enter a hexadecimal value: $" ); //let's say I had input $80 so it will become
// with zero extend $FF80

With zero extend into a word sized register, it will become $0080
Perhaps you meant sign extend here, in which case you are correct.

Quote
stdin.get( i8 );

stdout.newln();

movsz( i8, ax  );

What do you mean here?  zero extend or sign extend?
using movsx from 8 bits to 16 bits will fill the high order byte with $FF
the same with zero extend will zero out the high order byte.


Quote
stdout.put( "Value in 16-bits", ax, nl ); //zero extend

movsx( i8, ah );

stdout.put( "Value in 8-bits again", ah );


Will this get contracted? Does zero extend applies the same rules that only either zero or $FF.

8-bit to 8-bit extension is not allowed.

Using the extension is useful for converting an 8 or 16 bit variable to fit a larger sized register.
The important thing to remember is that:

1. sign extend will fill the higher order byte(s) with '$FF's
2. zero extned will zero out the higher order byte(s).


Xor Stance

Thank you I quite understand right now. I'm will follow more like the doc suggest me and I think it follows Intel Syntax naturally, so it
will compile in a comprenhensive way. I founded some suggestions for some little syntax but I wait until I learn completely well assembly and until the dev goes up like Masm32 is. Maybe at that time I will ask for that little syntax, but I still don't know how it will affect the Intel hardware.