Questions tagged [inline-assembly]

Assembly that is embedded within a source in another, higher language, such as x86 assembly embedded in C or C++.

Inline assembly is used in higher level language to provide access to features not exposed by intrinsics. and are the most common "host" languages that allow inline asm.

Don't use inline asm without being aware of the potential performance downsides, as well as the obvious maintainability / portability downsides. The compiler can't understand inline asm for constant-propagation and other optimizations. If you can get the compiler to generate equivalent asm from normal source code without inline asm, that is almost always preferable.

Resources

The tag wiki has tons of good stuff for that architecture, and the tag wiki also has a few links.

Making a function-call from inline asm: avoid if possible


Non-x86

GNU C inline asm works the same way for non-x86 architectures (you still use input and output operands with constraints to get data into / out of asm statements).

There are differences: many targets don't have a constraint syntax for requesting a specific register (e.g. x86's "a" for eax/rax).

2169 questions
0
votes
0 answers

GCC asm function, how to insert specific op code?

I'm trying to use the asm function in C to insert redundant xor instructions: int main (int argc, char** argv) { asm(".rept 100 ; xor %eax, %eax; .endr"); return 0; } which actually works but I want to know if there is a way…
0
votes
0 answers

How to insert inline assembly instruction by using llvm pass in SPEC CPU 2006 benchmarks

The summary of what I want to do is as follows. Detect {for loop's start,end point} in SPEC CPU 2006 benchmark's source code Insert inline assembly instruction that didn't exist before (ex. 0xFF570000) So, i made LLVM pass that functions i wrote…
Jin
  • 1
0
votes
0 answers

Specify immediate offset with GCC Extended ASM

I am using GCC 10.3.0 and I have this source code: __asm__ volatile ( "movl %%gs:%0, %%eax\n\t" : "=a"(some_output) : "i"(immediate_value) ); I want to make GCC translate this instruction into movl %gs:immediate_value, %eax but…
0
votes
1 answer

operand type mismatch for `lddqu' with an __int128 "=r" destination

I need to move 128 bit value from the address [rsi - 0x80] to the dest variable below using instruction lddqu, and I am encountering the error "operand type mismatch for `lddqu'". I know there are previous questions on stackoverflow using lower…
0
votes
0 answers

Reusing the register variable causes weird behavior

I have been programming with ARM64 assembly, and my goal has been the following: Reserve a register to store sensitive information (e.g., randomly generated key) Access this reserved register to load the sensitive information and use it for the…
Jay
  • 373
  • 1
  • 10
0
votes
1 answer

Operations with R14 (LR) in ARM Keil

I have a problem using assembler in Keil uVision ARM. I try set R14 register value with this inline assembler code: __asm { MOV R14, #Loop; } But the compiler says, that "undefined symbol R14". When I write the same code in .s-file, compiler says,…
Alex
  • 1
  • 1
0
votes
0 answers

ARM64 Neon loading single element

What am I missing? I am getting this error: Unknown symbolic operand name in inline assembly string. #if defined(__MATH_NEON_64) int x0 = 4; const int* pX0 = &x0; asm( "ld1.1s {v0}, [%[x0]] \n\t" :"+r"(pX0) ::…
0
votes
2 answers

Clang doesn't pass value via register as the code specified

I have the below snippet of code, and here I want to pass the value of variable num by register rax, but it seems in the assembly code, clang doesn't use rax directly. Rather, it saves the value of num on the stack and then passes the value on the…
Jason Yu
  • 1,886
  • 16
  • 26
0
votes
0 answers

Divide a negetive number in Assembly

I want to create a program that can transfer Fahrenheit degree into Celsius . The problem is that my program output crazy number when the Celsius degree is negative, even though I tried to use idiv and div instruction but it doesn't work . Does…
0
votes
0 answers

why my asm failed? asm("movl %%ebp, %0 \n":"=r"(ebp_reg));

i want read ebp address to ebg_reg, and to offset +4 +8, archive argc and argv. when i compiler on macOS use gcc version 13.0.0. gcc -c -fno-builtin -nostdlib -fno-stack-protector entry.c malloc.c stdio.c string.c printf.c compiler…
0
votes
1 answer

"undefined named operand" error in arm64 inline assembly

This is a code I used to write some data in memory for debugging (until printf is available in u-boot program). Variable myptr is located in .__mydebug section and it is incremented by 8 after every 8-byte write and I want to write any value I'm…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
0
votes
1 answer

How to mark that C++ function modifies all possible registers?

If I have some non-inline function and C++ compiler knows that this function modifies some registers then compiler will save all necessary registers before doing function CALL. At least I expect that compiler does this (saving) as far as it knows…
Arty
  • 14,883
  • 6
  • 36
  • 69
0
votes
2 answers

Passing integer to x86 ASM in C++

I am trying to do some script hooking in C++, and have setup a simple test function for this case. void __declspec(naked) testFunct() { int myInt; myInt = 2000; __asm{ mov eax, myInt jmp [jmp_back_address] …
0
votes
0 answers

How can I use inline assembly in 64bit for float->int conversion with rounding towards -Infinity?

I was trying to convert 32bit game client to 64bit. But I can't compile, because the client has an inline ASM code, 64bit doesn't support __asm inline. So I can't find a solution for this. I hope I can get into this community. define inline…
0
votes
0 answers

Popcnt using inline assembly language in C

A simple implementation of the popcnt function in C: int popcnt(uint64_t x) { int s = 0; for (int i = 0; i < 64; i++) { if ((x << i) & 1 == 1) s++; } return s; } I am using inline assembly language (x86-64) to implement popcnt, int…