Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Print "Hello, World!" - Windows - x32bit ONLY - NASM
- ;nasm -fwin32 print.asm -o print.obj
- ;golink /console /entry WinMain print.obj kernel32.dll
- global WinMain ;Defines entrypoint as "WinMain"
- extern GetStdHandle, WriteConsoleA ;Imports GetStdHandle and WriteConsoleA from kernel32.dll
- STD_OUTPUT_HANDLE equ -11 ;Assigns value -11 to STD_OUTPUT_HANDLE
- NULL equ 0 ;Assigns value 0 to NULL
- section .data ;Defines constants/variables
- msg db "Hello World!", 13, 10, 0 ;Defines message in appropriate C format
- msg.len equ $ - msg ;Defines constant message length
- section .bss ;Defines bytes for optimisation
- dummyByte resd1 ;Assigns 4bytes to dummyByte
- section .text ;Define code
- push STD_OUTPUT_HANDLE ;Push STD_OUTPUT_HANDLE to stack
- call GetStdHandle ;Call GetStdHandle from kernel32.dll using 1st parameter in stack
- push NULL ;Push Null to stack
- push dummyByte ;Push the 4bytes to stack
- push msg.len ;Push msg.len (buffer) to stack
- push msg ;Push msg to stack
- push eax ;Push accumulator result from GetStdHandle
- call WriteConsoleA ;Calls the external function
- jmp $ ;Keeps console open after printing
- ;WriteConsoleA has parameters in the order of Null, dummyByte, msg.len, msg, GetStdHandle(eax)
- ;WriteConsoleA(eax, msg, msg.len, dummyByte, NULL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement