Mail Archives: djgpp/2000/04/28/16:50:37
Eli Zaretskii wrote:
> > So, I strongly recommend to delete it from the site, since everyone who use it
> > can have my problems with inline asm.
>
> Instead of removing inaccurate tutorials, we should correct them.
>
> So please submit changes for any piece of documentation that is
> available from the DJGPP site that you think needs to be corrected.
Okay here goes what I want to change and explain...
----------------8<---------------
Let's move on to the input field. Constraints are just instructions you give to
the compiler to handle the variables they act upon. They are enclosed in double
quotes. So what does the "g" mean? "g" lets the compiler decide where to
load the value of i into, as long as the asm instructions accept it. In general,
most of your input variables can be constrained as "g", letting the compiler
decide how to load them (gcc might even optimize it!). Other commonly used
constraints are "r" (load into any available register), "a" (ax/eax), "b"
(bx/ebx), "c" (cx/ecx), "d" (dx/edx), "D" (di/edi), "S" (si/esi), etc.
----------------8<---------------
"g" must be explained as a constrain that may be used for anything from the
following list: eax, ebx, ecx, edx or variable in memory
Using "g" for constants and addresses ("g" (&some_variable)) is a bad idea (you
may learn from my trobles again :), since there are some constraints avaiable
exactly for those needs:
i - immediate value, 0..0xffffffff
n - immediate value known at compile time.
I - immediate 0..31
J - immediate 0..63
K - immediate 255
L - immediate 65535
M - immediate 0..3 (shifts that can be done with lea)
N - immediate 0..255 (one-byte immediate value)
O - immediate 0..32
It's a good idea to explain the "m" constraint there as well:
"m" stands for memory effective address, e.g. variable.
IMHO adding the "cc" (stands for condition codes e.g. (E)FLAGS bits) to the
clobbered registers list would be also very good.
Btw, is it true that "g" may be used for the following registers only: eax, ebx,
ecx, edx? Brennan Underwood's doc states exactly this list. Does that mean that
esi and edi (parhaps plus ebp) registers can not be substituted by the compiler
instead of "g"?
bye.
Alexei A. Frounze
-----------------------------------------
Homepage: http://alexfru.chat.ru
Mirror: http://members.xoom.com/alexfru
- Raw text -