Advertisement
kamasazi99

asm lab 7, 2 zad

Dec 4th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .386
  2. .Model Flat,stdcall
  3. ;stale
  4. GENERIC_READ equ 80000000h
  5. GENERIC_WRITE equ 40000000h
  6. CREATE_NEW equ 1
  7. CREATE_ALWAYS equ 2
  8. OPEN_EXISTING equ 3
  9. OPEN_ALWAYS equ 4
  10.  
  11.  
  12. ;plik
  13. CloseHandle PROTO:DWORD
  14. CreateFileA PROTO:DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
  15. WriteFile PROTO:DWORD, :DWORD, :DWORD, :DWORD, :DWORD
  16.  
  17. ;normal
  18. GetStdHandle PROTO:DWORD
  19. ReadConsoleA PROTO:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
  20. ExitProcess PROTO:DWORD
  21.  
  22. ;random
  23. GetTickCount PROTO
  24. nseed PROTO:DWORD
  25. nrandom PROTO:DWORD
  26. includelib masm32.lib
  27. .data
  28. ;plik
  29. handle_ZAMKNIECIE DWORD 0
  30. path byte "MyFile.txt",0
  31. handle_plik DWORD 0
  32. zapisane DWORD ?
  33. ;normal
  34. odczyt DWORD 0
  35. varRange DWORD 0
  36. znaki DWORD 0
  37. tabRandom byte 20 dup(0)
  38. pomoc byte 0
  39.  
  40. .code
  41. main proc
  42.  
  43. Invoke GetStdHandle,-10
  44. mov odczyt,eax
  45.  
  46. invoke ReadConsoleA,odczyt,offset varRange,13,offset znaki,0
  47.  
  48. mov ebx, offset varRange
  49. add ebx,znaki
  50. mov [ebx-2],BYTE PTR 0
  51. push offset varRange
  52. call atoi
  53. mov varRange,eax ;zamiana RANGE na normalna liczbe
  54.  
  55. invoke GetTickCount
  56. invoke nseed,eax
  57. mov ebx,0
  58. mov ecx,10
  59. petla:
  60. push ecx
  61. invoke nrandom,varRange
  62.  
  63. add al,48
  64.  
  65. mov tabRandom[ebx],al
  66. add ebx,1
  67. mov tabRandom[ebx],0Ah
  68. add ebx,1
  69. pop ecx
  70. LOOP petla
  71.  
  72. ;plik teraz
  73.  
  74. INVOKE CreateFileA , OFFSET path , GENERIC_READ OR GENERIC_WRITE, 0 , 0 ,CREATE_ALWAYS, 0 , 0
  75. mov handle_plik,eax
  76.  
  77.  
  78.  
  79. invoke WriteFile, handle_plik,offset tabRandom, lengthof tabRandom, offset zapisane,0
  80.  
  81.  
  82.  
  83.  
  84.  
  85. invoke CloseHandle, handle_plik
  86.  
  87. invoke ExitProcess,0
  88.  
  89. main endp
  90.  
  91. atoi proc uses esi edx inputBuffAddr:DWORD
  92.     mov esi, inputBuffAddr
  93.     xor edx, edx
  94.     xor EAX, EAX
  95.     mov AL, BYTE PTR [esi]
  96.     cmp eax, 2dh
  97.     je parseNegative
  98.  
  99.     .Repeat
  100.         lodsb
  101.         .Break .if !eax
  102.         imul edx, edx, 10
  103.         sub eax, "0"
  104.         add edx, eax
  105.     .Until 0
  106.     mov EAX, EDX
  107.     jmp endatoi
  108.  
  109.     parseNegative:
  110.     inc esi
  111.     .Repeat
  112.         lodsb
  113.         .Break .if !eax
  114.         imul edx, edx, 10
  115.         sub eax, "0"
  116.         add edx, eax
  117.     .Until 0
  118.  
  119.     xor EAX,EAX
  120.     sub EAX, EDX
  121.     jmp endatoi
  122.  
  123.     endatoi:
  124.     ret
  125. atoi endp
  126. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement