Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global _main
- bits 32
- section .data
- msg1 db "Enter string:", 0xa, 0
- msg1_blen equ $-msg1
- msg2 db "Enter substring:", 0xa, 0
- msg2_blen equ $-msg2
- section .bss
- string resb 255
- string_blen equ $-string
- string_len resb 10
- substring resd 255
- substring_len resb 10
- substring_blen equ $-substring
- mas resd 255
- i resb 1
- j resb 2
- section .text
- _main:
- ; arr test
- ; mov dword[mas + 4 * 0], 5
- ; mov dword[mas + 4 * 1], 9
- ; mov dword[mas + 4 * 2], 10
- ; write msg2
- ; sub esp, 4
- ; push dword msg2_blen
- ; push dword msg2
- ; push dword 1
- ; call sys_write
- ; add esp, 16
- ; read substring
- push dword substring_blen
- push dword substring
- push dword 1
- call sys_read
- add esp, 16
- ; save substring len
- dec eax
- mov [substring_len], eax
- mov eax, 0
- ; определяем первый элемент массива, i, j
- mov dword[mas + 4 * 0], 0
- mov dword[ebp-4], 1 ;i=1
- mov dword[ebp-8], 0 ;j=0
- ; for ($i = 1, $j = 0; $i < $m; $i++)
- for:
- ; $i < $m (+)
- mov ebx, dword[ebp-4]
- cmp ebx, [substring_len]
- jnl for_end
- ; while($j > 0 && $substr[$j] != $substr[$i])
- while:
- ; определяем адрес $substr[$j]
- mov ebx, substring
- mov ecx, dword[ebp-8]
- cmp dword[ebp-8], 0
- mov ebx, 0
- jne inc_address
- mov eax, ebx ; сохраняем адрес в eax
- ; определяем адрес $substr[$i]
- mov ebx, substring
- mov ecx, dword[ebp-4]
- jmp inc_address
- mov edx, ebx ; сохраняем адрес в edx
- ; $substr[$j] != $substr[$i]
- cmp eax, edx
- je if
- ; $j > 0
- mov ebx, dword[ebp-8]
- cmp ebx, 0
- jng if
- ; $j = $d[$j - 1];
- dec ebx
- mov ebx, dword[mas + ebx]
- mov dword[ebp-8], ebx
- jmp while
- if:
- ; определяем адрес $substr[$j]
- mov ebx, substring
- mov ecx, dword[ebp-8]
- cmp dword[ebp-8], 0
- mov ebx, 0
- jne inc_address
- mov eax, ebx ; сохраняем адрес в eax
- ; определяем адрес $substr[$i]
- mov ebx, substring
- mov ecx, dword[ebp-4]
- jmp inc_address
- mov edx, ebx ; сохраняем адрес в edx
- cmp eax, edx
- jne appropriation
- ; $d[$i] = $j;
- appropriation:
- mov ebx, dword[ebp-4]
- mov ecx, dword[ebp-8]
- mov dword[mas + ebx], ecx
- ; увеличить i
- inc ebx
- mov dword[ebp-4], ebx
- jmp for
- ; выход из for
- for_end:
- jmp sys_exit
- sys_write:
- pop ebx ; save link on next segment
- mov eax, 0x4 ; sys_write
- sub esp, 4 ; change head of stack
- int 0x80 ; interrupt
- push ebx ; push link on next segment to stack
- ret
- sys_read:
- pop ebx ; save link on next segment
- mov eax, 0x3
- sub esp, 4
- int 0x80
- push ebx ; push link on next segment to stack
- ret
- inc_address:
- inc ebx
- loop inc_address
- ret
- sys_exit:
- push dword 0 ; status
- mov eax, 0x1 ; sys_exit
- sub esp, 4 ; change head of stack
- int 0x80 ; interrupt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement