Questions tagged [inline-assembly]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
51 views

How to convert old x87 assembly code to extended asm (with "=u" and "=t" constraints) to convert spherical coordinates

I have this old code to transform spherical to Cartesian 3D coordinates : TDVector3D Cartesian3D_asm(const double &Theta, const double &Phi) { TDVector3D V; __asm__ { mov eax,[ebp+...
0 votes
0 answers
58 views

Unable to get the correct x86_64 CPU register values

I have a project to develop a game engine in C++. I want my game engine to be able to report errors as well as dump memory and get the values of CPU registers, print them to the screen, and then send ...
2 votes
3 answers
66 views

Forcing a function to be optimized on clang or prologuless non-naked C functions - paste together blocks of asm based on C constants

Is there anyway to force a C function on clang to be optimized even when the file is compiled with -O0? I'm looking for something equivalent to gcc's __attribute((optimize("s")) or ...
  • 57k
0 votes
0 answers
45 views

Asm block inside C program gives error C2400 in Visual Studio 2022 [duplicate]

I'm writing a C program that containes some anti-disassembly techniques, in particular I'm implementing this one: https://unprotect.it/technique/dynamically-computed-target-address/ This is my attempt ...
  • 97
0 votes
1 answer
61 views

asm error "inconsistent operand constraints in an 'asm'"

I'm trying to use this code for attiny10. Here, I try to use _delay_loop_2 but it does not work sometime. #include <avr/io.h> #include <util/delay.h> #define LED_PIN PB0 #define ...
1 vote
1 answer
39 views

Cortex M4 SVC code appears to always pass in 255 for the SVC number

I've tried following the documentation to make an SVC instruction work. From the Arm documentation here my SVC_Handler function is as they specify: void SVC_Handler(void) { __asm( ".global ...
0 votes
0 answers
10 views

Set debugging environment for inline assembly in Xcode like in Visual Studio

I have an assembly course this semester and i have to learn inline assembly using C. In my school they use MS Visual Studio with his debugging environment, which can show the disassembly, the memory ...
0 votes
2 answers
36 views

Cortex-A9 , Arm Compiler 5 (DS built int) , Read CNTFRQ register

I try to read CNTFRQ register with inline assembly code. I use the following: Arria V soc evaluation board Bare-Metal app Arm Compiler 5 (DS built in) I encountered two issues: I tried to use "...
2 votes
1 answer
48 views

GCC doesn't optimize inline assembly "=g" outputs to be memory operands when you use a temporary which is later assigned to a global?

I have setup an example on Compiler Explorer: int global; static inline int return3() { int ret; __asm__("mov %0, 3" : "=g" (ret)); return ret; } void f(...
  • 2,489
1 vote
0 answers
47 views

Compiling Intrinsics wrapper for generating platform specific code

I have a generically built binary that needs to include a lookup routine which gets compiled into vectorized instructions or otherwise based upon whether the cpu supports avx/avx2. The lookup routine ...
  • 3,243
0 votes
0 answers
27 views

llvm pass, how to use IRBuilder to insert an instruction to writes a constant int to a local txt file?

In llvm pass, how to use IRBuilder inserts an instruction at the beginning of each basic block of a code written in c/cpp , which writes a constantint to a local filename.txt. My aim is to know , when ...
1 vote
0 answers
78 views

Cannot compile C file containing asm code with MinGW

I need to compile as a 32 bit PE file a C program that has an asm snippet, the asm code is declared in this way: __asm__("jz $ + $13;\n\t" "jnz $ + $7;\n\t" "...
  • 97
1 vote
0 answers
59 views

asm() function in C [duplicate]

I'm working with some low-level C code and I don't quite understand what's going on here: /* Description of the current CPU. */ struct cpuid { unsigned eax, ebx, ecx, edx; }; /* Return information ...
1 vote
1 answer
86 views

Inserting inline assembly code into C function - I/O questions

I am developing an embedded C application for my Cortex M3 microcontroller using the GNU arm-none-eabi toolchain. I have plan to adopt an assembly subroutine that the vendor implemented into my C ...
2 votes
1 answer
72 views

Can I force a Cortex-M4 ARM processor to use conditional instructions outside an IT block?

I need to profile different machine instruction for a project, so I'm running some instructions in a loop of ~200 instructions per time (using .rept in an __asm__ directive). The processor I'm using ...
1 vote
1 answer
70 views

Aligning label values in dead code with gcc/clang

On some compilers (I'm mostly interested in GCC/clang) with void *jmp = &&label you can get the address of a label you can later goto jmp. For an interpreter with pointer tagging, I want to ...
  • 3,692
0 votes
0 answers
56 views

Writing Intel x86 Assembly within C++ wrapper on macOS [duplicate]

I'm trying to write Intel x86 Assembly code on macOS similarly to the following screenshot: This screenshot is taken from my professor's Visual Studio application, where he writes assembly. He's also ...
0 votes
0 answers
53 views

How to add a custom label in the compiled binary

I want to add a custom label in my compiled C code which I will be using later. For example, the C code might look like: #include <stdio.h> ...
  • 113
0 votes
1 answer
77 views

how to save the value of ESP during a function call

I have a problem with the below code: void swap(int* a, int* b) { __asm { mov eax, a; mov ebx, b; push[eax]; push[ebx]; pop[eax]; pop[ebx]; } } ...
1 vote
0 answers
65 views

Moving data into __uint24 with assembly

I originally had the following C code: volatile register uint16_t counter asm("r12"); __uint24 getCounter() { __uint24 res = counter; res = (res << 8) | TCNT0; return res; } ...
0 votes
0 answers
85 views

How to force Visual studio C++ compiler to inline a procedure defined in a separate external file?

Suppose that I have an external .asm file that contain below procedure definition: PSRAX PROC push rax ret PSRAX ENDP And I used that procedure with extern "C" int PSRAX();, ...
0 votes
0 answers
38 views

Inline assembly using insl instruction - passing variables in C to registers

Recently, I read Xv6, a simple Unix-like teaching operating system and its source code. There is one example of inline assembly, which I cannot find answer to my question about the implementation. ...
0 votes
0 answers
24 views

c++ inline at&t syntax num to the power of num function it always returns either 0 or 4 on the number 2

Here is my code: __asm__ ("movl %3, %%ecx\n" "movl $0, %%edx\n" "movl %2, %%eax\n" "1:\n" "movl %2, %%ebx\n" ...
0 votes
0 answers
29 views

GCC GAS jmp to a memory value without using registers (relative jmp) [duplicate]

how to jump in GCC inline asm without passing the value to a register? this code __asm__("jmp %0"::"r"(&_start)) generates: mov eax,0x1011 jmp eax but instead i want ...
  • 1,621
1 vote
1 answer
105 views

Translating RCL assembly into C/C++

I'm trying to manually translate some assembly into C/C++ in order to migrate a code-base to x64 bit as Visual Studio does not allow __asm code to compile in x64 bit. I've translated some parts, ...
  • 3,161
0 votes
1 answer
75 views

C Assembly : Return value from %eax beyond jump instruction error: expected ‘)’ before ‘:’ token

In following c function #1 int check() { __asm__ __volatile__ ( <snip some activity that has a jump to not_supported> "movl $1, %eax \n\t" \ "jmp done \n\t" ...
  • 3,243
4 votes
1 answer
106 views

How to let GCC know that the Direction Flag DF in the EFLAGS register has changed in inline asm?

For example, this code: void ppp(void); void kkk() { __asm__ volatile("std":::"cc"); ppp(); } Before calling ppp(), it needs to execute cld due to x86 API. Referencing ...
  • 101
2 votes
2 answers
54 views

gcc inline asm template for constant with out hash

I am trying to emit a global SYMBOL based on a #define VALUE. My attempt is as follows: __asm__ (".globl SYMBOL"); __asm__ (".set SYMBOL, %0" :: "i" (VALUE)); What is ...
  • 1,204
2 votes
2 answers
85 views

Input Operand `"m"(var)` and Output Operand `"=m"(var)` in GNU C inline asm? Used with no instructions as barriers?

I wonder what input operand "m"(var) and output operand "=m"(var) in asm do: asm volatile("" : "=m"(blk) : :); asm volatile("" : : "m"(...
  • 2,237
3 votes
1 answer
109 views

Vector registers in rust inline asm: Cannot use value of type `Simd<i64, 8>` for inline assembly

Compiling the following inline assembly: #![feature(portable_simd)] use std::simd::{i64x8, f64x8}; use std::arch::asm; pub fn convert(a: i64x8) -> f64x8{ let converted: f64x8; unsafe { ...
  • 1,661
0 votes
0 answers
72 views

"undefined named operand" error in C assembly

I'm trying to create a function using assembly like so : void asm_loop ( int n ){ register int *p1 asm ("r2") = &n; asm goto ( " cmp r2 , #0 \n\t" // Compare n ...
0 votes
2 answers
98 views

Inline assembly with branch

I got the following code : int *heap_x_test = (int*) malloc(4*sizeof(int)); heap_x_test[0] = 0x00310033 ; // add zero,sp,gp heap_x_test[1] = 0x008110b3 ; // sll ra,sp,s0 ...
1 vote
0 answers
99 views

Is it possible to tell the compiler that an object reachable through a pointer has changed? [duplicate]

Is there a way to tell the C++ compiler that an object that's reachable through a pointer has changed, even if it has every reason to believe it hasn't? My use-case is something like this: // Three ...
  • 53.8k
1 vote
0 answers
90 views

Why does inline asm LEA on a class member variable compile to a constant zero in Visual Studio?

When I compile a C++ program that uses assembly (using Visual Studio 2022), some of the assembly code appears to be adjusted or at least optimized away (but I have optimizations disabled). Does anyone ...
  • 423
1 vote
1 answer
50 views

__asm__ statement and csrr instruction

I'm trying to write the following code : #define CONFIG_PMP_SLOTS 16 #define PMPCFG_STRIDE 4 #define CSR_PMPCFG_BASE 0x3a0 void csr_pmp_check(){ for(int i = 0; i < (CONFIG_PMP_SLOTS / ...
2 votes
1 answer
71 views

Why do I get a strangely long opcode when attempting a RIP-relative direct jump with `*...(%rip)` in AT&T assembly?

The thing is that I cannot force gnu as interpret jmp as short or near, it constantly interprets it as far. For instance, the following code causes segfault: int main() { asm volatile ( // &...
  • 1,731
3 votes
0 answers
109 views

gcc inline assembly: how to insert symbol for table address as immediate value

I am trying to implement AES in gcc inline assembly on ARM Cortex M4. AES has many lookups into constant tables. I cannot afford to dedicate a register for the base address of each and every constant ...
5 votes
1 answer
121 views

Is there a way to use NASM syntax for inline assembly?

I really dislike the GNU Assembler syntax and I some existing code written with NASM syntax that would be quite painful and time consuming to port. Is it possible to make the global_asm!() macro use ...
  • 425
0 votes
0 answers
35 views

gcc inline assembly: What is the difference between output and output-only? [duplicate]

The following assembly works (in -O2) if all of my outputs are "output-only" (=&), but not if they are "output" (=). What is the difference between these two modes, and how can ...
0 votes
1 answer
67 views

What is the linux inline extended asm representation of jmp [rip+foo]?

As a follow up to: jmp absolute far 64 bit address. I need to write the equivalent of the following in linux extended assembly as mentioned here . Where foo is a 64 bit absolute address. jmp [rip+foo]...
0 votes
1 answer
63 views

Is there exist "_emit" or equivalent in Rust inline assembly?

In Visual Studio we can generate opcode bytes with the "_emit" directive. Also, in GCC we can use something like: asm __volatile__ (".byte 0x12"); Can we do something similar in ...
  • 239
0 votes
0 answers
93 views

Why can't my gcc inline assembly work as expected? [duplicate]

#include <cstdio> int main() { int a, b, c; const char* str = "hello world"; asm volatile ( R"(mov %0, 1 mov %1, 2 mov %2, 3 call ...
  • 21
1 vote
1 answer
34 views

What is the GCC documentation and example saying about inline asm and not using early clobbers so a pointer shares a register with a mem input?

The GCC documentation (https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1) contains the following PowerPC example and description: static void dgemv_kernel_4x4 (...
  • 1,847
0 votes
0 answers
64 views

mov [rcx], rbx is moved to the start or end of the address from rcx?

I would like to ask you a question about registers. I am totally a beginner in this so forgive me if question is trivial. I would like to know if I write in code: mov rcx, DigitSpace mov rbx, 10 mov [...
1 vote
2 answers
801 views

RISC-V inline assembly

I'm quite new to inline assembly, so I need your help to be sure that I use it correctly. I need to add assembly code inside my C code that is compiled with the Risc-v toolchain. Please consider the ...
  • 171
0 votes
0 answers
48 views

Support a custom instruction in RISC-V simulator

I've developed a RISC-V CPU simulator that only supports the base instruction set("I" extension). Now for a test, I need to make my simulator support a custom instruction. I'm wondering if ...
  • 171
-1 votes
1 answer
89 views

How to translate assembly code typed by {} into ()

First of all... I am a total noob with assembly. I understand almost nothing. But this code which you are gonna see below works fine in Visual Studio. I just need to compile this to .o file using a ...
0 votes
0 answers
20 views

Two-dimension array processing in assembly language C++ x86 mscv v19.latest

I am struggling to do this assignment for past two weeks I have tried different methods but none of them work can any one help me. In this assignment you will implement various two-dimension array (i....
0 votes
1 answer
74 views

Using JNI types like jint with arm neon inline assembly - compile errors on ARM64 [duplicate]

I know very little about inline assembly, codes(see here for details) are as follows: JNIEXPORT void JNICALL Java_com_xingin_xarengine_RGBAToGrayRenderer_nCopy(JNIEnv *env, jclass clazz, jobject ...
  • 755
0 votes
1 answer
48 views

I had an SOC with two coprocessors R52 and A55. Both had PMU registers. Is there any possibility to acees both PMU registers from single code

I use the code below to access the PMU register of the core A55. Is there any similar way to access the same register on the R52? asm volatile("mrs %0, pmccntr_el0" : "=r" (value));...
  • 1

1
2 3 4 5
43