entry start
include 'A:\Assembler\include\win32a.inc'
section '.idata' import data readable
library kernel, 'kernel32.dll', \
` msvcrt, 'msvcrt.dll'
import kernel, \
ExitProcess, 'ExitProcess'
import msvcrt, \
printf, 'printf', \
gets,'gets',\
strlen,'strlen', \
getchar, '_fgetchar', \
scanf,'scanf'
section '.data' data readable writeable
MESSAGE db "Enter string %d",13,10,0
RESULT_1 db "Contains from %d",13,10,0
RESULT_2 db "Doesn't contain",13,10,0
BUF_STR_1 db 250 dup(0)
BUF_STR_2 db 250 dup(0)
LEN_1 dd 0
LEN_2 dd 0
POS dd 0
LEN_SUB dd 0
section '.code' code readable executable
start:
ccall [printf], MESSAGE, dword 1
ccall [gets], BUF_STR_1
ccall [printf], MESSAGE, dword 2
ccall [gets], BUF_STR_2
ccall [strlen], BUF_STR_1
mov [LEN_1], eax
ccall [strlen], BUF_STR_2
mov [LEN_2], eax
mov ecx, 0
mov esi, BUF_STR_2
get_substring_length:
lodsb
or al, al
jz end_substring_length
inc ecx
jmp get_substring_length
end_substring_length:
mov [LEN_SUB], ecx
mov edi, BUF_STR_1
search_substring:
mov eax, [LEN_1]
dec eax
std
mov esi, BUF_STR_2
mov ecx, [LEN_SUB]
repne scasb
jne substring_not_found
mov ebx, [LEN_SUB]
add eax, ebx
mov [POS], eax
jmp substring_found
substring_not_found:
mov [POS], -1
substring_found:
cmp [POS], -1
jne substring_found_output
ccall [printf], RESULT_2
jmp end_program
substring_found_output:
ccall [printf], RESULT_1, [POS]
end_program:
ccall [getchar]
ccall [ExitProcess], 0
```[![что получается в итоге][1]][1]
[1]: https://i.stack.imgur.com/7hETZ.png