inline-assembly

C2244 when trying to call the pow function from inline assembly

I would like to call the pow function from inline assembly. The problem is i'm getting error C2244: 'pow' : unable to match function definition to an existing declaration. I'm new to assembly so this may be a trivial question but how do i resolve this? I guess it has something to do with the compiler not beeing able to properly resolve t...

Clang doesn't support the Lock Prefix. How shall I workaround?

Assume this code: static inline void inc(int64_t* atomic) { __asm__ __volatile__ ( "lock incq %0\n" : "=m" (*atomic) : "m" (*atomic) ); } The Clang compiler doesn't support the lock prefix (yet?). What shall I do now? ...

syscall from within GCC inline assembly

is it possible to write a single character using a syscall from within an inline assembly block? if so, how? it should look "something" like this: __asm__ __volatile__ ( " movl $1, %%edx \n\t" " movl $80, %%ecx \n\t" " movl $0, %%ebx \n\t" ...

Help with Assembly/SSE Multiplication

I've been trying to figure out how to gain some improvement in my code at a very crucial couple lines: float x = a*b; float y = c*d; float z = e*f; float w = g*h; all a, b, c... are floats. I decided to look into using SSE, but can't seem to find any improvement, in fact it turns out to be twice as slow. My SSE code is: Vector4 abcd...

Is it possible to access 32-bit registers in C ?

Is it possible to access 32-bit registers in C ? If it is, how ? And if not, then is there any way to embed Assembly code in C ? I`m using the MinGW compiler, by the way. Thanks in advance! ...

C inline assembly of x86 fbstp instruction

Was wondering how to inline a usage of fbstp on a 32 bit I86 architecture. I tried something like int main( ) { double foo = 100.0; long bar = 0; asm( "pushl %1; fbstp %0" : "=m"(bar) : "r"(foo) ); ... But bar is unchanged. I have tried reading everything I can find on this but most example ...

64-bit issues: trying to copy value from %rsp into temp variable using inline assembly

I'm taking an operating systems design class in which they have given us a microkernel written in C that we're building on top of. The kernel seems to have been designed with 32-bit machines in mind and I'm running snow leopard. So a friend in the class and I have been trying to hack it into 64-bit addressing. The biggest issue seems to...

How do I load all 1's into a mmx register? Why doesn't this work?

Hi, couldn't seem to find anything besides opinion questions on 64/32 bit stuff when I searched. __asm__ { mov rbx, 0xFFFFffffFFFFffffull movq mm2, rbx } After these 2 instructions the mm2 register holds the value 0x30500004ffffffff according to my xcode debugger (this is inline asm in C++). Now I am new to x86 assembly and my a...

Error in my first assembly program (GCC Inline Assembly)

Hi, After a lot of internet research I implemented a small assembler routine in my C++ program to get the CPU's L1 cache size using cpuid. int CPUID_getL1CacheSize() { int l1CacheSize = -1; asm ( "mov $5, %%eax\n\t" // EAX=80000005h: L1 Cache and TLB Identifiers "cpuid\n\t" "mov %%eax, %0" // eax i...

Fastest factorial implementation with 64-bit result in assembly.

This is not homework, just something I though of. So, straight computing factorial is not exactly fast; memoization can help, but if the result is to fit into 32 or 64 bits, then the factorial only can work for inputs 0 through 12 and 20 respectively. So ... we might as well use a lookup table: n n! 0 1 1 1 2 2 ...

x86/x64 CPUID in C#

Related to my other question, please help me debug "An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Stepping through the code, everything works up until the actual ...

Call a function twice with Assembly and C++

Hi, I have a code that changes the function that would be called, to my new function, but I don't want to call only my new function, I also want to call the old one. This is an example, so you can understand what I'm saying: If I disassemble my .exe, I will look at this part: L00123456: mov eax, [L00654321] //doesn't matter ...

C inline assembly on linux, write string from stack to stdout

how can i write a string (eg. "Hello") to stdout from the stack? without, data-segments, that is. void main() { __asm__( "movl $0x4, %eax \n\t" "movl $0x1, %ebx \n\t" // put "Hello" on the stack and load its address into %ecx "movl $0x5, %edx \n\t" ...

Compile error with embedded assembler

I don't understand why this code #include <iostream> using namespace std; int main(){ int result=0; _asm{ mov eax,3; MUL eax,3; mov result,eax; } cout<<result<<endl; return 0; } shows the following error. 1>c:\users\david\documents\visual studio 2010\projects\assembler_instructions\ass...

Documentation about inline gas

Hi When reading the linux 0.01 kernel I pass throw some inline gas which is hard for me to decode: __asm__("movl $0x3ff000,%%eax\n\t" "movl %%eax,%%db0\n\t" "movl $0x000d0303,%%eax\n\t" "movl %%eax,%%db7" :::"ax") or __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \ ...

What is the difference between '__asm' and '__asm__'?

I am learning inline assembly in C. As far as I can tell, the only difference between __asm { ... }; and __asm__("..."); is that the first uses mov eax, var and the second uses movl %0, %%eax with :"=r" (var) at the end. Also, there are a lot less websites about the first. What other differences are there? ...

How to convert inline assembler to .asm file

Hi all, I'm having a problem converting an inline assembler function to .asm file. I need seperate inline assembler code because in x64 architecture doesn't have support for inline assembly. Here is the code, #include <windows.h> #include <string> #include <iostream> #include <tlhelp32.h> using namespace std; int filter(int code...

How to call function with address having stack object as argument with heap based data

Hello, I have a complex problem to be solve, as I am stuck and found no way at all to solve this. Here's a code struct MyStruct { int x; float y; char c; }; void foo(MyStruct a_myStruct); int _tmain(int argc, _TCHAR* argv[]) { void *pMyStruct = malloc(sizeof(MyStruct)); int* pInt = (int*)pMyStruct; *pI...

GCC Inline-assembly: call dword ptr

Hello. If I have the following code in Windows VC++: DWORD somevar = 0x12345678; _asm call dword ptr [somevar] How can I make the same thing in GCC inline-assembly, with AT&T syntax? __asm__ __volatile__ ( "call dword ptr [%%edx]" : : "d" (somevar) ); I've tried something like this, but it generates an "junk" error... And ...

Direct call using GCC's inline assembly

If you want to call a C/C++ function from inline assembly, you can do something like this: void callee() {} void caller() { asm("call *%0" : : "r"(callee)); } GCC will then emit code which looks like this: movl $callee, %eax call *%eax This can be problematic since the indirect call will destroy the pipeline on older CPUs. Sin...