I'm trying to write simple assembly program, which takes 2 strings from command line and then counts occurrences of first one in the second one.
For example: x="abc" y="abcabc abc". It should print 3.
I can't compile this code, because of too many memory references for 'cmp'.
I think that problem is between //here. How can I solved it?
.intel_syntax noprefix
.global main
.text
main:
mov eax, [esp+4]
cmp eax, 3
je fun
mov eax, offset error
push eax
call printf
add esp, 4
mov eax, 0
ret
fun:
mov eax, [esp+8]
mov ebx, [esp+12]
xor ecx,ecx
push edx
call loop
loop_z:
xor edx,edx
loop:
inc ecx
cmp byte ptr [eax+ecx-2],0
je end
cmp byte ptr [ebx+edx-1],0
je zer
jump:
//here
cmp byte ptr [eax+ecx-2],[ebx+edx-1]
//here
jne loop_z
inc edx
jmp loop
zer:
pop edx
inc edx
push edx
xor edx,edx
jmp jump
end:
call printf
add esp, 4
mov eax, 0
ret
.data
error:
.asciz " 2 arg \n"