extern printf, scanf, strlen
section .data
format db "%1000s", 0
form_print db "%d", 0
form_skip db "%c", 0
section .bss
str1 resb 1001
str2 resb 1001
len1 resd 1
len2 resd 1
ind resd 1
l resd 1
section .text
global main
main:
push ebp
mov ebp, esp
sub esp, 8
push str1
push format
call scanf
add esp, 16
sub esp, 12
push str1
call strlen
add esp, 16
mov dword[len1], eax
sub esp, 8
push str2
push format
call scanf
add esp, 16
sub esp, 12
push str2
call strlen
add esp, 16
mov dword[len2], eax
mov eax, dword[len1]
cmp eax, dword[len2]
je .eqviv
jl .less
jmp .greater
.less: ; len1 < len2
mov dword[ind], 0
.search_first_simb:
mov ebx, dword[ind]
cmp ebx, dword[len2]
je .print0
mov eax, [str2 + 4*ebx]
mov ebx, [str1]
cmp eax, ebx
je .cmp_all_next ; по ind в str2 нач подстр
inc dword[ind]
jmp .search_first_simb
.cmp_all_next:
; ind - начало подстр str1 в str2
mov dword[l], 1 ; индекс в самой подстр str1 (нулевой симв уже совпал)
.next:
mov ebx, dword[ind]
mov eax, [str2 + 4*ebx]
mov ebx, dword[l]
mov ecx, [str1 + 4*ebx]
cmp eax, ecx
jne .search_first_simb
inc dword[ind]
inc dword[l]
mov eax, dword[l]
cmp eax, dword[len1]
je .print12
jmp .next
.greater: ; str1 > str2
mov dword[ind], 0
.find_first_simb:
mov ebx, dword[ind]
cmp ebx, dword[len1]
je .print0
mov eax, [str1 + 4*ebx]
mov ebx, [str2]
cmp eax, ebx
je .all_next ; по ind в str2 нач подстр
inc dword[ind]
jmp .find_first_simb
.all_next:
; ind - начало подстр str2 в str1
mov dword[l], 1 ; индекс в самой подстр str2 (нулевой симв уже совпал)
.nxt:
mov ebx, dword[ind]
mov eax, [str1 + 4*ebx]
mov ebx, dword[l]
mov ecx, [str2 + 4*ebx]
cmp eax, ecx
jne .find_first_simb
inc dword[ind]
inc dword[l]
mov eax, dword[l]
cmp eax, dword[len2]
je .print21
jmp .nxt
.eqviv:
mov eax, [str1]
mov ebx, [str2]
cmp eax, ebx
mov dword[ind], 1 ; чтобы l=ind=1 и исп
je .all_next
jmp .print0
.print0:
mov eax, 0
sub esp, 8
push eax
push form_print
call printf
add esp, 16
jmp .end
.print12:
mov eax, 1
sub esp, 8
push eax
push form_print
call printf
add esp, 16
mov eax, ' '
sub esp, 8
push eax
push form_skip
call printf
add esp, 16
mov eax, 2
sub esp, 8
push eax
push form_print
call printf
add esp, 16
jmp .end
.print21:
mov eax, 2
sub esp, 8
push eax
push form_print
call printf
add esp, 16
mov eax, ' '
sub esp, 8
push eax
push form_skip
call printf
add esp, 16
mov eax, 1
sub esp, 8
push eax
push form_print
call printf
add esp, 16
jmp .end
.end:
xor eax, eax
mov esp, ebp
pop ebp
ret