c++ & inline asm

P

__PPS__

Hello
I have a simple question about inline asm.
suppose I have asm { push eax, 123 }
does it mean that it will have exactly this effect as in usual asm or
it's just a suggestion to the compiler (meaning that the compiled
program might probably use some other register in place of eax)

Thanks.

Ps. I do not have any intention to use inline asm.
 
V

Victor Bazarov

__PPS__ said:
I have a simple question about inline asm.
suppose I have asm { push eax, 123 }

Actually, you're supposed to have

asm ( "push eax, 123" ) ;

(IOW, inside the parentheses there should be a string literal),
according to the Standard, subclause 7.4. Any other form, like

asm { <actual assembly commands> }

is probably an extension provided by the compiler.
does it mean that it will have exactly this effect as in usual asm or
it's just a suggestion to the compiler (meaning that the compiled
program might probably use some other register in place of eax)

The meaning of the asm definition is implementation-defined. The
usual purpose is to convey something to the assembler, often insert
a short piece of assembly code into the function. And, yes, usually
the code is assembled *exactly* as written.
Thanks.

Ps. I do not have any intention to use inline asm.

LOL... Why the question, then?

V
 
P

pavlov.pavel

Thanks.
LOL... Why the question, then?

Victor, it's because my good friend Artur says that asm is more
`powerful` when it comes to precise control of which register should be
used etc etc. He says that asm( "whatever") blocks only give compiler a
tip but aren't for sure included as-is (similar to inline keyword)

Thanks
 
I

Ioannis Vranos

Victor, it's because my good friend Artur says that asm is more
`powerful` when it comes to precise control of which register should be
used etc etc. He says that asm( "whatever") blocks only give compiler a
tip but aren't for sure included as-is (similar to inline keyword)


The standard says:

"7.4 The asm declaration

An asm declaration has the form

asm-definition:
asm ( string-literal ) ;

The meaning of an asm declaration is implementation-defined. [Note: Typically it is used
to pass information through the implementation to an assembler. ]"


So its behaviour is implementation-defined. However in most compilers it is used to pass
instructions directly to the assembler. In other words, in most compilers the passed
instructions are used, and are not considered a suggestion.
 
W

Walter

__PPS__ said:
I have a simple question about inline asm.
suppose I have asm { push eax, 123 }
does it mean that it will have exactly this effect as in usual asm or
it's just a suggestion to the compiler (meaning that the compiled
program might probably use some other register in place of eax)

Compilers that implement an inline assembler usually implement it as exactly
the instructions listed. After all, that's the whole point of having one.

-Walter
www.digitalmars.com/ctg/ctgInlineAsm.html C++ inline assembler
www.digitalmars.com/d/iasm.html D inline assembler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top