extern scanf, printf, strncmp, fgets, stdin
section .data
format_s db "%1000s", 0
format_p db "%d %d", 0
format_d db "%d", 0
i dd 0
i_max dd 0
j dd 0
j_max dd 0
section .bss
arr1 resb 1002
arr2 resb 1002
len1 resd 1
len2 resd 1
section .text
global main
main:
push ebp
mov ebp, esp
and esp, ~15
; fgets(arr1, 1002, stdin)
sub esp, 4
push stdin
push 1002
push arr1
call fgets
add esp, 16
; fgets(arr2, 1002, stdin)
sub esp, 4
push stdin
push 1002
push arr2
call fgets
add esp, 16
; for (len1 = 0; arr[len1] != '\0'; len1++)
loop_len1:
mov ecx, [len1]
cmp byte[arr1 + ecx], `\n`
jz loop_len2
add dword[len1], 1
jmp loop_len1
loop_len2:
mov ecx, [len2]
cmp byte[arr2 + ecx], `\n`
jz loop_len2_fin
add dword[len2], 1
jmp loop_len2
loop_len2_fin:
; for (int i = 0; i < len2 + 1 - len1; i++)
; strncmp (arr1, arr2 + i, len1)
mov eax, [len2]
mov dword[i_max], eax
inc dword[i_max]
mov eax, [len1]
sub dword[i_max], eax
loop1:
mov eax, [i]
cmp eax, [i_max]
jge loop1_end
; strncmp (arr1, arr2 + i, len1)
sub esp, 4
push dword[len1]
mov eax, arr2
add eax, [i]
push eax
push arr1
call strncmp
add esp, 16
cmp eax, 0
jz fin12
inc dword[i]
jmp loop1
loop1_end:
mov eax, dword[len1]
mov dword[j_max], eax
inc dword[j_max]
mov eax, [len2]
sub dword[j_max], eax
loop2:
mov eax, [j]
cmp eax, [j_max]
jge loop2_end
; strncmp (arr1 + j, arr2, len2)
sub esp, 4
push dword[len2]
push arr2
mov eax, arr1
add eax, [j]
push eax
call strncmp
add esp, 16
cmp eax, 0
jz fin21
inc dword[j]
jmp loop2
loop2_end:
; printf("%d", 0)
sub esp, 8
push 0
push format_d
call printf
add esp, 16
jmp finish
fin12:
; printf("%d %d, 1, 2);
sub esp, 4
push 2
push 1
push format_p
call printf
add esp, 16
jmp finish
fin21:
; printf("%d %d, 2, 1);
sub esp, 4
push 1
push 2
push format_p
call printf
add esp, 16
jmp finish
finish:
mov esp, ebp
pop ebp
xor eax, eax
ret