inline-assembly

How to access stack base pointer (rbp) using inline assembly?

两盒软妹~` 提交于 2019-12-11 01:05:48
问题 My requirement is to access a function call parameters by offsetting rbp using inline assembly. But I couldn't find a suitable operand constraint to specify the base pointer in x86. I am using Intel compiler but it's documentation states that it supports GCC style inline assembly. So GCC based example would be sufficient. 回答1: You can try: #include <stdio.h> #include <inttypes.h> int main(int argc, char **argv) { uint64_t n; __asm__ __volatile__( "movq %%rbp, %0\n\t" : "=r"(n) ); printf("rbp

is it safe to use xmm registers to save the general-purpose ones?

核能气质少年 提交于 2019-12-10 23:49:37
问题 pushf //couldnt store this in other registers movd xmm0,eax//storing in xmm registers instead of pushing movd xmm1,ebx// movd xmm2,ecx// movd xmm3,edx// movd xmm4,edi//end of push backups . .//doing work . movd edi,xmm4//pop edi movd edx,xmm3//pop edx movd ecx,xmm2//pop ecx movd ebx,xmm1//pop ebx movd eax,xmm0//pop eax popf is %50 faster than push eax version in my computer. Is this safe? 回答1: Yes, as long as you (or some code you're calling) doesn't use XMM regs for anything else in the

Why am I getting these assembler errors?

試著忘記壹切 提交于 2019-12-10 22:39:51
问题 I have a big function that needs to convert from floats to integers at a point. Without this conversion the function takes 11-12 ns/loop on my machine. With the conversion it takes ~ 400 ns/loop. After some reading I found a way to speed the conversion up using a bit of inline assembly. The first iteration of my function was as follows: inline int FISTToInt (float f) { int i; asm("fld %1;" "fistp %0;" :"=r" ( i ) :"r" ( f ) : ); return i; } when I compiled that I got the following errors: src

Can pretty variable names be used for registers in GCC inline assembly?

旧城冷巷雨未停 提交于 2019-12-10 21:17:59
问题 I have some inline assembly. I want GCC to have total freedom in choosing GP registers to allocate. I also want to use pretty names for registers inside the assembly for ease of comprehension for future maintainers. I think I did this previously (10+ years ago) for ARM 5te but am now scratching my head while writing some AArch64 code. In a simpler example, this is what I want: uint32_t arg1 = 1, arg2 = 2, result; asm volatile( "add %result, %arg1, %arg2\n" // Outputs: : ??? // Inputs: : ??? /

Get linear address of FS:[0] in 32-bit protected mode / MSVC inline asm

别来无恙 提交于 2019-12-10 18:22:07
问题 I used this instruction in Visual C++ inline assembly lea eax, FS:[0] Why did eax get a zero? And how do I get the linear address of FS:[0] ? 回答1: Assuming FS points to the Windows Thread Information Block (TIB), also known as the Thread Environment Block (TEB), you get the linear address of the TIB by reading the 32-bit value at fs:[0x18] . The best way to do this in Visual C++ is to use the __readfsdword intrinsic: TEB *teb = (TEB *) __readfsdword(0x18); 回答2: The LEA instruction ("Load

GCC extended Asm - Understanding clobbers and scratch registers usage

强颜欢笑 提交于 2019-12-10 17:23:44
问题 From GCC documentation regarding Extended ASM - Clobbers and Scratch Registers I find it difficult to understand the following explanation and example: Here is a fictitious sum of squares instruction, that takes two pointers to floating point values in memory and produces a floating point register output. Notice that x, and y both appear twice in the asm parameters, once to specify memory accessed, and once to specify a base register used by the asm. Ok, first part understood, now the

How to load kernel or be able to use more space in own bootloader?

泄露秘密 提交于 2019-12-10 17:08:03
问题 I've been following this: ( http://www.codeproject.com/KB/tips/boot-loader.aspx ) But not sure what and how to do next. How to load self written kernel in it? Or how to make more place than in single segment? And what to do with binaries? I have to copy bootloader to first sector, ok, but what with kernel, etc, just put on floppy/disc? 回答1: "How to load a kernel" comes down to knowing where the kernel is on disk and where you want it in memory, and then using BIOS disk services to read it. If

What is the purpose of glibc's atomic_forced_read function?

帅比萌擦擦* 提交于 2019-12-10 15:59:10
问题 I am trying to understand the purpose of the definition of atomic_forced_read which shows up frequently in the GNU libc implementation of malloc.c. I am not great when it comes to inline assembly, but it looks like this returns the exact same value, with the same type as the input value. what am I missing here? Atomic forced read definition in atomic.h 523 #ifndef atomic_forced_read 524 # define atomic_forced_read(x) \ 525 ({ __typeof (x) __x; __asm ("" : "=r" (__x) : "0" (x)); __x; }) 526

Setting a non-default rounding mode with Rust inline asm isn't respected by the LLVM optimizer?

丶灬走出姿态 提交于 2019-12-10 15:36:15
问题 I am working on a Rust crate which changes the rounding mode (+inf, -inf, nearest, or truncate). The functions that change the rounding mode are written using inline assembly: fn upward() { let cw: u32 = 0; unsafe { asm!("stmxcsr $0; mov $0, %eax; or $$0x4000, %eax; mov %eax, $0; ldmxcsr $0;" : "=*m"(&cw) : "*m"(&cw) : "{eax}" ); } } When I compile the code in debug mode it works as intended, I get 0.3333333333337 for one-third when rounding toward positive infinity, but when I compile in

Does __asm{}; return the value of eax?

萝らか妹 提交于 2019-12-10 15:14:31
问题 Simple question. The function asm in C is used to do inline assembly in your code. But what does it return? Is it the conventional eax , and if not, what does it return? 回答1: __asm__ itself does not return a value. C standard does not define how __asm__ should handle the return value, so the behavior might be different between compilers. You stated that Visual Studio example is valid, but Visual Studio uses __asm . __asm__ is used at least by GCC. Visual Studio To get the result in a C