Advertisement
Guest User

NASM - x32Bit - Windows

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