inline-assembly

What is r() and double percent %% in GCC inline assembly language?

本小妞迷上赌 提交于 2019-12-03 15:31:27
Example: int main(void) { int x = 10, y; asm ("movl %1, %%eax;" "movl %%eax, %0;" :"=r"(y) /* y is output operand */ :"r"(x) /* x is input operand */ :"%eax"); /* %eax is clobbered register */ } what is r(y) ? also why %% is used before eax ? Generally single % is used right? Okay, this is gcc inline assembler which very powerful but difficult to understand. First off, the % char is a special char. It lets you define register and number placeholders (mor on this later). Unfortunately the % is also used to as part of a register name (such as %EAX) so in gcc inline assembler you have to use two

gcc removes inline assembler code

北慕城南 提交于 2019-12-03 15:26:26
问题 It seems like gcc 4.6.2 removes code it considers unused from functions. test.c int main(void) { goto exit; handler: __asm__ __volatile__("jmp 0x0"); exit: return 0; } Disassembly of main() 0x08048404 <+0>: push ebp 0x08048405 <+1>: mov ebp,esp 0x08048407 <+3>: nop # <-- This is all whats left of my jmp. 0x08048408 <+4>: mov eax,0x0 0x0804840d <+9>: pop ebp 0x0804840e <+10>: ret Compiler options No optimizations enabled, just gcc -m32 -o test test.c ( -m32 because I'm on a 64 bit machine).

Code injecting/assembly inlining in Java?

冷暖自知 提交于 2019-12-03 08:26:40
问题 I know Java is a secure language but when matrix calculations are needed, can I try something faster? I am learning __asm{} in C++, Digital-Mars compiler and FASM. I want to do the same in Java. How can I inline assembly codes in functions? Is this even possible? Something like this (a vectorized loop to clamp all elements of an array to a value without branching, using AVX support of CPU): JavaAsmBlock( # get pointers into registers somehow # and tell Java which registers the asm clobbers

Compile an asm bootloader with external c code

余生颓废 提交于 2019-12-03 08:07:57
I write a boot loader in asm and want to add some compiled C code in my project. I created a test function here: test.c __asm__(".code16\n"); void print_str() { __asm__ __volatile__("mov $'A' , %al\n"); __asm__ __volatile__("mov $0x0e, %ah\n"); __asm__ __volatile__("int $0x10\n"); } And here is the asm code (the boot loader): hw.asm [org 0x7C00] [BITS 16] [extern print_str] ;nasm tip start: mov ax, 0 mov ds, ax mov es, ax mov ss, ax mov sp, 0x7C00 mov si, name call print_string mov al, ' ' int 10h mov si, version call print_string mov si, line_return call print_string call print_str ;call

How to use address constants in GCC x86 inline assembly

你。 提交于 2019-12-03 07:40:25
问题 The GCC toolchain uses AT&T assembler syntax by default, but support for Intel syntax is available via the .intel_syntax directive. Additionally, both AT&T and Intel syntax are available in a prefix and a noprefix version, which differ in whether or not they require to prefix register names with a % sigil. Depending on which directives are present, the format for address constants changes. Let's consider the following C code *(int *)0xdeadbeef = 0x1234; Using objdump -d , we find that it's

Calling fsincos instruction in LLVM slower than calling libc sin/cos functions?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 07:08:28
I am working on a language that is compiled with LLVM. Just for fun, I wanted to do some microbenchmarks. In one, I run some million sin / cos computations in a loop. In pseudocode, it looks like this: var x: Double = 0.0 for (i <- 0 to 100 000 000) x = sin(x)^2 + cos(x)^2 return x.toInteger If I'm computing sin/cos using LLVM IR inline assembly in the form: %sc = call { double, double } asm "fsincos", "={st(1)},={st},1,~{dirflag},~{fpsr},~{flags}" (double %"res") nounwind this is faster than using fsin and fcos separately instead of fsincos. However, it is slower than if I calling the llvm

How to make a C program that can run x86 hex codes

回眸只為那壹抹淺笑 提交于 2019-12-03 07:05:24
I have an array of hex codes that translate into assembly instructions and I want to create program in C that can execute these. unsigned char rawData[5356] = { 0x4C, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x0C, 0x00, 0x00, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x05, 0x00, 0x00, 0xA4, 0x01, 0x00, 0x00, 0x68, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x60, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

GCC inline assembly: constraints

笑着哭i 提交于 2019-12-03 05:06:02
问题 I'm having difficulty understanding the role constraints play in GCC inline assembly (x86). I've read the manual, which explains exactly what each constraint does. The problem is that even though I understand what each constraint does, I have very little understanding of why you would use one constraint over another, or what the implications might be. I realize this is a very broad topic, so a small example should help narrow the focus. The following is a simple asm routine which just adds

How would i make this a decryption instead of an encryption?

好久不见. 提交于 2019-12-03 01:19:39
问题 Wanna know how to get this from being a encryption code and using the same code to create a decryption. I know it means that I have to reverse some of the instruction and re-order it but I can't figure out which ones need to be reordered and which ones don't. (edit) Heres the full function to make things a bit clearer. Very new to stack overflow so apologies for any confusions. //--------------------------------------------------------------------------------------------------------------- //

What does __asm__ __volatile__ do in C?

蹲街弑〆低调 提交于 2019-12-03 01:13:54
问题 I looked into some C code from http://www.mcs.anl.gov/~kazutomo/rdtsc.html They use stuff like " inline ", " asm " etc like the following: code1: static __inline__ tick gettick (void) { unsigned a, d; __asm__ __volatile__("rdtsc": "=a" (a), "=d" (d) ); return (((tick)a) | (((tick)d) << 32)); } code2: volatile int __attribute__((noinline)) foo2 (int a0, int a1) { __asm__ __volatile__ (""); } I was wondering what does the code1 and code2 do? 回答1: The __volatile__ modifier on an __asm__ block