Advertisement
jakubs11

lab assembler 17-01-2014

Jan 20th, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ;Flat Assembler
  3.  
  4. format PE console
  5. entry start
  6.  
  7. include 'C:\Users\Student\Documents\dos\8086\FASM\INCLUDE\win32a.inc'
  8.  
  9. section '.text' code executable
  10.  
  11. start:
  12.         push hello
  13.         call [printf]
  14.         pop ecx
  15.  
  16.         push 0
  17.         call [ExitProcess]
  18.  
  19. section '.rdata' data readable
  20.         hello db 'Hello world!', 10, 0
  21.  
  22. section '.idata' data readable import
  23.         library kernel32, 'kernel32.dll', \
  24.                 msvcrt, 'msvcrt.dll'
  25.         import kernel32, ExitProcess, 'ExitProcess'
  26.         import msvcrt, printf, 'printf'    
  27.  
  28. ////////////////////////////////////////////////////////////////////////////
  29.  
  30.  
  31. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  32.  
  33. .code
  34.         start:
  35.                 invoke AllocConsole
  36.                 invoke WriteConsole, <invoke GetStdHandle, STD_OUTPUT_HANDLE>,tex,12,dummy,0
  37.                 invoke Sleep,-1
  38.                 invoke ExitProcess,0
  39. .end start
  40.  
  41. .data
  42. tex     TCHAR   'Hello Wordl!'
  43. dummy   rd      1      
  44.  
  45.  
  46. //////////////////////////////////////////////////////////////////////////// ODCZYT PLIKU
  47.  
  48. format pe console 4.0
  49. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  50.  
  51. .data
  52.         FileTitle db 'qwerty.txt',0
  53.         hFile dd ?
  54.         nSize dd ?
  55.         lpBytesRead dd ?
  56.         lpBuffer rb 8192
  57.  
  58.         MessageBoxCaption db 'Output:',0
  59.  
  60. .code
  61.         main:
  62.         invoke CreateFile, FileTitle, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ; open the file
  63.  
  64.         mov [hFile], eax ;Save the file's handle to hFile
  65.         invoke GetFileSize, [hFile], 0    ; Determine the file size
  66.  
  67.         mov [nSize], eax ; Save the file size given by EAX
  68.         invoke ReadFile, [hFile], lpBuffer, [nSize], lpBytesRead, 0     ;now read the full file
  69.  
  70.         invoke CloseHandle, [hFile] ;   Handle should be close after the file has been read
  71.         invoke MessageBox, NULL, addr lpBuffer, addr MessageBoxCaption, MB_OK   ;easy way of outputing the text
  72.         invoke ExitProcess,0
  73.  
  74. .end main
  75.  
  76.  
  77.  
  78. ////////////////////////////////////////////////////////////////////////////
  79.  
  80. format pe console 4.0
  81. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  82.  
  83. .data
  84.      buf db 'plik testowy'
  85.      bufsize = $ - buf      ;zczytywanie dlugosci stringa
  86.      byteswritten dd ?
  87.  
  88. .code
  89.         main:
  90.         invoke CreateFile, 'test.txt', GENERIC_WRITE, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0
  91.         invoke WriteFile, eax, buf, bufsize, byteswritten, 0
  92.         invoke ExitProcess, 0
  93.  
  94.  
  95. .end main
  96.  
  97.  
  98. ////////////////////////////////////////////////////////////////////////////
  99.  
  100.  
  101.  
  102. format pe console 4.0
  103. entry start
  104.  
  105. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  106.  
  107. ;;;;
  108. section '.code' code readable executable
  109. ;;;;
  110.  
  111. start:
  112.         invoke Beep, 750, 300
  113.         ccall [getchar]
  114.         stdcall [ExitProcess], 0
  115.  
  116. section '.idata' import data readable
  117.  
  118.  
  119. library  kernel, 'kernel32.dll',\
  120.          msvcrt, 'msvcrt.dll'
  121.  
  122. import kernel, \
  123.        Beep, 'Beep',\
  124.        ExitProcess, 'ExitProcess'
  125.  
  126.  
  127. ; symbol \ oznacz przedluzenie linii
  128.  
  129. import msvcrt, \
  130.        getchar, '_fgetchar'          
  131.  
  132.  
  133. ////////////////////////////////////////////////////////////////////////////
  134.  
  135. ;WYWOLANIE FUNKCJI MESSAGEBOX
  136.  
  137. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  138.  
  139. .data
  140.         tekst_w_oknie db '      Program w assemblerze pod WINDOWS       ',0
  141.         tekst_okna    db '      Okienko w asemblerze  ',0
  142.         wynik dd 0
  143.  
  144. .code
  145.         start:
  146.                 push MB_ICONQUESTION+MB_DEFBUTTON1
  147.                 push tekst_w_oknie
  148.                 push tekst_okna
  149.                 push 0
  150.                 call [MessageBoxA]
  151.  
  152.                 invoke MessageBox, HWND_DESKTOP,'Test drugi', 'DRUGIE OKNO', MB_RETRYCANCEL+MB_ICONEXCLAMATION+MB_RIGHT
  153.  
  154.  
  155.         koniec:
  156.                 invoke ExitProcess,0
  157.  
  158. .end start
  159.  
  160.  
  161. ////////////////////////////////////////////////////////////////////////////
  162.  
  163. include 'c:\users\student\documents\dos\include\win32wxp.inc'
  164.  
  165.  
  166. .data
  167.         MsgBoxCaption   db      'An example of cancel, retry, continue',0
  168.         MsgBoxText      db      'hello message box!',0
  169.  
  170. .code
  171.         start:
  172.                 invoke MessageBox, HWND_DESKTOP, 'hello message box!' , 'An example of cancel, retry, continue',MB_ICONERROR OR MB_ABORTRETRYIGNORE OR MB_ICONWARNING
  173.  
  174.                 .if eax = IDABORT
  175.                ;abort was pressed
  176.                     invoke MessageBox, HWND_DESKTOP, 'ABORT', 'WIN ABORT', MB_OK
  177.  
  178.                 .elseif eax=IDRETRY
  179.                        ;retry was pressed
  180.                                 invoke MessageBox, HWND_DESKTOP, 'RETRY', 'WIN RETRY', MB_OK
  181.  
  182.                 .elseif eax = IDCANCEL
  183.                        ;cancel was pressed
  184.  
  185.                 .endif
  186.  
  187.                 invoke ExitProcess,0
  188.  
  189.         .end start      
  190.  
  191.  
  192. ////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement