inline-assembly

ARM syscall as c++ template

帅比萌擦擦* 提交于 2019-12-01 22:41:41
问题 I need to call some syscalls in my newlib stubs and the current implementation uses C macros which got unreadable and awful looking over time. (And I hate macros...) However, my implementation with C++ templates does only work for one parameter: template <int nr, typename RETTYPE, typename PARAM1> inline RETTYPE syscall(PARAM1 p1) { register PARAM1 r0 asm("r0") = p1; asm volatile("svc %[nr]\n" : "=r" (r0) : [nr] "i" (nr), "r" (r0) : "memory", "r1", "r2", "r3", "r12", "lr"); return (RETTYPE)

Modifying array elements with inline assembly

最后都变了- 提交于 2019-12-01 21:39:12
Is there a way of modifying specific array elements with inline assembly ? int move[2]; I'm looking to change move[0] and move[1] in __asm . I am a novice with assembly coding, mainly stick to C++, and there is probably a very simple answer. So far I've attempted to move move[1] into registers, move the number I want to change it to into another, and then move one into the other. I have managed to get it to compile but it doesnt actually work. You can use something like MOV array[TYPE array * index], value; , for example: #include <stdio.h> int main(int argc, char **argv) { int foo[] = {1, 2,

Is there a way to disable inline assembler in GCC?

不问归期 提交于 2019-12-01 20:13:25
问题 I'm developing an online judge system for programming contests like LeetCode, Codeforces, etc. As for most programming contests, inline assembler is not allowed in C/C++, so I would like to add the same restriction to my system. I would like to let GCC and G++ produce an error when compiling a C/C++ program containing inline assembler, so that any code containing inline assembler will result in compilation error. Is there a way to achieve that? Should I pass some command line arguments to GCC

Is there a way to disable inline assembler in GCC?

那年仲夏 提交于 2019-12-01 19:29:54
I'm developing an online judge system for programming contests like LeetCode, Codeforces, etc. As for most programming contests, inline assembler is not allowed in C/C++, so I would like to add the same restriction to my system. I would like to let GCC and G++ produce an error when compiling a C/C++ program containing inline assembler, so that any code containing inline assembler will result in compilation error. Is there a way to achieve that? Should I pass some command line arguments to GCC/G++? Note: disabling inline assembler is just for obeying the rules, not for security concerns. Is

ROL / ROR on variable using inline assembly in Objective-C

被刻印的时光 ゝ 提交于 2019-12-01 19:04:50
I would like to perform ROR and ROL operations on variables in an Objective-C program. However, I can't manage it – I am not an assembly expert. Here is what I have done so far: uint8_t v1 = ....; uint8_t v2 = ....; // v2 is either 1, 2, 3, 4 or 5 asm("ROR v1, v2"); the error I get is: Unknown use of instruction mnemonic with unknown size suffix How can I fix this? Edit: The code does not need to use inline assembly. However, I haven't found a way to do this using Objective-C / C++ / C instructions. To do this in standard C, you can do: var = (var << shift) | (var >> (sizeof(var)*CHAR_BIT

c inline assembly getting “operand size mismatch” when using cmpxchg

六眼飞鱼酱① 提交于 2019-12-01 12:16:18
问题 I'm trying to use cmpxchg with inline assembly through c. This is my code: static inline int cas(volatile void* addr, int expected, int newval) { int ret; asm volatile("movl %2 , %%eax\n\t" "lock; cmpxchg %0, %3\n\t" "pushfl\n\t" "popl %1\n\t" "and $0x0040, %1\n\t" : "+m" (*(int*)addr), "=r" (ret) : "r" (expected), "r" (newval) : "%eax" ); return ret; } This is my first time using inline and i'm not sure what could be causing this problem. I tried "cmpxchgl" as well, but still nothing. Also

How to access C variable for inline assembly manipulation?

亡梦爱人 提交于 2019-12-01 08:53:19
Given this code: #include <stdio.h> int main(int argc, char **argv) { int x = 1; printf("Hello x = %d\n", x); } I'd like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax. Aniket Inge In GNU C inline asm, with x86 AT&T syntax: (But https://gcc.gnu.org/wiki/DontUseInlineAsm if you can avoid it). // this example doesn't really need volatile: the result is the same every time asm volatile("movl $0, %[some]" : [some] "=r" (x) ); after this, x contains 0. Note that you should generally

GCC inline assembly error: Error: junk `(%esp)' after expression

末鹿安然 提交于 2019-12-01 08:19:17
问题 GCC inline assembly error: Error: junk `(%esp)' after expression I'm studying gcc inline assembly. My environment is Win 7 32bit, mingw-gcc 4.6.1. I have got a problem about the 'm' constraint. Here is my c function code: static int asm_test(int a, int b) { int c = 0; __asm__ __volatile__(".intel_syntax\n" "mov eax, %1\n" //error "mov edx, %2\n" //error "add eax, edx\n" "mov %0, eax\n" //error ".att_syntax" :"=m"(c)\ :"m"(a),"m"(b)\ :"eax","edx" ); return c; } For at&t code, it is like this:

Save CPU registers to variables in GCC

允我心安 提交于 2019-12-01 08:05:53
问题 I want get the values in EAX/EBX/ESP/EIP etc. and save them in C variables. For example: int cEax; asm("mov cEax,%eax"); ... 回答1: You can use this register int eax asm("eax"); register int eax asm("ebx"); register int eax asm("esp"); //... int cEax = eax; int cEbx = ebx; int cEsp = esp; //... You can also work with those registers in an expression just as any other variables or just use that register's value directly without assigning to another variable. It's more tricky to get eip without

How to access C variable for inline assembly manipulation?

邮差的信 提交于 2019-12-01 07:12:11
问题 Given this code: #include <stdio.h> int main(int argc, char **argv) { int x = 1; printf("Hello x = %d\n", x); } I'd like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax. 回答1: In GNU C inline asm, with x86 AT&T syntax: (But https://gcc.gnu.org/wiki/DontUseInlineAsm if you can avoid it). // this example doesn't really need volatile: the result is the same every time asm volatile("movl