Merge pull request #345 from fruel/master

Added Win32 and Win64 ASM Hello World
This commit is contained in:
Mike Donaghy
2017-02-12 16:18:36 -06:00
committed by GitHub
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
; ---------------------------------------------
; Hello World for Win32 Intel x86 Assembly
;
; by fruel (https://github.com/fruel)
; 13 June 2016
; ---------------------------------------------
.386
.model flat,stdcall
.stack 4096
EXTRN ExitProcess@4 : PROC
EXTRN GetStdHandle@4 : PROC
EXTRN WriteConsoleA@20 : PROC
.data
msg BYTE "Hello World!",0
bytesWritten DWORD ?
.code
main PROC
push -11 ; nStdHandle (STD_OUTPUT_HANDLE)
call GetStdHandle@4
push 0 ; lpReserved
push OFFSET bytesWritten ; lpNumberOfCharsWritten
push LENGTHOF msg - 1 ; nNumberOfCharsToWrite
push OFFSET msg ; *lpBuffer
push eax ; hConsoleOutput
call WriteConsoleA@20
push 0 ; uExitCode
call ExitProcess@4
main ENDP
END main

View File

@@ -0,0 +1,33 @@
; ---------------------------------------------
; Hello World for Win64 Intel x64 Assembly
;
; by fruel (https://github.com/fruel)
; 13 June 2016
; ---------------------------------------------
GetStdHandle PROTO
ExitProcess PROTO
WriteConsoleA PROTO
.data
msg BYTE "Hello World!",0
bytesWritten DWORD ?
.code
main PROC
sub rsp, 5 * 8 ; reserve shadow space
mov rcx, -11 ; nStdHandle (STD_OUTPUT_HANDLE)
call GetStdHandle
mov rcx, rax ; hConsoleOutput
lea rdx, msg ; *lpBuffer
mov r8, LENGTHOF msg - 1 ; nNumberOfCharsToWrite
lea r9, bytesWritten ; lpNumberOfCharsWritten
mov QWORD PTR [rsp + 4 * SIZEOF QWORD], 0 ; lpReserved
call WriteConsoleA
mov rcx, 0 ; uExitCode
call ExitProcess
main ENDP
END