inline-assembly

Why does MSVC not support inline assembly for AMD64 and Itanium targets?

送分小仙女□ 提交于 2019-11-28 07:12:23
问题 Yesterday I learned that inline assembly (with the __asm keyword) is not supported under Microsoft Visual C++ when compiling for AMD64 and Itanium targets. Is that correct? And if so, does anyone know why they would not support inline assembly for those targets? It seems like a rather big feature to just drop... 回答1: Correct, it still isn't supported in VS 2010 Beta 1. My guess is that inline assembly is just too difficult to implement: the way Microsoft implemented it, it integrates with the

Assembly code fsqrt and fmul instructions

北城余情 提交于 2019-11-28 06:55:50
问题 I'm trying to compute 1.34 *sqrt(lght) in this function using inline assembly but I'm getting errors like: '_asm' undeclared (first use in this function) each undeclared identifier is reported only once for each func tion it appears in expected ';' before '{' token I have been researching how to solve this problem but can't find much information. Can someone suggest a way to get this to work? My code is: double hullSpeed(double lgth) { _asm { global _start fld lght; //load lght fld st(0); /

GCC: putchar(char) in inline assembly

*爱你&永不变心* 提交于 2019-11-28 05:55:08
问题 Overflow, how can I implement the putchar(char) procedure using inline assembly only? I would like to do this in x86-64 assembly. The reason for me doing this is to implement my own standard-lib (or at least part of it). Here is what I have so far: void putchar(char c) { /* your code here: print character c on stdout */ asm(...); } void _start() { /* exit system call */ asm("mov $1,%rax;" "xor %rbx,%rbx;" "int $0x80" ); } I am compiling with: gcc -nostdlib -o putchar putchar.c Thanks for

How to write a short block of inline gnu extended assembly to swap the values of two integer variables?

半世苍凉 提交于 2019-11-28 05:14:04
问题 For entertainment, I am learning gnu extended assembly using AT&T syntax for x86 with a 32bit Linux target. I have just spent the last three hours coding two possible solutions to my challenge of swapping the values of two integer variables a and b , and neither of my solutions completely solved my problem. First, let's look at my TODO obstacle in some more detail: int main() { int a = 2, b = 1; printf("a is %d, b is %d\n", a, b); // TODO: swap a and b using extended assembly, and do not

Is this assembly function call safe/complete?

老子叫甜甜 提交于 2019-11-28 02:05:47
I don't have experience in assembly, but this is what I've been working on. I would like input if I'm missing any fundamental aspects to passing parameters and calling a function via pointer in assembly. For instance I'm wondering if I supposed to restore ecx , edx , esi , edi . I read they are general purpose registers, but I couldn't find if they need to be restored? Is there any kind of cleanup I am supposed to do after a call? This is the code I have now, and it does work: #include "stdio.h" void foo(int a, int b, int c, int d) { printf("values = %d and %d and %d and %d\r\n", a, b, c, d);

Questions about the performance of different implementations of strlen [closed]

最后都变了- 提交于 2019-11-28 01:36:37
I have implemented the strlen() function in different ways, including SSE2 assembly , SSE4.2 assembly and SSE2 intrinsic , I also exerted some experiments on them, with strlen() in <string.h> and strlen() in glibc . However, their performance in terms of milliseconds (time) are unexpected. My experiment environment: CentOS 7.0 + gcc 4.8.5 + Intel Xeon Following are my implementations: strlen using SSE2 assembly long strlen_sse2_asm(const char* src){ long result = 0; asm( "movl %1, %%edi\n\t" "movl $-0x10, %%eax\n\t" "pxor %%xmm0, %%xmm0\n\t" "lloop:\n\t" "addl $0x10, %%eax\n\t" "movdqu (%%edi,

Calling a function in gcc inline assembly

不羁的心 提交于 2019-11-28 01:08:51
问题 Say, I want to call a function with the following signature in inline assembly of gcc. How can I do that? int some_function( void * arg ); 回答1: Generally you'll want to do something like void *x; asm(".. code that writes to register %0" : "=r"(x) : ... int r = some_function(x); asm(".. code that uses the result..." : ... : "r"(r), ... That is, you don't want to do the function call in the inline asm at all. That way you don't have to worry about details of the calling conventions, or stack

calling assembly function from c

ε祈祈猫儿з 提交于 2019-11-28 00:13:13
I'm trying to call an assembly function from c,but i keep getting errors. .text .globl integrate .type integrate, @function integrate: push %ebp mov %esp, %ebp mov $0,%edi start_loop: cmp %edi,1024 je loop_exit mov 8(%ebp),%eax mov 12(%ebp),%ecx sub %eax,%ecx add %edi,%ecx incl %edi jmp start_loop loop_exit: movl %ebp, %esp popl %ebp ret This is my assembly function,file called integrate.s. #include <stdio.h> extern int integrate(int from,int to); void main() { printf("%d",integrate(1,10)); } Heres my c code. function.c:5:6: warning: return type of ‘main’ is not ‘int’ [-Wmain] /tmp/cciR63og.o:

When to use earlyclobber constraint in extended GCC inline assembly?

久未见 提交于 2019-11-27 23:58:02
I understand when to use a cobbler list (e.g. listing a register which is modified in the assembly so that it doesn't get chosen for use as an input register, etc), but I can't wrap my head around the the earlyclobber constraint & . If you list your outputs, wouldn't that already mean that inputs can't use the selected register (aside from matching digit constraints)? For example: asm( "movl $1, %0;" "addl $3, %0;" "addl $4, %1;" "addl %1, %0;" : "=g"(num_out) : "g"(num_in) : ); Would & even be needed for the output variables? The compiler should know the register that was selected for the

Is inline asm part of the ANSI C standard?

南楼画角 提交于 2019-11-27 18:17:24
问题 I always thought it was but many IDEs and syntax highlighting tools do not highlight ASM in C, but they always do with C++. Is inline assembly part of the C standard (ANSII or ISO) or not? 回答1: It's not in the ISO C standard (n1570 draft of C2011) as such, but mentioned in annex J (common extensions): J.5.10 The asm keyword 1 The asm keyword may be used to insert assembly language directly into the translator output (6.8). The most common implementation is via a statement of the form: asm (