inline-assembly

What is the right way to create a constant pool for inline assembly?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 13:35:16
问题 The problem is that inside a C function I have an inline assembly. Something like ldr r7, =0xdeadbeef svc 0 If a literal pool wasn't created explicitly (this is the case), assembler creates one at the end of the translation unit. Usually this is fine, but if the translation unit turns out to be really huge, this doesn't work, because the literal pool is too far from the ldr instruction. So, I wonder what is the best way to handle the problem. The most obvious way is to create a literal pool

Count digits of number using inline assembly [closed]

我们两清 提交于 2019-12-10 12:24:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . How can I get the Amount of digits of a number by using Delphi's inline assembler? For example : 13452 should return 5 1344 should return 4 9721343 should return 7 etc My attempt was this: function CalculateLength(Number : integer) : Integer; begin asm PUSH Length(Number) MOV @Result, EAX end; end; 回答1: Here is

Why is this simple c program with gcc (clang) inline assembly exhibiting undefined behaviour?

帅比萌擦擦* 提交于 2019-12-10 11:28:58
问题 I'm trying to do a very simple thing with gcc assembler extension: load an unsigned int variable into a register add 1 to it output the result While compiling my solution: #include <stdio.h> #define inf_int volatile unsigned long long int main(int argc, char *argv[]){ inf_int zero = 0; inf_int one = 1; inf_int infinity = ~0; printf("value of zero, one, infinity = %llu, %llu, %llu\n", zero, one, infinity); __asm__ volatile ( "addq $1, %0" : "=r" (infinity) ); __asm__ volatile ( "addq $1, %0" :

“Custom intrinsic” function for x64 instead of inline assembly possible?

浪子不回头ぞ 提交于 2019-12-10 04:08:09
问题 I am currently experimenting with the creation of highly-optimized, reusable functions for a library of mine. For instance, I write the function "is power of 2" the following way: template<class IntType> inline bool is_power_of_two( const IntType x ) { return (x != 0) && ((x & (x - 1)) == 0); } This is a portable, low-maintenance implementation as an inline C++ template. This code is compiled by VC++ 2008 to the following code with branches: is_power_of_two PROC test rcx, rcx je SHORT $LN3@is

Correct way to wrap CMPXCHG8B in GCC inline assembly, 32 bits

瘦欲@ 提交于 2019-12-10 02:30:51
问题 I'm trying to write GCC inline asm for CMPXCHG8B for ia32. No, I cannot use __sync_bool_compare_and_swap . It has to work with and without -fPIC. So far the best I've ( EDIT : does not work after all, see my own answer below for details) is register int32 ebx_val asm("ebx")= set & 0xFFFFFFFF; asm ("lock; cmpxchg8b %0;" "setz %1;" : "+m" (*a), "=q" (ret), "+A" (*cmp) : "r" (ebx_val), "c" ((int32)(set >> 32)) : "flags") However I'm not sure if this is in fact correct. I cannot do "b" ((int32)

how to write inline assembly codes about LOOP in Xcode LLVM?

霸气de小男生 提交于 2019-12-09 11:35:00
问题 I'm studying about inline assembly. I want to write a simple routine in iPhone under Xcode 4 LLVM 3.0 Compiler. I succeed write basic inline assembly codes. example : int sub(int a, int b) { int c; asm ("sub %0, %1, %2" : "=r" (c) : "r" (a), "r" (b)); return c; } I found it in stackoverflow.com and it works very well. But, I don't know how to write code about LOOP. I need to assembly codes like void brighten(unsigned char* src, unsigned char* dst, int numPixels, int intensity) { for(int i=0;

Is there an equivalent instruction to rdtsc in ARM?

独自空忆成欢 提交于 2019-12-09 09:28:38
问题 For my project I must use inline assembly instructions such as rdtsc to calculate the execution time of some C/C++ instructions. The following code seems to work on Intel but not on ARM processors: {unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t0 = ((unsigned long)a) | (((unsigned long)d) << 32);} //The C++ statement to measure its execution time {unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t1 = ((unsigned long)a) | (((unsigned long)d) << 32);} time = t1-t0; My

How to store a C++ variable in a register

前提是你 提交于 2019-12-09 08:30:28
问题 I would like some clarification regarding a point about the storage of register variables: Is there a way to ensure that if we have declared a register variable in our code, that it will ONLY be stored in a register? #include<iostream> using namespace std; int main() { register int i=10;// how can we ensure this will store in register only. i++; cout<<i<<endl; return 0; } 回答1: You can't. It is only a hint to the compiler that suggests that the variable is heavily used. Here's the C99 wording:

How to write .syntax unified UAL ARMv7 inline assembly in GCC?

北城余情 提交于 2019-12-09 03:46:28
问题 I want to write unified assembly to get rid of pesky # in front of my literals as mentioned at: Is the hash required for immediate values in ARM assembly? This is a minimal non-unified code with # : #include <assert.h> #include <inttypes.h> int main(void) { uint32_t io = 0; __asm__ ( "add %0, %0, #1;" : "+r" (io) : : ); assert(io == 1); } which compiles and later runs fine under QEMU: arm-linux-gnueabihf-gcc -c -ggdb3 -march=armv7-a -pedantic -std=c99 -Wall -Wextra \ -fno-pie -no-pie -marm -o

x86 Assembly: INC and DEC instruction and overflow flag

北慕城南 提交于 2019-12-08 22:51:41
问题 In x86 assembly, the overflow flag is set when an add or sub operation on a signed integer overflows, and the carry flag is set when an operation on an unsigned integer overflows. However, when it comes to the inc and dec instructions, the situation seems to be somewhat different. According to this website, the inc instruction does not affect the carry flag at all. But I can't find any information about how inc and dec affect the overflow flag, if at all. Do inc or dec set the overflow flag