inline-assembly

Exceuting a simple assembly code in C++ without it being in a function

馋奶兔 提交于 2019-12-13 21:01:17
问题 I'm trying to write a trampoline hook to some win32 api function, when I write the JMP instruction to the start of the original function I want it to jump to a codecave instead of calling a function. The original function start looks like this in OllyDBG: PUSH 14 MOV EAX, 12345678 ... And I patch it to: JMP 87654321 NOP NOP The address of the following function: int HookFunc(int param) { DoStuff(param); return ExecuteOriginal(param); } ExceuteOriginal looks like this: unsigned long address =

Using a specific zmm register in inline asm

本小妞迷上赌 提交于 2019-12-13 19:09:03
问题 Can I tell gcc-style inline assembly to put my __m512i variable into a specific zmm register, like zmm31 ? 回答1: Like on targets where the are no specific-register constraints at all (like ARM), use local register variables to get broad constraints to pick a specific register for asm statements. The compiler can still optimize otherwise, because the only documented guaranteed effect of a register-local is for asm inputs/outputs. The compiler will prefer the specified register even if there's

Where is __v2di declared when using -std=c++11 under GCC?

我是研究僧i 提交于 2019-12-13 17:53:32
问题 I'm having trouble compiling some code under GCC 4.9 when using -std=c++11 . GCC 4.9 is provided under Debian 8.5 (Stable), so its fairly popular. The relevant code is: __inline __m128i clmulepi64_si128 (__m128i a, __m128i b, const int i) { asm ("pclmulqdq %2, %1, %0" : "+x"(a) : "xm"(b), "i"(i)); return a; } Attempting to compile it results in: In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/include/x86intrin.h:43:0, from /usr/include/x86_64-linux-gnu/c++/4.9/bits/opt_random.h:33,

1252-142 Syntax error from AIX assembler due to local label

核能气质少年 提交于 2019-12-13 17:04:30
问题 I'm catching an assembler error when using inline assembly and a local label. The compiler is GCC, and the machine is PowerPC running AIX. The code reads the timestamp (it is roughly equivalent to rdtsc ): static unsigned long long cpucycles( void ) { unsigned long long int result=0; unsigned long int upper, lower,tmp; __asm__ __volatile__ ( "0: \n\t" "mftbu %0 \n\t" "mftb %1 \n\t" "mftbu %2 \n\t" "cmpw %2,%0 \n\t" "bne- 0b \n\t" : "=r"(upper),"=r"(lower),"=r"(tmp) : : ); result = upper;

How can I experience “LFENCE or SFENCE can not pass earlier read/write”

两盒软妹~` 提交于 2019-12-13 16:27:08
问题 I'm doing something about function safety. I need verify some X86 CPU instructions, such as LFENCE, SFENCE and MFENCE. Now I can experience MFENCE according to Intel SDM chapter 8.2.3.4 "loads may be reordered with earlier store to different location". "xor %0, %0\n\t " "movl $1, %1\n\t " "mfence\n\t " "movl %2, %0\n\t " : "=r"(r1), "=m" (X) : "m"(Y) : "memory"); "xor %0, %0\n\t " "movl $1, %1\n\t " "mfence\n\t " "movl %2, %0\n\t " : "=r"(r2), "=m" (Y) : "m"(X) : "memory"); Above code only

how can i read value from register using C++

不羁岁月 提交于 2019-12-13 15:31:42
问题 I am writhing code with C++ for a calculator ,but it display\read results with assembly,I want to store the value in any register for example( Al )to variable int in C++... I searched for away but I always find it with C language ... 回答1: If you want to read value in al into an int : GCC: unsigned char out; asm volatile("movb %%al, %[Var]" : [Var] "=r" (out)); Or unsigned char out; asm volatile("movb %%al, %0" : "=r" (out)); For MSVC: unsigned char c; __asm movb c, al There's no official C++

Error: matching constraint not valid in output operand

我怕爱的太早我们不能终老 提交于 2019-12-13 08:07:45
问题 I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9. The regular assembly I am trying to get GCC to accept is darn 3, 1 , where 3 is r3 and 1 is parameter called L in the docs. It disassembles to this on big-endian: 0: e6 05 61 7c darn r3,1 And on little-endian: 0: 7c 61 05 e6 darn r3,1 Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test

Can't declare .data in inline assembly

我怕爱的太早我们不能终老 提交于 2019-12-13 07:53:44
问题 Hello I have a problem where I can't seem to declare .data . I've tried various different things with my code and it always seems to break at this part asm( ".data\n" ".file: .ascii \"/dev/mem\\000\"\n" ); I can also remove any information after the .data and it will still break at '.data'. This is done on a raspberry pi 2 with inline assembly on C. If the rest of the code is relevant let me know but I'm pretty sure it's not. Thanks for any help! Edit: Apologies I forgot to include the error

__asm__ gcc call to a memory address

偶尔善良 提交于 2019-12-13 06:49:52
问题 I have a code that allocates memory, copies some buffer to that allocated memory and then it jumps to that memory address. the problem is that I cant jump to the memory address. Im using gcc and __asm__ but I cant call that memory address. I want to do something like: address=VirtualAlloc(NULL,len+1, MEM_COMMIT, PAGE_EXECUTE_READWRITE); dest=strncpy(address, buf, len); And then I want to do this in ASM: MOV EAX, dest CALL EAX. I've tried something like: __asm__("movl %eax, dest\n\t" "call

How to use global variable in Inline Assembly in Greenhills Compiler?

徘徊边缘 提交于 2019-12-13 04:58:39
问题 I want to use a global variable in inline assembly. asm(" LDR R0,g_TsInitStackPointerAddress"); Here g_TsInitStackPointerAddress is a global variable. While compiling its not showing any error . But while linking it shows the following error [elxr] (error) out of range: 0x1001326 (unsigned) didn't fit in 12 bits while performing relocation type R_ARM_POOL (4) at address 0x10013e0 from InitStack+0x20 (drv.o(.text)+0x1a4), to g_TsInitStackPointerAddress+0x0 ((COMMON)+0xb6) Here My function name