flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
vid
Accessing external symbols from inline AT&T assembly is very hard (and on other side, much more powerful and complete than simplistic MS way).
Quick googling: http://homepage.fudan.edu.cn/~euler/gcc_asm/inline-3.html |
|||
![]() |
|
f0dder
Use external assembly modules instead, then you don't have to worry about compiler-specific features (the big 32bit x86 OSes tend to use the same calling convention, so you can reuse your assembly code).
|
|||
![]() |
|
Cthulhu
Thank you guys.
I think I'll try to use external assembly modules then. |
|||
![]() |
|
f0dder
It obviously has a bit more overhead than inline assembly since it can't be, well, inlined
![]() ![]() |
|||
![]() |
|
Cthulhu
I already solved the problem with external assembly modules. Fasm rules!
I also did a "workaround" for the problem, just for test purposes. Just in case anyone else is interested in the solution, I'll post it here: Code: unsigned long vEax = 0; unsigned long vEbx = 0; unsigned long vEcx = 0; unsigned long vEdx = 0; asm( "xorl %eax, %eax" ); asm( "cpuid" ); asm( "pushl %edx" ); asm( "popl -16(%ebp)" ); asm( "pushl %ecx" ); asm( "popl -12(%ebp)" ); asm( "pushl %ebx" ); asm( "popl -8(%ebp)" ); asm( "pushl %eax" ); asm( "popl -4(%ebp)" ); That way it works. |
|||
![]() |
|
f0dder
Cthulhu, that inline assembly is extremely dirty and you can't depend on it working. Check the manuals on GCC's asm statement, it shows how to properly do variable input and output from assembly blocks.
|
|||
![]() |
|
Cthulhu
Man you're right.
This way is much better. Code: asm ("movl %%edx, %0" : "=m" (vEdx) ); asm ("movl %%ecx, %0" : "=m" (vEcx) ); asm ("movl %%ebx, %0" : "=m" (vEbx) ); asm ("movl %%eax, %0" : "=m" (vEax) ); In fact that dirty code caused a segmentation fault in release version. |
|||
![]() |
|
f0dder
A few thing to keep in mind...
first, you should make a single asm block - and you might have to mark it as "volatile", because otherwise GCC is free to do various reordering (dunno if it ever has or ever will, but it's going to bite your butt if it does). Also, when you have combined into one block, you need to set up the register-clobbering list, so GCC knows what to preserve - this is likely the cause of your segfault. |
|||
![]() |
|
Cthulhu
Thank you f0dder!
I'll take a look at yout tips right now. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.