extern printf, strstr, strlen, fgets, stdin
section .bss
s1 resb 102 ; 100 символов + \0 + \n
s2 resb 102
section .data
my_str db "%s", 0
my_bracket_open db "[", 0
my_bracket_close db "]", 0
my_newline db `\n`, 0
section .text
global main
my_fgets: ; добавил fgets заместо scanf
push ebp
mov ebp, esp
push ebx
and esp, -16 ; добавил выравнивание по 16
mov ebx, [ebp + 8]
sub esp, 4
push dword [stdin]
push 102
push ebx
call fgets
add esp, 16
sub esp, 12
push ebx
call strlen
add esp, 16
test eax, eax
jz end_fgets
cmp byte [ebx + eax - 1], 10
jne end_fgets
mov byte [ebx + eax - 1], 0
end_fgets:
lea esp, [ebp - 4]
pop ebx
pop ebp
ret
printer:
push ebp
mov ebp, esp
push ebx
push esi
push edi
and esp, -16
mov esi, [ebp + 8]
mov edi, [ebp + 12]
mov ebx, [ebp + 16]
movzx eax, byte [ebx]
push eax
mov byte [ebx], 0
sub esp, 4
push esi
push my_str
call printf
add esp, 12
pop eax
mov byte [ebx], al
sub esp, 12
push my_bracket_open
call printf
add esp, 16
sub esp, 8
push edi
push my_str
call printf
add esp, 16
sub esp, 12
push my_bracket_close
call printf
add esp, 16
sub esp, 12
push edi
call strlen
add esp, 16
add ebx, eax
sub esp, 8
push ebx
push my_str
call printf
add esp, 16
sub esp, 12
push my_newline
call printf
add esp, 16
lea esp, [ebp - 12]
pop edi
pop esi
pop ebx
pop ebp
ret
main:
push ebp
mov ebp, esp
and esp, -16
sub esp, 12
push s1
call my_fgets
add esp, 16
sub esp, 12
push s2
call my_fgets
add esp, 16
sub esp, 8
push s1
push s2
call strstr
add esp, 16
test eax, eax
jz reverse_s1s2
sub esp, 4
push eax
push s1
push s2
call printer
add esp, 16
jmp finish
reverse_s1s2:
sub esp, 8
push s2
push s1
call strstr
add esp, 16
test eax, eax
jz nothing
sub esp, 4
push eax
push s2
push s1
call printer
add esp, 16
jmp finish
nothing:
sub esp, 8
push s1
push my_str
call printf
add esp, 16
sub esp, 12
push my_newline
call printf
add esp, 16
finish:
xor eax, eax
mov esp, ebp
pop ebp
ret