Advertisement
tolikpunkoff

helloc1.asm

May 28th, 2022
3,703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Console helloworld v 1.0
  2. ; Assembler: MASM32
  3. ; Compiling: G:\masm32\bin\ml.exe /c /coff helloc1.asm
  4. ; Linking: G:\masm32\bin\link.exe helloc1.obj  /SUBSYSTEM:CONSOLE /LIBPATH:G:\masm32\lib\
  5.  
  6. .386
  7. .model flat
  8.  
  9. extern  _ExitProcess@4:near
  10. extern  _GetStdHandle@4:near
  11. extern  _WriteConsoleA@20:near
  12.  
  13. includelib kernel32.lib
  14.  
  15. .data
  16.     message db  'Hello, world!',0Dh,0Ah
  17.     handle  dd  ?
  18.     written dd  ?
  19.    
  20.     STD_INPUT_HANDLE    equ -10
  21.     STD_OUTPUT_HANDLE   equ -11
  22.     STD_ERROR_HANDLE    equ -12
  23.    
  24. .code
  25. _main:
  26.     ;get StdOut handle
  27.     push    STD_OUTPUT_HANDLE
  28.     call    _GetStdHandle@4
  29.     cmp     eax,0
  30.     jle     exiterr             ; exit if error in GetStdHandle (return -1) or no console (return 0)
  31.     mov     handle, eax
  32.    
  33.     push    0                   ;reserved
  34.     push    offset written      ;number of chars written
  35.     push    15                  ;number of chars to write
  36.     push    offset message      ;output string
  37.     push    handle              ;handle StdOutput
  38.     call    _WriteConsoleA@20
  39.     jmp     exit
  40.    
  41. exiterr:
  42.     push    1
  43.     call    _ExitProcess@4
  44.  
  45. exit:
  46.     push    0
  47.     call    _ExitProcess@4
  48. end _main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement