Advertisement
tolikpunkoff

helloc2.asm

May 29th, 2022
3,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Console helloworld v 2.0
  2. ; Assembler: MASM32
  3. ; Compiling: G:\masm32\bin\ml.exe /c /coff helloc2.asm
  4. ; Linking: G:\masm32\bin\link.exe helloc2.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. extern  _ReadConsoleA@20:near
  13.  
  14. includelib kernel32.lib
  15.  
  16. .data
  17.     message db  'Hello, world!',0Dh,0Ah,0Dh,0Ah
  18.     handle  dd  ?
  19.     written dd  ?  
  20.    
  21.     msgexit db  'Press ENTER to exit...'
  22.    
  23.     hInput  dd  ?
  24.     readed  dd  ?
  25.     readbuf db  ?
  26.        
  27.     STD_INPUT_HANDLE    dd  -10
  28.     STD_OUTPUT_HANDLE   dd  -11
  29.     STD_ERROR_HANDLE    dd  -12
  30.    
  31. .code
  32. _main:
  33.     ;get StdOut handle
  34.     push    STD_OUTPUT_HANDLE
  35.     call    _GetStdHandle@4
  36.     cmp     eax,0
  37.     jle     exiterr             ; exit if error in GetStdHandle (return -1) or no console (return 0)
  38.     mov     handle, eax
  39.    
  40.     push    0                   ;reserved
  41.     push    offset written      ;number of chars written
  42.     push    17                  ;number of chars to write
  43.     push    offset message      ;output string
  44.     push    handle              ;handle StdOutput
  45.     call    _WriteConsoleA@20  
  46.    
  47.     ;write exit message
  48.     push    0                   ;reserved
  49.     push    offset written      ;number of chars written
  50.     push    22                  ;number of chars to write
  51.     push    offset msgexit      ;output string
  52.     push    handle              ;handle StdOutput
  53.     call    _WriteConsoleA@20
  54.    
  55.     ;read user input
  56.     ;get StdIn handle
  57.     push    STD_INPUT_HANDLE
  58.     call    _GetStdHandle@4
  59.     cmp     eax,0
  60.     jle     exiterr             ; exit if error in GetStdHandle (return -1) or no console (return 0)
  61.     mov     hInput, eax
  62.    
  63.     ;ReadConsole
  64.     push    0                   ;READ_CONSOLE_CONTROL structure
  65.     push    offset readed       ;number of readed chars
  66.     push    0                   ;number of chars to read
  67.     push    offset readbuf      ;readed chars buffer
  68.     push    hInput              ;Input handle
  69.     call    _ReadConsoleA@20
  70.    
  71.     jmp     exit
  72.    
  73. exiterr:
  74.     push    1
  75.     call    _ExitProcess@4
  76.  
  77. exit:
  78.     push    0
  79.     call    _ExitProcess@4
  80. end _main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement