the program i have written is distributed in two files where members of the files are declared global and used in the other program..i have posted both of them..
;main program
global str1,str2, length1, length2, ptr1, ptr2,count1,count2
extern concat, substring
%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, %2
syscall
%endmacro
SECTION .data
msg1: db "Enter first string : "
len1: equ $-msg1
msg2: db "Enter second string : "
len2: equ $-msg2
SECTION .bss
str1: resb 7
str2: resb 7
ptr1: resb 7
ptr2: resb 7
length1: resb 3
length2: resb 3
count1 : resb 3
count2 : resb 3
SECTION .text
global_start:
_start:
print msg1,len1
accept str1,7
mov [length1],rax
sub byte[length1],01
mov rbx,[str1]
mov [ptr1],rbx
print msg2,len2
accept str2,7
mov [length2],rax
sub byte[length2],01
mov rbx,[str2]
mov [ptr2],rbx
call concat
call substring
mov rax, 60
mov rdi,0
syscall
;
;subordinate program
global str3, concat, substring
extern str1,str2,length1,length2,ptr1, ptr2,count1,count2
%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx,%2
syscall
%endmacro
SECTION .data
msg3: db "Length of substring should be less than the main string. "
len3: equ $-msg3
msg4: db "substring occurence : "
len4: equ $-msg4
SECTION .bss
str3 : resb 16
count : resb 3
SECTION .text
global_start:
_start:
concat:
mov rsi,str1
mov rdi, str3
mov bl,[length1]
mov byte[count1],bl
loop1:
movsb
dec byte[count1]
cmp byte[count1],00h
jne loop1
mov rsi,str2
mov bl,[length2]
mov byte[count1],bl
loop2:
movsb
dec byte[count1]
cmp byte[count1],00h
jne loop2
print str3, 16
ret
substring:
mov al,length1
mov bl,length2
mov byte[count1],length1
mov byte[count2],length2
;mov byte[count1],al
;mov byte[count2],bl
mov bl,byte[count1]
mov cl,byte[count2]
cmp cl,bl
jg loop3
mov byte[count],00h
mov al,[ptr1]
;mov di,[ptr2]
compare:
cmp rax,[ptr2]
jne loop4
inc rax
inc byte[ptr2]
dec byte[count1]
dec byte[count2]
cmp byte[count2],00h
jne compare
mov rbx,[str2]
mov [ptr2],rbx
mov byte[count2],al
sub byte[count],01h
inc byte[count]
inc byte[ptr1]
jmp loop4
loop3:
print msg3,len3
loop4:
dec byte[count1]
cmp byte[count1],00h
jne compare
mov bl,byte[count]
call convascii
print msg4,len4
print count,3
ret
mov rax, 60
mov rdi,0
syscall
convascii:
mov rsi,count
mov rcx,10h
l3:
;rol rbx,04
mov al,bl
and al,0Fh
cmp al,09h
jbe add30
add al,07h
add30:
add al,30h
mov [rsi],al
;inc rsi
print rsi,3
;loop l3
ret
;
it is giving the above mentioned error for 'length 1' and 'length 2'