Advertisement
Batisk_AFF

Dz1

Apr 18th, 2021
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Template for console application
  2.          .586
  3.          .MODEL  flat, stdcall
  4.          OPTION CASEMAP:NONE
  5.  
  6. Include kernel32.inc
  7. Include masm32.inc
  8.  
  9. IncludeLib kernel32.lib
  10. IncludeLib masm32.lib
  11.  
  12.          .CONST        
  13. MsgExit  DB         13, 10, "Press Enter to Exit", 0
  14. LenWords DB         13, 10, "Words length: ", 0
  15. NumWords DB         13, 10, "Words number: ", 0
  16. space    DB         " ", 0 ;" "
  17. endl     DB         13, 10, 0
  18. n        DWORD      32
  19.  
  20.          .DATA
  21.  
  22.          .DATA?
  23. inbuf    DB         100 DUP (?)
  24. resstr   DB         33  DUP (?)
  25. string   DB         33  DUP (?)
  26.  
  27.          .CODE
  28.          
  29. in_str proc near  ; inpput string procedure
  30.     Invoke StdIn, ADDR string, LengthOf string ; string input
  31.     Invoke StripLF, ADDR string  ; "1337\n" -> "13370"
  32.    
  33.     ret
  34.  
  35. in_str endp
  36.  
  37. Start:             ; TEST: abcd efgh alala xDD lul a bc de
  38.  
  39. call in_str   ; string input
  40. Invoke StdOut,ADDR LenWords  ; const for pretty output
  41.  
  42. XOR EDX, EDX  ; word letters counter
  43. XOR EBX, EBX  ; words counter
  44. XOR ECX, ECX  ; loop counter
  45. XOR EAX, EAX  ; stores char to find in repne
  46.  
  47. lea EDI, string  ; string.address -> EDI
  48. mov ECX, n       ; ECX - counter for repne
  49. mov AL, ' ' ;space    ; ' ' -> AL,    AL <=> flag for repne
  50. scan_word:
  51.     mov EDX, ECX ; EDX <=> length of not checked part of string
  52.    
  53.     push EDX     ; save EDX to stack (probably used by repne, but we use it too)
  54.     repne scasb  ; (za)loop, after it (EDX-ECX-1) == length of checked word
  55.     pop EDX      ; get our EDX
  56.     sub EDX, ECX ; EDX -= ECX
  57.     dec EDX      ; --EDX (word letters counter)
  58.     inc EBX      ; ++EBX (words counter)
  59.    
  60.     push EAX     ; saving EAX && ECX values
  61.     push ECX     ; (probably used by output, but we use them too)
  62.     Invoke dwtoa,EDX,ADDR resstr ; word letters number to string
  63.     Invoke StdOut,ADDR resstr    ; word letters number output
  64.     Invoke StdOut,ADDR space     ; cout << " ";
  65.     pop ECX      ; getting our ECX && EAX
  66.     pop EAX
  67.    
  68.     jecxz scan_end  ; jump to end of scan if ECX == 0 (if we reached the end of string)
  69.     jmp scan_word   ; else loop back to next word
  70.  
  71. scan_end:
  72.     Invoke StdOut,ADDR NumWords  ; const for pretty output
  73.     Invoke dwtoa,EBX,ADDR resstr ; words number to string
  74.     Invoke StdOut,ADDR resstr    ; words number output
  75.     Invoke StdOut,ADDR endl      ; cout << endl;
  76.    
  77. prog_end:
  78.      XOR    EAX,EAX
  79.      Invoke StdOut,ADDR MsgExit
  80.      Invoke StdIn,ADDR inbuf,LengthOf inbuf    
  81.  
  82.      Invoke ExitProcess,0
  83.      End    Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement