inline-assembly

x86/x64 CPUID in C#

落爺英雄遲暮 提交于 2019-11-26 07:58:42
问题 Related to my other question, please help me debug \"An unhandled exception of type \'System.AccessViolationException\' occurred in Unknown Module. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.\" Stepping through the code, everything works up until the actual call to del() and fails in that line. This code is based on this article\'s sample and this python code which works in python. I can\'t get the code example

C/C++ function definitions without assembly

百般思念 提交于 2019-11-26 07:55:03
问题 I always thought that functions like printf() are, in the last step, defined using inline assembly. That deep in the bowels of stdio.h is buried some asm code that actually tells CPU what to do. For example, in dos, I remember it was implemented by first mov ing the beginning of the string to some memory location or register and than calling an int terupt. However, since the x64 version of Visual Studio doesn\'t support inline assembler at all, it made me wonder how there could be no

Calling printf in extended inline ASM

六月ゝ 毕业季﹏ 提交于 2019-11-26 07:47:32
问题 I\'m trying to output the same string twice in extended inline ASM in GCC , on 64-bit Linux. int main() { const char* test = \"test\\n\"; asm( \"movq %[test], %%rdi\\n\" // Debugger shows rdi = *address of string* \"movq $0, %%rax\\n\" \"push %%rbp\\n\" \"push %%rbx\\n\" \"call printf\\n\" \"pop %%rbx\\n\" \"pop %%rbp\\n\" \"movq %[test], %%rdi\\n\" // Debugger shows rdi = 0 \"movq $0, %%rax\\n\" \"push %%rbp\\n\" \"push %%rbx\\n\" \"call printf\\n\" \"pop %%rbx\\n\" \"pop %%rbp\\n\" : :

Labels in GCC inline assembly

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 07:27:26
问题 In my ongoing experimentation with GCC inline assembly, I\'ve run into a new problem regarding labels and inlined code. Consider the following simple jump: __asm__ ( \"jmp out;\" \"out:;\" : : ); This does nothing except jump to the out label. As is, this code compiles fine. But if you place it inside a function, and then compile with optimization flags, the compiler complains: \"Error: symbol \'out\' is already defined\". What seems to be happening is that the compiler is repeating this

Efficient integer compare function

非 Y 不嫁゛ 提交于 2019-11-26 06:17:02
问题 The compare function is a function that takes two arguments a and b and returns an integer describing their order. If a is smaller than b , the result is some negative integer. If a is bigger than b , the result is some positive integer. Otherwise, a and b are equal, and the result is zero. This function is often used to parameterize sorting and searching algorithms from standard libraries. Implementing the compare function for characters is quite easy; you simply subtract the arguments: int

Looping over arrays with inline assembly

血红的双手。 提交于 2019-11-26 04:55:52
问题 When looping over an array with inline assembly should I use the register modifier \"r\" or he memory modifier \"m\"? Let\'s consider an example which adds two float arrays x , and y and writes the results to z . Normally I would use intrinsics to do this like this for(int i=0; i<n/4; i++) { __m128 x4 = _mm_load_ps(&x[4*i]); __m128 y4 = _mm_load_ps(&y[4*i]); __m128 s = _mm_add_ps(x4,y4); _mm_store_ps(&z[4*i], s); } Here is the inline assembly solution I have come up with using the register

How to represent hex value such as FFFFFFBB in x86 assembly programming?

不羁的心 提交于 2019-11-26 04:00:00
问题 I\'m learning about x86 inline assembly programming. I wanted to write mov ecx, FFFFFFBB , however the compiler isn’t recognizing it. How should hex numbers like that be written in inline assembler code? 回答1: It depends on the flavour of your assembler. AT&T: movl $0xFFFFFFBB, %ecx Intel: mov ecx, 0FFFFFFBBh FYI, AT&T syntax is used by assemblers such as the GNU Assembler , whereas NASM and most of others use Intel's one. 回答2: See the x86 tag wiki for links to assembler manuals, and lots of

Can I use Intel syntax of x86 assembly with GCC?

做~自己de王妃 提交于 2019-11-26 02:09:25
问题 I want to write a small low level program. For some parts of it I will need to use assembly language, but the rest of the code will be written on C/C++. So, if I will use GCC to mix C/C++ with assembly code, do I need to use AT&T syntax or can I use Intel syntax? Or how do you mix C/C++ and asm (intel syntax) in some other way? I realize that maybe I don\'t have a choice and must use AT&T syntax, but I want to be sure.. And if there turns out to be no choice, where I can find full/official

What is the difference between &#39;asm&#39;, &#39;__asm&#39; and &#39;__asm__&#39;?

烈酒焚心 提交于 2019-11-25 22:42:55
问题 As far as I can tell, the only difference between __asm { ... }; and __asm__(\"...\"); is that the first uses mov eax, var and the second uses movl %0, %%eax with :\"=r\" (var) at the end. What other differences are there? And what about just asm ? 回答1: Which one you use depends on your compiler. This isn't standard like the C language. 回答2: There's a massive difference between MSVC inline asm and GNU C inline asm. GCC syntax is designed for optimal output without wasted instructions, for