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

Does inline ASM in C change disassembly?

I tried my best to search for this question before asking, but could not find an answer. Perhaps this question would be better suited to ask on the Reverse Engineering SE. I am examining a 32-bit C Portable Executable that I suspect to make use of…
Biggs
  • 111
  • 4
0
votes
0 answers

I can't get Non-Temporal stores/loads to work without -fsanitize=address

Non-temporal store fails every time for me, but if I replace them with temporal stores it never fails; The only way I got non-temporal loads/stores not to fail is if I use -fsanitize=address option, and I don't quiet understand why; I use calloc so…
0
votes
0 answers

Converting a C++ funtion to Inline assembly?

I am trying to convert a C++ function code that converts passed string argument to UPPERCASE, into inline assembly code. Below is what i did: // Funtion to convert each letter of employee name to uppercase. // Input : employee structure object as…
luck
  • 1
  • 1
0
votes
1 answer

Global constructor gone wrong after inline assembly

I'm having an issue that I cannot explain. I have a global constructor that sets TP: void init_threads() { register long tp asm("tp"); asm volatile("mv %0, %1" : "=r"(tp) : "r"(&main_thread)); asm…
gonzo
  • 442
  • 4
  • 15
0
votes
0 answers

ARM equivalent for x86 asm constraint "x" (256-bit vector operand)

I want to execute the assembler instruction vrhadd in C++ using __asm__. I need to map the following function to ARM-specific instructions (using vrhadd), since the given codebase was developed on x86-64 and im using ARM64. __asm__("vpavgb %[a],…
terdev
  • 57
  • 1
  • 8
0
votes
1 answer

gcc inline-assembly compilation error when optimization flags is not enabled?

I've been studying inline-assembly for almost 1 month now, and as another practice problem, I'm trying to add up two uint512 using inline-assembly, at first I got what I wanted, the code compiles and I was able to get the correct result with my code…
0xdeadbeef
  • 500
  • 3
  • 17
0
votes
0 answers

how to deal with inline assembly

why sum2 result is 6?? ,here is the code #if defined(__aarch64__) int tmp=0; int sum2=0; int a1=2; __asm__ __volatile__ ( "mov %0,3\n\t" //tmp=3 "add %1,%0,%2\n\t" …
0
votes
1 answer

How do I access a local variable using ARM assembly language?

I use the following piece of assembly code to enter the critical section in ARM Cortex-M4. The question is, how can I access the local variable primeMask? volatile uint8_t primaskValue; asm( …
0
votes
0 answers

Segmentation fault in inline assembly

I want to move an assembly code from .S to the c++ code(inline). The assembly works correctly when I use .S file. extern "C" int libucontext_getcontext(libucontext_ucontext_t *); . . . template int thread_create(C(*f),…
Hesam
  • 36
  • 5
0
votes
0 answers

Using inline assembly "__asm" what concerns are there with portability?

Using inline assembly "__asm" what concerns are there with portability? Is it safer to use heap or stack memory? Heap memory may be too non-determinstic in yielding different results on each run. The big deal is in some math computations where…
jdl
  • 6,151
  • 19
  • 83
  • 132
0
votes
0 answers

Solve Cortex M7 priority inversion deadlock by surrendering context from a higher priority IRQ to a lower priority IRQ

Background I have a custom bare metal mutex primitive written for the STM32F7 (Arm Cortex M7) processor per the Barrier and Litmus Test Cookbook from ARM, using the LDREX and STREX instructions. I use this to control critical sections in my code. It…
Tegan
  • 93
  • 5
0
votes
0 answers

What is clobber list and gcc optimization

asm volatile("cld\n\trepne\n\tinsl" : "=D" (addr), "=c" (cnt) : "d" (port), "0" (addr), "1" (cnt) : "memory", "cc"); Here insl is used so it is saying do input four times but wht tells it that when doing input four…
OSdev
  • 107
  • 6
0
votes
0 answers

gcc inline assembly: how to use intel syntax temporarily with constraint 'm' under 'gcc -masm=att'

I'd like to use intel syntax gcc inline assembly, leaving gcc's default -masm=att dialect untouched. The following code works fine: #include int main(int argc, char *argv[]) { int a = 123; int b = 0; printf("before: a = %d\n",…
Wot
  • 102
  • 11
0
votes
1 answer

Inline assembly in C with a jump and two return statements

I would like to have a void function which prints whether carry (overflow) happened and print the value of the (possibly overflowed) summand. This is my try, but it does want to compile: #include typedef unsigned long…
aahlback
  • 82
  • 1
  • 5
0
votes
0 answers

Can't store 32-bit float in 64-bit long

Clang can't compile the following code: long Result = 0; __asm { ; call 32-bit float-returning function, then MOVSS Result, xmm0 }; I'm getting "error : invalid operand for instruction", pointing to MOVSS qword ptr Result, xmm0. I'm using…
Phi
  • 467
  • 5
  • 16