MASM instruction "s" bit question 
Author Message
 MASM instruction "s" bit question


Quote:
>Hi,

>The MASM manual shows an "s" bit appearing in the machine code of some
>instructions.
>For example the machine code for add reg,immed and add mem,immed is given as
>follows:
>100000sw mod,000,r/m (disp) data
>Could someone be kind enough to give me some examples where s=0 and s=1, and
>the corresponding rationale.

The s bit is the sign-extension bit.  It indicates that the 8 or 16
bit immediate data should have the sign bit extended.

For example, if the immediate data byte is 0FFh, the value added is
255 if the s bit is clear, or -1 if the s bit is set.

Regards,

                          -=Dave
Just my (10-010) cents
I can barely speak for myself, so I certainly can't speak for B-Tree.
Change is inevitable.  Progress is not.



Sat, 30 Dec 2000 03:00:00 GMT  
 MASM instruction "s" bit question

Quote:

>The MASM manual shows an "s" bit appearing in the machine code of some
>instructions.
>For example the machine code for add reg,immed and add mem,immed is given as
>follows:
>100000sw mod,000,r/m (disp) data
>Could someone be kind enough to give me some examples where s=0 and s=1, and
>the corresponding rationale.

s has meaning when w is 1 (word size).

ADD AX,-1 can be encoded two ways:

10 000 001    11 000 000    1111 1111    1111 1111    no sign extend
10 000 011    11 000 000    1111 1111                         sign extend

Sign extension is applied to the immediate data only.  If sign extension
"s" bit is zero, the full sized immediate data is required.

Henry S. Takeuchi

Seattle, Washington (USA)



Sat, 30 Dec 2000 03:00:00 GMT  
 MASM instruction "s" bit question

Quote:

> Thanks Henry How do I affect which of these two encodings will be produced by
> the assembler?

  Why do you want to affect it?

  MASM will use the shorter form whenever it knows that the shorter
form is correct.  It will use the longer form if it doesn't know,
or if the shorter form is not correct.

  I doubt that you want to use the long form when MASM would
normally choose the short form.

  In the rare cases that MASM would choose the long form, and the
programmer knows that the short form would work, I don't know any
way to tell MASM to use the short form.  It would be a rare and
minor optimization anyway, so it isn't worth a lot of trouble.

--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/



Sat, 30 Dec 2000 03:00:00 GMT  
 MASM instruction "s" bit question

Quote:




>> ADD AX,-1 can be encoded two ways:
>> [snip]

>Thanks Henry How do I affect which of these two encodings will be produced by
>the assembler?

Depends on the assembler.  The assemblers I'm familiar with don't have any
special way to choose--they automatically choose the shorter encoding when
the value of the immediate data is known, and that value (interpreted as
signed) is in byte range (-128 thru +127).  Otherwise, they use the longer
encoding.

Henry S. Takeuchi

Seattle, Washington (USA)



Mon, 01 Jan 2001 03:00:00 GMT  
 MASM instruction "s" bit question


Quote:
>>Thanks Henry How do I affect which of these two encodings will be produced by
>>the assembler?

>Depends on the assembler.  The assemblers I'm familiar with don't have any
>special way to choose--they automatically choose the shorter encoding when
>the value of the immediate data is known, and that value (interpreted as
>signed) is in byte range (-128 thru +127).  Otherwise, they use the longer
>encoding.

Tasm has the SMART or NOSMART directive.
Or on the command line /jSMART or /jNOSMART.

I don't know if masm has anything equivalent.

****************************************************
*      My local newsserver knows three states      *
*              down ... down ... down              *



Tue, 02 Jan 2001 03:00:00 GMT  
 MASM instruction "s" bit question

Quote:

> Hi,

> The MASM manual shows an "s" bit appearing in the machine code of some
> instructions.
> For example the machine code for add reg,immed and add mem,immed is given
as
> follows:
> 100000sw mod,000,r/m (disp) data
> Could someone be kind enough to give me some examples where s=0 and s=1,
and
> the corresponding rationale.

s=0 means not to sign-extend the immediate word or dword value.
s=1 means to sign-extend the immediate byte value into word or dword.

Ex.
80 C0 01 -- add al,1
80 C0 FF -- add al,-1
81 C0 01 00 00 00 -- add eax,1
81 C0 FF FF FF FF -- add eax.-1
81 C0 80 00 00 00 -- add eax,128
81 C0 80 FF FF FF -- add eax,-128
83 C0 01 -- add eax,1
83 C0 FF -- add eax,-1
83 C0 80 -- add eax,-128

The main rationale is to save memory.  If an immediate
value comes between -128 and 127, we can encode it
in byte form instead of word or dword form and save
1 or 3 bytes memory space.




Fri, 05 Jan 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. beginners "let"/"random" question

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. Availability of "N3" instructions

4. "0xC0000096: Privileged instruction"

5. P4's "PAUSE" instruction

6. "out" instruction

7. "OUT" Instruction

8. Pentium III "katmai" instructions

9. Instruction like "if"

10. "GLOBAL" keyword in MASM

11. "Undefined symbol" Error with MASM

12. MASM .exe "garbage"

 

 
Powered by phpBB® Forum Software