Skip to content

Instantly share code, notes, and snippets.

@georgy7
Last active November 15, 2017 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgy7/e9280f998caa6e7a1a163e2eb20365e1 to your computer and use it in GitHub Desktop.
Save georgy7/e9280f998caa6e7a1a163e2eb20365e1 to your computer and use it in GitHub Desktop.
flat assembler Windows (PE) CLI HelloWorld
format pe CONSOLE 4.0
entry start
include 'win32a.inc'
stdin = -10
stdout = -11
stderr = -12
section '.data' data readable writeable
message db 'Hello, World!',10
stdinHandle dd ?
stdoutHandle dd ?
section '.code' code readable executable
start:
invoke GetStdHandle,stdin
mov [stdinHandle],eax
invoke GetStdHandle, stdout
mov [stdoutHandle],eax
; Probably the same as `_setmode(_fileno(handle) _o_binary);` in C.
invoke SetConsoleMode,stdinHandle,0
invoke SetConsoleMode,stdoutHandle,0
invoke WriteConsoleA,[stdoutHandle],message,14,NULL,NULL
invoke ExitProcess,0
section '.idata' import data readable writeable
library kernel32,'kernel32.dll'
import kernel32,\
GetStdHandle,'GetStdHandle',\
ExitProcess,'ExitProcess',\
SetConsoleMode,'SetConsoleMode',\
ReadConsoleA,'ReadConsoleA',\
WriteConsoleA,'WriteConsoleA'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment