inline-assembly

incorrect register '%rbx' used with 'l' suffix

守給你的承諾、 提交于 2019-12-01 06:45:36
I'm trying to compile this code under linux with gcc compiler : static inline unsigned long get_current(void) { unsigned long current; asm volatile ( " movl %%esp, %%eax;" " andl %1, %%eax;" " movl (%%eax), %0;" : "=r" (current) : "i" (0xfffff000) ); return current; } But i'm getting this error : program.c: Assembler messages: program.c:455: Error: incorrect register `%rbx' used with `l' suffix what is wrong here ? Obviously, you're compiling for 64 bits. Try using gcc -m32 if it's not what you want, or use 64-bit registers (%esp makes no sense at all on x64). Whilst the above is sort of

How do I tell gcc that my inline assembly clobbers part of the stack?

故事扮演 提交于 2019-12-01 06:12:20
Consider inline assembly like this: uint64_t flags; asm ("pushf\n\tpop %0" : "=rm"(flags) : : /* ??? */); Nonwithstanding the fact that there is probably some kind of intrinsic to get the contents of RFLAGS, how do I indicate to the compiler that my inline assembly clobbers one quadword of memory at the top of stack? As far as I am concerned, this is currently not possible. 来源: https://stackoverflow.com/questions/39160450/how-do-i-tell-gcc-that-my-inline-assembly-clobbers-part-of-the-stack

ARM assembly: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’

假装没事ソ 提交于 2019-12-01 05:57:24
I am trying to implement a function which multiplies 32-bit operand with 256-bit operand in ARM assembly on ARM Cortex-a8. The problem is I am running out of registers and I have no idea how I can reduce the number of used registers here. Here is my function: typedef struct UN_256fe{ uint32_t uint32[8]; }UN_256fe; typedef struct UN_288bite{ uint32_t uint32[9]; }UN_288bite; void multiply32x256(uint32_t A, UN_256fe* B, UN_288bite* res){ asm ( "umull r3, r4, %9, %10;\n\t" "mov %0, r3; \n\t"/*res->uint32[0] = r3*/ "umull r3, r5, %9, %11;\n\t" "adds r6, r3, r4; \n\t"/*res->uint32[1] = r3 + r4*/

ARM assembly: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’

回眸只為那壹抹淺笑 提交于 2019-12-01 04:56:40
问题 I am trying to implement a function which multiplies 32-bit operand with 256-bit operand in ARM assembly on ARM Cortex-a8. The problem is I am running out of registers and I have no idea how I can reduce the number of used registers here. Here is my function: typedef struct UN_256fe{ uint32_t uint32[8]; }UN_256fe; typedef struct UN_288bite{ uint32_t uint32[9]; }UN_288bite; void multiply32x256(uint32_t A, UN_256fe* B, UN_288bite* res){ asm ( "umull r3, r4, %9, %10;\n\t" "mov %0, r3; \n\t"/*res

Using condition flags as GNU C inline asm outputs

别等时光非礼了梦想. 提交于 2019-12-01 04:38:13
I'm working on some code where it would be highly desirable to take condition-flags output from an inline asm block and use that as a condition to branch on in the calling C code. I don't want to store the flags (that would be useless and inefficient; there are already more efficient ways to achieve the result) but use the flags directly. Is there any way to achieve this with GNU C inline asm constraints? I'm interested in approaches that would work for multiple instruction set architectures, with the intent of using it with the condition flags produced by the architecture's LL/SC style

incorrect register '%rbx' used with 'l' suffix

醉酒当歌 提交于 2019-12-01 04:23:22
问题 I'm trying to compile this code under linux with gcc compiler : static inline unsigned long get_current(void) { unsigned long current; asm volatile ( " movl %%esp, %%eax;" " andl %1, %%eax;" " movl (%%eax), %0;" : "=r" (current) : "i" (0xfffff000) ); return current; } But i'm getting this error : program.c: Assembler messages: program.c:455: Error: incorrect register `%rbx' used with `l' suffix what is wrong here ? 回答1: Obviously, you're compiling for 64 bits. Try using gcc -m32 if it's not

What does %c mean in GCC inline assembly code?

£可爱£侵袭症+ 提交于 2019-12-01 04:01:45
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 information on what %c in the first line means. I did not find any information in the most obvious section of the GCC manual , which explains %[name] , but not %c[name] . Is there any other place I should look at? Ned From the GCC internals documentation : `%c digit ' can be used to substitute an

Constraining r10 register in gcc inline x86_64 assembly

痞子三分冷 提交于 2019-12-01 03:30:47
I'm having a go at writing a very light weight libc replacement library so that I can better understand the kernel - application interface. The first task is clearly getting some system call wrappers in place. I've successfully got 1 to 3 argument wrappers working but I'm struggling with a 4 argument varient. Here's my starting point: long _syscall4(long type, long a1, long a2, long a3, long a4) { long ret; asm ( "syscall" : "=a"(ret) : "a"(type), "D"(a1), "S"(a2), "d"(a3), "r10"(a4) : "c", "r11" ); return ret; } The compiler gives me the following error: error: matching constraint references

GCC extended asm, struct element offset encoding

荒凉一梦 提交于 2019-12-01 02:47:10
问题 I am trying to write a small piece of my code in GCC style extended asm (x86-64 target) and am having trouble encoding struct offsets. I have a struct s with a member size_t a[] , a pointer to such a struct and an index both of which are generated within the asm block. Now I need to address that element in asm asm ( "mov %[displ](%[s], %[index], 8), %%rbx" : [s] "+r" (s) , [index] "+r" (i) : "memory", "cc", "rax", "rbx" ); How can I encode displ into the asm block? Passing offsetof(struct s,

Force GCC to push arguments on the stack before calling function (using PUSH instruction)

眉间皱痕 提交于 2019-12-01 02:33:54
I have started developing a small 16-bit OS under GCC/G++. I am using a GCC cross-compiler, which I compiled under Cygwin, I am putting asm(".code16gcc\n") as the first line of each .CPP file, using Intel ASM syntax and the command lines for compiling and linking a .CPP file look like this: G++: i586-elf-g++ -c $(CPP_FILE) -o $(OBJECT_OUTPUT) -nostdinc -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fpermissive -masm=intel LD: i586-elf-ld -T $(LD_SCRIPT) $(OBJECT_OUTPUT) -o $(BINARY_OUTPUT) The problem I am currently facing is the way GCC translates function-calling code into