x86

Hello world in NASM with LINK.EXE and WinAPI

允我心安 提交于 2021-02-04 08:05:32
问题 I'm trying to get a simple Hello world program in NASM to run. I want to print to the console without using C-Libraries, interfacing directly with WinAPI. I am using the Visual Studio provided LINK.EXE for linking. Here's my code so far: section .data message: db 'Hello world!',10 ; 'Hello world!' plus a linefeed character messageLen: db $-message ; Length of the 'Hello world!' string global _start extern GetStdHandle extern WriteConsoleW extern ExitProcess section .text _start: ; DWORD bytes

x86 XOR opcode differences

橙三吉。 提交于 2021-02-04 07:24:11
问题 looking at http://ref.x86asm.net/coder32.html I found two opcodes that match for the statement xor eax,eax 1) opcode 31 XOR r/m16/32 r16/32 2) opcode 33 XOR r16/32 r/m16/32 both refers to 32bit register for operand1 and operand2. So, is there any differences in this specific case of the XORing two 32bit registers ? 回答1: x86 has 2 redundant ways to encode a 2-register instance of any of the basic ALU instructions that have r/m source and r/m destination forms. This redundancy is a consequence

Reverse byte order in XMM or YMM register?

你说的曾经没有我的故事 提交于 2021-02-04 06:30:06
问题 Let's say I want to reverse the byte order of a very large byte array. I can do this the slow way using the main registers but I would like to speed it up using the XMM or YMM registers. Is there a way to reverse the byte order in an XMM or YMM register? 回答1: Yes, use SSSE3 _mm_shuffle_epi8 or AVX2 _mm256_shuffle_epi8 to shuffle bytes within 16-byte AVX2 "lanes". Depending on the shuffle control vector, you can swap pairs of bytes, reverse 4-byte units, or reverse 8-byte units. Or reverse all

Efficient sse shuffle mask generation for left-packing byte elements

人盡茶涼 提交于 2021-02-04 06:19:05
问题 What would be an efficient way to optimize the following code with sse ? uint16_t change1= ... ; uint8_t* pSrc = ... ; uint8_t* pDest = ... ; if(change1 & 0x0001) *pDest++ = pSrc[0]; if(change1 & 0x0002) *pDest++ = pSrc[1]; if(change1 & 0x0004) *pDest++ = pSrc[2]; if(change1 & 0x0008) *pDest++ = pSrc[3]; if(change1 & 0x0010) *pDest++ = pSrc[4]; if(change1 & 0x0020) *pDest++ = pSrc[5]; if(change1 & 0x0040) *pDest++ = pSrc[6]; if(change1 & 0x0080) *pDest++ = pSrc[7]; if(change1 & 0x0100) *pDest

How to reverse an __m128 type variable?

心已入冬 提交于 2021-02-04 05:37:04
问题 I know this should be a Googling question but I just cannot find the answer. Say I have an __m128 variable a , whose content is a[0] , a[1] , a[2] , a[3] . Is there a single function that can reverse it to be a[3] , a[2] , a[1] , a[0] ? 回答1: Use _mm_shuffle_ps(). This instruction was already available in SSE and can gather 4 32-bit components in a single vector by combining two arbitrary 32-bit components from each of the two input vectors. How to create the mask using the macro _MM_SHUFFLE()

Make gcc use conditional moves

家住魔仙堡 提交于 2021-02-04 03:39:58
问题 Is there a gcc pragma or something I can use to force gcc to generate branch-free instructions on a specific section of code? I have a piece of code that I want gcc to compile to branch-free code using cmov instructions: int foo(int *a, int n, int x) { int i = 0, j = n; while (i < n) { #ifdef PREFETCH __builtin_prefetch(a+16*i + 15); #endif /* PREFETCH */ j = (x <= a[i]) ? i : j; i = (x <= a[i]) ? 2*i + 1 : 2*i + 2; } return j; } and, indeed, it does so: morin@soprano$ gcc -O4 -S -c test.c -o

ASM language pointer to an array

僤鯓⒐⒋嵵緔 提交于 2021-02-02 09:35:02
问题 my project I'm supposed to create a program that fills an array with an x number of fibbonacci numbers. In this case it's 47. I've got the programming set to get it the numbers etc, I just can't seem to get them into my array. Any help would be great as I'm sure i'm just off on my syntax. I'm debugging it in visual studio, so I guess that's masm? Thanks in advance. .386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword .data fibba DWORD 47 DUP(?) .code main proc mov eax,1

Converting bin to hex in assembly

▼魔方 西西 提交于 2021-02-02 03:42:30
问题 I'm beginner and I need help with converting 16-bit binary number to hex. I have done most of the code, but I need help with a couple of things. How to make it only accept 0 and 1 in input and ignore the rest of numbers and letters? After conversion process I'm getting wrong number in hex. What did I do wrong? Example input: 1010101111001101 Expected output: ABCD Current output: AAAC Here's my code: .MODEL SMALL .STACK 1000h .DATA title db 'Convert BIN to HEX:.',13,10,'$' HEX_Map DB '0','1',

Minimal executable size now 10x larger after linking than 2 years ago, for tiny programs?

半世苍凉 提交于 2021-02-02 02:33:31
问题 For a university course, I like to compare code-sizes of functionally similar programs if written and compiled using gcc/clang versus assembly. In the process of re-evaluating how to further shrink the size of some executables, I couldn't trust my eyes when the very same assembly code I assembled/linked 2 years ago now has grown >10x in size after building it again (which true for multiple programs, not only helloworld): $ make as -32 -o helloworld-asm-2020.o helloworld-asm-2020.s ld -melf

Minimal executable size now 10x larger after linking than 2 years ago, for tiny programs?

旧时模样 提交于 2021-02-02 02:33:08
问题 For a university course, I like to compare code-sizes of functionally similar programs if written and compiled using gcc/clang versus assembly. In the process of re-evaluating how to further shrink the size of some executables, I couldn't trust my eyes when the very same assembly code I assembled/linked 2 years ago now has grown >10x in size after building it again (which true for multiple programs, not only helloworld): $ make as -32 -o helloworld-asm-2020.o helloworld-asm-2020.s ld -melf