- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to use the Intel inline assembler in C++ code in a project in Mac OS/X. I try to convert the example code from
http://www.zathras.de/angelweb/blog-intel-assembler-on-mac-os-x.htm
AT-T syle code to Microsoft style.
I cannot find how to do it with this code
leal myHelloWorld-myAnchorPoint(%ebx), %eax
When I try:
leaeax, myHelloWorld-myAnchorPoint[ebx]
the compiler complains about the- operator. Could you please provide me an hint.
Thanks
GB
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
Have you tried the "-use-msasm" compiler switch?
Best Regards
Lars Petter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lea ecx, myAnchorPoint
lea eax, myHelloWorld
add ecx, ebx
sub eax, ecx
and that will get you around your problem.
It is an illegal form of lea to use it in this way, I'm actually a little surprised the GNU or Mac assembler accepts this.
I'm also wondering why you're trying this code in inline assembly at all. It doesn't seem to be applicable to inline asm to me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Brandon, what you are suggesting is not position independent code anymore. In other words, it needs rebasing (relocation) in order to work. What he is asking is why Intel inline assembler doesn't perform simple mathematical operation (subtraction) and use that value as a displacement for the lea instruction.
lea eax, label2-label1[ebx]
If distance between label1 and label2 is 100 bytes then you would get:
lea eax, 100[ebx] ; syntax 1 lea eax, [ebx + 100] ; syntax 2
I am also confused as to why that isn't possible to do because it is really usefull for generating postition independent code (the code which can be loaded anywhere in memory without relocation). It is actually not a limitation of an instruction but the limitation of the preprocessor/assembler itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Igor,
Does Intel C++ inline assembler support parenthesis evaluations of constant expressions?
lea eax, (label2-label1)[ebx]
or
lea eax, [ebx + (label2-label1)]
If label1 and label2 are in the same module then the ASSEMBLER should be able to fix-up the address offset
If label1 and/or label2 are in the seperate modules then the LINKER should be able to fix-up the address offset.
Not sure if the user's Linker will do this.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd have to look into it more, but I think this is just a limitation of our MS-style inline asm parser.
I'm guessing that if you used gnu-style asm (as it more natural on MAC & Linux), you shouldn't have any problems since these get dumped straight to the assembler as seen.
I would highly recommend, however, to leave it to the compiler to figure out all the PIC calculations for you, instead of trying to do them yourself. All it takes is a simple "locally_declared_var = global_var", and you won't have to mess with the PIC stuff.
Zia.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Zia, could you give an example please? I am not sure I understand what are you talking about.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure.
For my comment on leaving it to the compiler to do the PIC, I meant doing something like this (if applicable):
int my_glob = 3;
main()
{
int my_local = my_glob;
__asm {
mov eax, my_local
.........
}
}
The glob -> local assignment will do all the necessary PIC to get my_glob, and you work on my_local as much as you want w/o worrying about PIC. Assignments back to my_glob will work the same way. Again, if this is applicable/efficient for the way you want to use PIC.
For gnu-asm, I simply meant something like this:
__asm("call LLL LLL: popl %redx movl _my_glob-LLL(%edx), %eax .......etc..");
(or any other combination of gnu-asm statements to move in/out values.
Hope this helps.
Zia.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page