inline-assembly

Gcc inline assembly what does “'asm' operand has impossible constraints” mean?

六眼飞鱼酱① 提交于 2019-12-08 20:40:14
问题 I have this below code within function: void makeSystemCall(uint32_t num, uint32_t param1, uint32_t param2, uint32_t param3){ asm volatile ( "mov %0, %%eax\n\t"//Move num to eax "mov %1, %%ebx\n\t"//Move param1 to ebx "mov %2, %%ecx\n\t"//Move param2 to ecx "mov %3, %%edx\n\t"//Move param3 to edx "int $0x80"//Call interrupt. Data in eax, ebx, ecx and edx : //No output params : "r" (num), "r" (param1), "r" (param2), "r" (param3)//Input params : "%eax", "%ebx", "%ecx", "%edx" //This handles

How to write multiple assembly statements within asm() without “\t\n” separating each line using GCC?

一个人想着一个人 提交于 2019-12-08 08:59:44
问题 How to write multiple assembly statements within asm() without "\t\n" separating each line using GCC? I've seen some textbooks write multiple assembly statements within asm() as: asm(" movl $4, %eax movl $2, %ebx addl %eax, %ebx ... "); However, my compiler (GCC) doesn't recognize this syntax. Instead, I must rely on "\t\n" separating each line or using multiple asm() : asm( "movl $4, %eax\t\n" "movl $2, %ebx\t\n" "addl %eax, %ebx\t\n" ...); or asm("movl $4, %eax"); asm("movl $2, %ebx"); asm(

SSE2 instructions not working in inline assembly with C++

China☆狼群 提交于 2019-12-08 07:21:29
问题 I have this function which uses SSE2 to add some values together it's supposed to add lhs and rhs together and store the result back into lhs: template<typename T> void simdAdd(T *lhs,T *rhs) { asm volatile("movups %0,%%xmm0"::"m"(lhs)); asm volatile("movups %0,%%xmm1"::"m"(rhs)); switch(sizeof(T)) { case sizeof(uint8_t): asm volatile("paddb %%xmm0,%%xmm1":); break; case sizeof(uint16_t): asm volatile("paddw %%xmm0,%%xmm1":); break; case sizeof(float): asm volatile("addps %%xmm0,%%xmm1":);

C / Assembly: how to change a single bit in a CPU register?

ぐ巨炮叔叔 提交于 2019-12-08 04:50:29
问题 I'm a new researcher on the software fault injection field, and currently my ultimate goal is to write a simple piece of code that is able to change a single bit in a CPU register. I was thinking of doing it in C (with some Assembly calls included amongst the code). With that in mind, I found here in Stack Overflow this great thread & simple example on how to access the contents of a 32 bit CPU register: Is it possible to access 32-bit registers in C? This way, I was able to write this simple

Visual-C++ inline assembler difference of two offsets

蹲街弑〆低调 提交于 2019-12-08 04:08:02
问题 I'm porting chunk of code from MASM to C inline assembler (x86, Windows, MS VC) Foolowing is not a real code, just spoof to give an idea. Let's say I have some data defined as static array or even a code chunk between two labels, and I need to get size of it. label1: bla bla bla label2: .... mov eax, (offset label2 - offset label1) Such a code works in MASM like a charm, but in C I get following error message: "error C2425: '-' : non-constant expression in 'second operand'" I can get compiled

32bit to 64bit inline assembly porting

强颜欢笑 提交于 2019-12-07 18:35:38
问题 I have a piece of C++ code (compiled with g++ under a GNU/Linux environment) that load a function pointer (how it does that doesn't matter), pushes some arguments onto the stack with some inline assembly and then calls that function, the code is like : unsigned long stack[] = { 1, 23, 33, 43 }; /* save all the registers and the stack pointer */ unsigned long esp; asm __volatile__ ( "pusha" ); asm __volatile__ ( "mov %%esp, %0" :"=m" (esp)); for( i = 0; i < sizeof(stack); i++ ){ unsigned long

ARM inline asm: exit system call with value read from memory

笑着哭i 提交于 2019-12-07 16:47:27
问题 Problem I want to execute the exit system call in ARM using inline assembly on a Linux Android device, and I want the exit value to be read from a location in memory. Example Without giving this extra argument, a macro for the call looks like: #define ASM_EXIT() __asm__("mov %r0, #1\n\t" \ "mov %r7, #1\n\t" \ "swi #0") This works well. To accept an argument, I adjust it to: #define ASM_EXIT(var) __asm__("mov %r0, %0\n\t" \ "mov %r7, #1\n\t" \ "swi #0" \ : \ : "r"(var)) and I call it using:

Using FPU with C inline assembly

老子叫甜甜 提交于 2019-12-07 13:38:34
问题 I wrote a vector structure like this: struct vector { float x1, x2, x3, x4; }; Then I created a function which does some operations with inline assembly using the vector: struct vector *adding(const struct vector v1[], const struct vector v2[], int size) { struct vector vec[size]; int i; for(i = 0; i < size; i++) { asm( "FLDL %4 \n" //v1.x1 "FADDL %8 \n" //v2.x1 "FSTL %0 \n" "FLDL %5 \n" //v1.x2 "FADDL %9 \n" //v2.x2 "FSTL %1 \n" "FLDL %6 \n" //v1.x3 "FADDL %10 \n" //v2.x3 "FSTL %2 \n" "FLDL

GCC code that seems to break inline assembly rules but an expert believes otherwise

孤者浪人 提交于 2019-12-07 04:03:55
问题 I was engaged with an expert who allegedly has vastly superior coding skills than myself who understands inline assembly far better than I ever could. One of the claims is that as long as an operand appears as an input constraint, you don't need to list it as a clobber or specify that the register has been potentially modified by the inline assembly. The conversation came about when someone else was trying to get assistance on a memset implementation that was effectively coded this way: void

Explanation of Asm code

北慕城南 提交于 2019-12-07 03:47:58
问题 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" "movl 4(%1), %%esp\n\t" "jmp *(%1)\n" "1:\n" : "+S" (from), "+D" (to) : : "eax", "ebx", "ecx", "edx", "memory", "cc"); } Thanks 回答1: My ASM is a bit fuzzy about the details, but I think I