inline-assembly

GCC: Inline assembly - good for?

So I just found out GCC could do inline assembly and I was wondering two things: What's the benefit of being able to inline assembly? Is it possible to use GCC as an assembly compiler/assembler to learn assembly? I've found a couple articles but they are all oldish, 2000 and 2001, not really sure of their relevance. Thanks ...

Inline Assembler: What scratch registers can be used?

When inserting inline assembler into a function in a C-like language, what is the convention about what registers you're allowed to use for scratch? Is it the compiler's responsibility to save the values of all the registers it needs to save before entering the asm block? Is it the responsibility of the programmer to store the values i...

How to write inline assembly in gnu pascal?

Since there is not offical reference,I got only one tutorial gpcasm.zip .But when I try to follow the tut and try the inline assembly example on my debian.The gpc was not happy with it. gnu_asm.pas : In procedure 'MyStupidDelay': gnu_asm.pas:3: error : can't find a register in class AREG while reloading asm Here is the code progra...

What does %c mean in GCC inline assembly code?

I am trying to understand this inline assembly code which comes from _hypercall0 here. asm volatile ("call hypercall_page+%c[offset]" \ : "=r" (__res) \ : [offset] "i" (__HYPERVISOR_##name * sizeof(hypercall_page[0])) \ : "memory", "edi", "esi", "edx", "ecx", "ebx", "eax") I am having trouble finding informatio...

ljmp syntax in gcc inline assembly

I was thinking of using a far jump to set the code segment (CS) register. Getting into why I'm doing this and why I'm dealing with segmentation at all would take a while, so bear with me and consider it an academic exercise. I can't seem to get the syntax right. Error: suffix or operands invalid for 'ljmp' I know it's foolish to put c...

Need atomic addition operation code on Solaris(sparc architecture)

I need atomic operation code equivalent to following: __asm__ __volatile__ ( " lock;\n" " addl %1, %0; \n" " movl %0, %%eax" : "=m"(a), "=a" (c) : "ir"(b) ); (Adding two variables a and b and output stored in both a ...

What is causing this segmentation fault while using SSE instructions?

This problem is driving me a bit crazy. The code seems to be segmentation faulting for no good reason: #define MULT_FLOAT4(X, Y) ({ \ asm volatile ( \ "movups (%0), %%xmm0\n\t" \ "mulps (%1), %%xmm0\n\t" \ "movups %%xmm0, (%1)" \ :: "r" (X), "r" (Y)); }) int main(void) { int before; float a[4...

How do you detect the CPU architecture type during run-time with GCC and inline asm?

Hello, I need to find the architecture type of a CPU. I do not have access to /proc/cpuinfo, as the machine is running syslinux. I know there is a way to do it with inline ASM, however I believe my syntax is incorrect as my variable iedx is not being set properly. I'm drudging along with ASM, and by no means an expert. If anyone has an...

AT&T inline syntax

can anyone show my the correct AT&T syntax to do what i'm doing below in INTEL i've shown my attempts at AT&T, but they don't compile... unsigned int CheckIfGenuineIntel(void) { unsigned int VendorIdentificationString[4] = {0, 0, 0, 0}; #if defined( _DO_INTEL_ ) __asm__ __volatile__ ( "xor eax, eax\n\t" "cpu...

at&t asm inline c++ problem

My Code const int howmany = 5046; char buffer[howmany]; asm("lea buffer,%esi"); //Get the address of buffer asm("mov howmany,%ebx"); //Set the loop number asm("buf_loop:"); //Lable for beginning of loop asm("movb (%esi),%al"); //Copy buffer[x] to al asm("inc %e...

Can you convert this inline asm into non-inline one?

Hi, I came across this inline asm. I am not sure how it should look without this syntax... Could someone show it to me? __asm__ volatile ("lock\n\tincl %0" :"=m"(llvm_cbe_tmp__29) :"m"(*(llvm_cbe_tmp__29))"cc"); ...

How to write binary data to file in assembler?

I tried a binary write via sys_write syscall (to stdout or file) but I can have only text file. How to have no-text (binary) bytes too? "mov %eax, %ebx;" "mov $4, %eax;" "mov -0x40(%rbp), %ecx;" "mov $14, %edx;" "int $0x80;" Trying with this example I can't have 14 bytes written if they are not text-bytes (...

How do you populate an x86 XMM register with 4 identical floats from another XMM register entry?

I'm trying to implement some inline assembler (in C/C++ code) to take advantage of SSE. I'd like to copy and duplicate values (from an XMM register, or from memory) to another XMM register. For example, suppose I have some values {1, 2, 3, 4} in memory. I'd like to copy these values such that xmm1 is populated with {1, 1, 1, 1}, xmm2 wit...

Inline assembly inside loops

Hello. I use inline assembly massively in a project where I need to call functions with an unknown number of arguments at compile time and while I manage myself to get it to work, sometimes, in linux (in windows I don't recall having that problem) strange things like this happen: If I have something like for(int i = 1; i >= 0; i--) ...

What is the difference between these two forms of inline assembler in C?

Background: I've been tasked with writing a data collection program for a Unitech HT630, which runs a proprietary DOS operating system that can run executables compiled for 16-bit MS DOS, albeit with some restrictions. I'm using the Digital Mars C/C++ compiler, which seems to be working very well. For some things I can use standard C l...

Nasm Inline Assembly Using GCC

In my project I need to use inline Assembly, but it need to be Nasm, because I'm not too much familiar with GAS. My try: void DateAndTime() { asm (.l1: mov al,10 ;Get RTC register A out RTCaddress,al in al,RTCdata test al,0x80 ;Is update in progress? jne .l1 ; yes, wait mov ...

Reading a register value into a C variable

I remember seeing a way to use extended gcc inline assembly to read a register value and store it into a C variable. I cannot though for the life of me remember how to form the asm statement. Any help is much appreciated. ...

Getting the address of the function that called my function with inline assembly

Hello. I would like to know how to retrieve the address of the function that called my function with inline assembly. My idea is to get the address to where the function that called mine will return and using the instruction before it (that is a call to the function that called mine) retrieving the address of the one that called mine add...

a Simple "Hello World" Inline Assembly language Program in C/C++....

i use devcpp and borland c compiler.... asm { mov ax,4 // (I/O Func.) mov bx,1 // (Output func) mov cx,&name // (address of the string) mov dx,6 // (lenght of the string) int 0x21 // system call } in the above code snippets i want to print a string with the help of assembly language... ...

Beginner problem with inline assembly

I am using VS2008 C++ (no libs). This is my code: __asm { jmp start msg: db "http://www.stackoverflow.com" dtfld: db "00/00/0000" tmfld: db "00:00:00" start: I am getting the following errors: Error 1 error C2400: inline assembler syntax error in 'opcode'; found 'bad token' Error 2 e...