How to write hello world in assembly under Windows?

This example shows how to go directly to the Windows API and not link in the C Standard Library. global _main extern _GetStdHandle@4 extern _WriteFile@20 extern _ExitProcess@4 section .text _main: ; DWORD bytes; mov ebp, esp sub esp, 4 ; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE) push -11 call _GetStdHandle@4 mov ebx, eax ; WriteFile( hstdOut, message, … Read more

x86, difference between BYTE and BYTE PTR

Summary: NASM/YASM requires word [ecx] when the operand-size isn’t implied by the other operand. (Otherwise [ecx] is ok). MASM/TASM requires word ptr [ecx] when the operand-size isn’t implied by the other operand. (Otherwise [ecx] is ok). They each choke on the other’s syntax. WARNING: This is very strange area without any ISO standards or easy-to-find … Read more

Why data and stack segments are executable?

On modern Linux systems, the linker will mark stack/data non-executable IFF all objects that participate in the link have a special “marker” section .note.GNU-stack. If you compile e.g. int foo() { return 1; } into assembly (with gcc -S foo.c), you’ll see this: .section .note.GNU-stack,””,@progbits For nasm, the syntax is shown in section 8.9.2 of … Read more