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
1 answer

The execution time of C calling multiple the same assembly is increasing exponentially

The following C code should simply execute p times the same assembly code, which in turns should only decrease of the ecx register in sixteen loops from 16 to 0. When p is small, the program completes quickly, but when p is high (say p = 16), its…
ran
  • 13
  • 1
0
votes
0 answers

error: 'asm' operand has impossible constraints (A53) - gcc 9.3.1

This is code to read 64bit address space. Issue showed up with gcc 9.3.1, did not have issue with earlier version of gcc static inline void write_to_64bit_address(uint64_t address, uint32_t data) { uint32_t address_upper =…
0
votes
1 answer

Verify stw actually wrote to memory

I want to verify my stw actually wrote to a memory location using C. I know I could use a load word to read it(as long as I didn't use the same register it was written to?), but what's the equivalent syntax that would work in C?
JWorkin
  • 31
  • 5
0
votes
0 answers

_asm function, which prints "Pow (x) = x^2"

I create this piece of code in VS (C++) #include using namespace std; static short arr[10]; void powers() { _asm { mov ecx, 0; mov dx, 0; for: mov ax, cx; inc ax; mul ax; mov[arr…
cwva44
  • 9
  • 2
0
votes
0 answers

Using inline assembly to copy data from one array to another in C

I'm trying to copy data from one array to another using inline assembly in C by using the rep movsd, my code currently looks like this: #include int main(){ int v1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int v2[10]; asm ("mov %edi,…
Bruno Mello
  • 4,448
  • 1
  • 9
  • 39
0
votes
0 answers

inline assembly code for calculating TCP checksums in Linux

I'm trying to understand following inline assembly code, it took from https://elixir.bootlin.com/linux/v3.16.82/source/arch/x86/include/asm/checksum_32.h at line 114 how it works please.... static inline __wsum csum_tcpudp_nofold(__be32 saddr,…
HSan
  • 1
0
votes
0 answers

How can i fix Inline Assembly in Code blocks?

What did i did wrong? **#include #include int x,y,vysled=0; int main() { asm(".intel_syntax noprefix \n" "mov eax,_x \n" "add eax,_y \n" "mov _vysled,eax \n" …
0
votes
1 answer

The usage of writemask k1 in AVX-512 VORPS?

I am studying AVX-512. I have a question about VORPS. The documentation says like this: EVEX.512.0F.W0 56 /r VORPS zmm1 {k1}{z}, zmm2, zmm3/m512/m32bcst Return the bitwise logical OR of packed single-precision floating-point values in zmm2 and…
Ammar Faizi
  • 1,393
  • 2
  • 11
  • 26
0
votes
1 answer

How to store register values using assembly to C++ variables?

int my_var; void __declspec(naked) stuff() { __asm { lea edx, [ecx + edi + 0x0000111] } } How to store the value from the address [ecx + edi + 0x0000111] in the c++ variable "my_var" above.
0
votes
1 answer

Quick workaround for SSE2 movq instruction on non-SSE2 CPUs

How could I convert a movq SSE2 instruction into a simple code snippet which I could later patch into the original EXE which cointained? Please if you could provide sample direct instructions to be used as a replacement "template", so much the…
MSC
  • 1
0
votes
1 answer

How use INT %0 in inline asm with the interrupt number coming from a C variable?

I want to call the bios inline my c code. I tried asm("int %%al"::"a" (interrupt)); but gcc write Error: operand size mismatch for 'int'. I wonder that code work.
0
votes
0 answers

How to iterate over a C array in inline assembly?

I just started learning assembly for a contest and I am using intel-syntax inline assembly. Recentlly I've learned how to access global C variable's in assembly using ptr[rip + ] syntax. (for example in the mov command) I tried…
OverShifted
  • 457
  • 1
  • 7
  • 17
0
votes
0 answers

How do I compile C code with assembly with arm neon instructions in Android Studio?

I am trying to compile a math library for project that uses arm neon assembly instructions. However a list of errors is generated whenever I try to build the file, such…
Steve M
  • 9,296
  • 11
  • 49
  • 98
0
votes
0 answers

How to understand these few lines of in-line _asm_ powerPC code

I am in process of migrating some legacy code to vxWorks 7.0. The vxWorks 6.9 code has the following few lines of assembly in an ISR. I am seeking an understanding of the below code line-by-line if possible. I am totally inexperienced with PPC…
peinal
  • 121
  • 4
0
votes
1 answer

x86-64 Zero Flag is clearing between inline calls (and another problem)

I am using the bsf x86-64 instruction found on page 210 of Intels developers manual found here. Essentially, if a least significant 1 bit is found, its bit index is stored in the destination operand . Furthermore, the ZF flag is set to 1 if all the…
Dean P
  • 1,841
  • 23
  • 23
1 2 3
99
100