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

Inline assembly statements in the variable declarations and extern variable declarations inside a function

This is a function in C program (including in-line assembly) compiled and run ok with gcc. What is the asm statements at the end of variable declarations? Why is extern variable declared inside a function? What effect does it have compared to being…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
0
votes
1 answer

Loading 16-bit (or bigger) immediate with a Arm inline GCC assembly

Note: Just here for the brevity the examples are simplified, so they do not justify my intentions. If I would be just writing to a memory location exactly like as in the example, then the C would be the best approach. However, I'm doing stuff where…
Anton Krug
  • 1,555
  • 2
  • 19
  • 32
0
votes
0 answers

How do I pass the value of a variable in C to an argument of an instruction in inline assembly?

I am trying to use the value of a variable I've declared in C as the argument of a mov instruction in assembly. I've tried using a conversion character like this (where ptr is the variable): asm("mov x9, %p\n\t" : : "r"(ptr)); But it doesn't…
3h6_1
  • 13
  • 1
  • 2
  • 5
0
votes
1 answer

Convert C++ code to x87 inline assembly code

I am trying to convert C++ code into x87 style inline assembly code. C++ code: double a = 0.0, b = 0.0, norm2 = 0.0; int n; for (n = 0; norm2 < 4.0 && n < N; ++n) { double c = a*a - b*b + x; b = 2.0*a*b + y; a = c; norm2 = a*a…
user3702643
  • 1,465
  • 5
  • 21
  • 48
0
votes
0 answers

How can I call a function in inline assembly from C

I am currently playing around with in-line simply and I've gotten a bit stuck. I have managed to call a function with no parameters but when it comes to calling one with two parameters I get stuck. My code below should call a function (add) that…
nad34
  • 343
  • 4
  • 13
0
votes
2 answers

How to ignore output in inline assembly?

In inline assembly the first : refers to output and the second to input, what if I don't want to use the output? can I leave it empty like this: asm ("add $0, %rcx" : :"m"(Example) /* intput */ ); Plus if I want to use output only can I delete the…
user15982858
0
votes
2 answers

Assembly how to use SIDT or LIDT?

I was reading: https://www.aldeid.com/wiki/X86-assembly/Instructions/sidt But have one question, where should I save? I don't know if the memory in which I am going to save is empty to be used or that it's in range. So how should I choose that…
user15961623
0
votes
1 answer

Generate all the possible permutations of the first N numbers in Assembly Inline with Visual Studio

I am new to Assembly Inline in C. I have to solve the following problem with the inline assembler of Visual Studio: Input: a DWORD (the number N, N≤ 6) Output: a vector of DWORD (all permutations, see description in the code), a DWORD (the number…
0
votes
0 answers

Cannot call assembly function from C kernel

I am writing a 32-bit C kernel and I tried to call a function that I wrote in assembly. So I wrote an assembly file containing the function myfunc and then I wrote the kernel which defined myfunc as a global variable and I linked them together so I…
MARSHMALLOW
  • 1,315
  • 2
  • 12
  • 24
0
votes
1 answer

How to store in a register the address of an element of an array in asm?

#include void main() { //Variables char string[] = "This is a string"; _asm { XOR EAX, EAX XOR EBX, EBX XOR ECX, ECX MOV EAX, [string] } What I'm trying to do is store the memory address of the first element of…
JustJohn
  • 59
  • 1
  • 7
0
votes
1 answer

Questions on atomic_add function of arch/arm64/include/asm/atomic.h

I am very new to Linux Kernel-based C-coding Style. I am trying to understand the following implementation of the "atomic_add" function from "arch/arm64/include/asm/atomic.h" file (Lines 112-124 of here). static inline void atomic_add(int i,…
0
votes
0 answers

why does this inline assembly code not work in my c++ program?

the visual studio 2019 compiler marks the colon in the line " : [x] "m" (x), " as an error and says that it expected a closing paranthes ")" instead. Why does this inline assembly code not work? asm ( "rsqrtss %[x], %%xmm0;" "movss %%xmm0,…
0
votes
0 answers

Miscalculation in assembly language

The program gives a wrong calculation in assembly language compared to C++ and I can't find the error. Any ideas? // (2 * c + b + a - 5) / (a / 4 - 1) #include using namespace std; void print_of() { cout << "Overflow error\n"; …
0
votes
0 answers

_asm in which cases is it best to use it?

I will risk a question, sorry if the question is simple. Currently, I am refreshing the knowledge of C. I was browsing a book and found something completely new for me, namely the keyword "__asm", can anyone share their experiences, where did the…
reg3x_mr
  • 75
  • 1
  • 10
0
votes
2 answers

Is it possible to write asm in C++ with opcode instead of shellcode

I'm curious if there's a way to use __asm in c++ then write that into memory instead of doing something like: BYTE shell_code[] = { 0x48, 0x03 ,0x1c ,0x25, 0x0A, 0x00, 0x00, 0x00 }; write_to_memory(function, &shell_code, sizeof(shell_code)); So I…
1 2 3
99
100