inline-assembly

Is there a way to insert assembly code into C?

I remember back in the day with the old borland DOS compiler you could do something like this: asm { mov ax,ex etc etc... } Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me. ...

How do I do inline assembly on the IPhone?

How is it done? What steps do I need to take and what pitfalls and gotchas are there to consider? ...

How to use address constants in GCC x86 inline assembly

The GCC toolchain uses AT&T assembler syntax by default, but support for Intel syntax is available via the .intel_syntax directive. Additionally, both AT&T and Intel syntax are available in a prefix and a noprefix version, which differ in whether or not they require to prefix register names with a % sigil. Depending on which directives...

ASM in C gives an error with -std=c99

I'm now willing to compile my project with -std=c99 and I'm facing an error I'm not understanding for the moment. This line : my_type* td = ({ register kmy_type* arg0 asm("eax"); arg0; }); gives me the following error only in C99 : warning: ISO C forbids nested functions error: syntax error before ‘asm’ error: ‘arg0’ undeclared (firs...

x86 inline assembler flag

Hi Silly question, but I just can not find the necessary flag in gcc. Basically, I have in my C program the following inline assembler code asm volatile ("lea ebx, [timings] \n\t"); When compiling, I get an errormessage which says: Error: invalid char '[' beginning operand 2 `[timings]' Now I remember that a long time ago I used some...

GCC's extended version of asm

I never thought I'd be posting an assembly question. :-) In GCC, there is an extended version of the asm function. This function can take four parameters: assembly-code, output-list, input-list and overwrite-list. My question is, are the registers in the overwrite-list zeroed out? What happens to the values that were previously in th...

iphone dev : problem with inline asm

Hi, I read the different topics that deal with that kind of problem, but I still have no answer. Here is my problem : In my header file, i have this : int cl, ch, _a = a, _b = b;\ __asm__ ("smull %0, %1, %2, %3\n" "mov %0, %0, lsr %4\n" "orr %0, %0, %1, lsl %5\n" : "=&r" (cl), "=&r" (ch) : "r" (_a), "r" (_b...

What's an example of a simple C function which is faster implemented in inline assembly?

I'm having a hard time beating my compiler using inline assembly. What's a good, non-contrived examples of a function which the compiler has a hard time making really, really fast and simple? But that's relatively simple to make with inline assembly. ...

Syscall from inline asm in x86_64 Linux?

Hi, Why does this print garbage instead of exiting my program gracefully? I use system calls this way on BSD, and I wonder what would I need to make it work in Linux. int main(int argc, char **argv) { __asm ("movq $1,%rax; movq $0,%rdi; syscall"); /* exit(0) ? */ return 0; } Thanks. ...

Using NASM as inline assembler compiler in Visual Studio 2008 ?

Hi everybody, I managed to set NASM as compiler for separate .asm files, but I can't find a way to set NASM as compiler for inline assembler (__asm directive). For example, helloWorld db "Hello world !",0 won't compile (assembler syntax error, found "db"). Is there a way to do that ? Or am I bound to use MASM or use another deve...

Inline assembly error, thwarting gcc compilation attempts.

Greetings, SO. I have some code which I've made attempts at compiling using gcc, but my attempts have been thwarted. Could anyone more versed assist me with the subject, perhaps there's something I'm missing. I'm compiling this code on Linux Kitchen 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linux. int ...

Using C with inline assembler beginner problem

Hello! I am just testing and trying to learn how assembler works with C. So i was browsing around some tutorials and i found this: __asm { mov ax,0B800h //startaddress for the screen memory (in textmode) mov es,ax //add the startaddress to es xor di,di //reset di (start at the beginnin...

Explanation of Asm code

Hi, The following GCC inline asm is taken from LuaJit's coco library. Can someone provide a line by line explanation of what it does? static inline void coco_switch(coco_ctx from, coco_ctx to) { __asm__ __volatile__ ( "movl $1f, (%0)\n\t" "movl %%esp, 4(%0)\n\t" "movl %%ebp, 8(%0)\n\t" "movl 8(%1), %%ebp\n\t" "...

Switching callstack for C++ functions

Hi, Here's my previous question about switching C callstacks. However, C++ uses a different calling convention (thiscall) and may require some different asm code. Can someone explain the differences and point to or supply some code snippets that switch C++ callstacks (preferably in GCC inline asm)? Thanks, James ...

Linux assembler error "impossible constraint in ‘asm’"

I'm starting with assembler under Linux. I have saved the following code as testasm.c and compiled it with: gcc testasm.c -otestasm The compiler replies: "impossible constraint in ‘asm’". #include <stdio.h> int main(void) { int foo=10,bar=15; __asm__ __volatile__ ("addl %%ebx,%%eax" : "=eax"(foo) : "eax"(foo), "ebx"(...

Inline assembly in C: Dynamic registers

I'm trying to inline some assembly code in my C code: __asm { mov reg,val }; The problem: I want to define the register and value dynamically. I know the 'val' can be a variable written in the C code, but I don't know how can I choose the register dynamically (i.e decide according to user input- register 'dh' or 'dl'). Any suggestion...

Inline assembly in C: INT command and C variables

I'm trying to use assembly in C code using C variables. My code looks like this: __asm { INT interruptValue }; Where 'interruptValue' is a variable I get from the user (e.g 15 or 15h). When I try to compile I get: Assembler error: 'Invalid instruction operands' I don't know what is the correct type for interruptValue . I trie...

Problem regarding inline assembly and function overwriting.

Somebody over at SO posted a question asking how he could "hide" a function. This was my answer: #include <stdio.h> #include <stdlib.h> int encrypt(void) { char *text="Hello World"; asm("push text"); asm("call printf"); return 0; } int main(int argc, char *argv[]) { volatile unsigned char *i=encrypt; while(*i!=0x00) *i...

Translate inline assembly to support x64

I have a small inline assembly code written in my C code. The asm goes through an array and if needed, move values from a different array to a register. In the end, an interrupt is called. The code is similar to this: cmp arrPointer[2],1h jne EXIT mov AX, shortArrPtr[2] EXIT: int 3h This all work in x86 but according to microsoft: x64...

Includes in inline assembly

We are working on a toy operating system as a assignment for a class. I'm having some trouble with writing of the kernel panic function. It should save all registers, call some printf-like function, then print the saved registers and halt the cpu. Right now it's defined as a macro: #define panic(...) \ do{ \ asm volatile("S...