Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Template for console application
- .586
- .MODEL flat, stdcall
- OPTION CASEMAP:NONE
- Include kernel32.inc
- Include masm32.inc
- IncludeLib kernel32.lib
- IncludeLib masm32.lib
- .CONST
- MsgExit DB 13, 10, "Press Enter to Exit", 0
- LenWords DB 13, 10, "Words length: ", 0
- NumWords DB 13, 10, "Words number: ", 0
- space DB " ", 0 ;" "
- endl DB 13, 10, 0
- n DWORD 32
- .DATA
- .DATA?
- inbuf DB 100 DUP (?)
- resstr DB 33 DUP (?)
- string DB 33 DUP (?)
- .CODE
- in_str proc near ; inpput string procedure
- Invoke StdIn, ADDR string, LengthOf string ; string input
- Invoke StripLF, ADDR string ; "1337\n" -> "13370"
- ret
- in_str endp
- Start: ; TEST: abcd efgh alala xDD lul a bc de
- call in_str ; string input
- Invoke StdOut,ADDR LenWords ; const for pretty output
- XOR EDX, EDX ; word letters counter
- XOR EBX, EBX ; words counter
- XOR ECX, ECX ; loop counter
- XOR EAX, EAX ; stores char to find in repne
- lea EDI, string ; string.address -> EDI
- mov ECX, n ; ECX - counter for repne
- mov AL, ' ' ;space ; ' ' -> AL, AL <=> flag for repne
- scan_word:
- mov EDX, ECX ; EDX <=> length of not checked part of string
- push EDX ; save EDX to stack (probably used by repne, but we use it too)
- repne scasb ; (za)loop, after it (EDX-ECX-1) == length of checked word
- pop EDX ; get our EDX
- sub EDX, ECX ; EDX -= ECX
- dec EDX ; --EDX (word letters counter)
- inc EBX ; ++EBX (words counter)
- push EAX ; saving EAX && ECX values
- push ECX ; (probably used by output, but we use them too)
- Invoke dwtoa,EDX,ADDR resstr ; word letters number to string
- Invoke StdOut,ADDR resstr ; word letters number output
- Invoke StdOut,ADDR space ; cout << " ";
- pop ECX ; getting our ECX && EAX
- pop EAX
- jecxz scan_end ; jump to end of scan if ECX == 0 (if we reached the end of string)
- jmp scan_word ; else loop back to next word
- scan_end:
- Invoke StdOut,ADDR NumWords ; const for pretty output
- Invoke dwtoa,EBX,ADDR resstr ; words number to string
- Invoke StdOut,ADDR resstr ; words number output
- Invoke StdOut,ADDR endl ; cout << endl;
- prog_end:
- XOR EAX,EAX
- Invoke StdOut,ADDR MsgExit
- Invoke StdIn,ADDR inbuf,LengthOf inbuf
- Invoke ExitProcess,0
- End Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement