;---------------------------------------------------------------------
section .data
nline db 10,10
nline_len: equ $-nline
cmsg db 10,"The Concatenated String is : "
cmsg_len: equ $-cmsg
ymsg db 10,"The substring is Present.",10
db 10,"No. of occurences of substring : "
ymsg_len: equ $-ymsg
nmsg db 10,"The substring is not Present.",10
db 10,"No. of occurences of substring : "
nmsg_len: equ $-nmsg
;---------------------------------------------------------------------
section .bss
str3 resb 40
str3_len: equ $-str3
str3_size resw 1
sscount resw 1
cur_add resq 1
end_add resq 1
char_ans resb 4
;---------------------------------------------------------------------
extern str1,str1_size, str2, str2_size
global con_proc, sub_proc
%include "macro.asm"
;---------------------------------------------------------------------
section .text
global _main
_main:
; global con_proc, sub_proc
con_proc: ;STRING CONCATINATION PROCEDURE
cld
xor rcx,rcx
mov cx,[str1_size]
mov rsi, str1 ; 1st string
mov rdi, str3 ; concatenated string
rep movsb
xor rcx,rcx
mov cx,[str2_size]
mov rsi, str2 ; 2nd string
rep movsb
mov cx,[str1_size]
add cx,[str2_size]
mov [str3_size],cx
print cmsg,cmsg_len
print str3,str3_len
ret
;---------------------------------------------------------------------
sub_proc: ;substring procedure
mov rsi,str1
CLD
mov [cur_add],rsi ; store starting address of string1
mov rcx,rsi ; calculate end address of string1
add cx,[str1_size]
dec rcx
mov [end_add],rcx
back:
mov rdi,str2
xor rcx,rcx
mov cx,[str2_size]
repe cmpsb
jnz conti
inc word[sscount]
conti:
inc qword[cur_add]
mov rsi,[cur_add]
cmp rsi,[end_add]
jbe back
cmp word[sscount],00
je no
print ymsg, ymsg_len
jmp last
no: print nmsg, nmsg_len
last:
mov ax,[sscount]
call display_16
ret
;------------------------------------------------------------------
display_16:
mov rsi,char_ans+3 ; load last byte address of char_ans in rsi
mov rcx,4 ; number of digits
cnt: mov rdx,0 ; make rdx=0 (as in div instruction rdx:rax/rbx)
mov rbx,16 ; divisor=16 for hex
div rbx
cmp dl, 09h ; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add dl,30h ; calculate ASCII code
mov [rsi],dl ; store it in buffer
dec rsi ; point to one byte back
dec rcx ; decrement count
jnz cnt ; if not zero repeat
print char_ans,4 ; display result on screen
ret
;----------------------------------------------------------------
section .data
nline db 10,10
nline_len: equ $-nline
cmsg db 10,"The Concatenated String is : "
cmsg_len: equ $-cmsg
ymsg db 10,"The substring is Present.",10
db 10,"No. of occurences of substring : "
ymsg_len: equ $-ymsg
nmsg db 10,"The substring is not Present.",10
db 10,"No. of occurences of substring : "
nmsg_len: equ $-nmsg
;---------------------------------------------------------------------
section .bss
str3 resb 40
str3_len: equ $-str3
str3_size resw 1
sscount resw 1
cur_add resq 1
end_add resq 1
char_ans resb 4
;---------------------------------------------------------------------
extern str1,str1_size, str2, str2_size
global con_proc, sub_proc
%include "macro.asm"
;---------------------------------------------------------------------
section .text
global _main
_main:
; global con_proc, sub_proc
con_proc: ;STRING CONCATINATION PROCEDURE
cld
xor rcx,rcx
mov cx,[str1_size]
mov rsi, str1 ; 1st string
mov rdi, str3 ; concatenated string
rep movsb
xor rcx,rcx
mov cx,[str2_size]
mov rsi, str2 ; 2nd string
rep movsb
mov cx,[str1_size]
add cx,[str2_size]
mov [str3_size],cx
print cmsg,cmsg_len
print str3,str3_len
ret
;---------------------------------------------------------------------
sub_proc: ;substring procedure
mov rsi,str1
CLD
mov [cur_add],rsi ; store starting address of string1
mov rcx,rsi ; calculate end address of string1
add cx,[str1_size]
dec rcx
mov [end_add],rcx
back:
mov rdi,str2
xor rcx,rcx
mov cx,[str2_size]
repe cmpsb
jnz conti
inc word[sscount]
conti:
inc qword[cur_add]
mov rsi,[cur_add]
cmp rsi,[end_add]
jbe back
cmp word[sscount],00
je no
print ymsg, ymsg_len
jmp last
no: print nmsg, nmsg_len
last:
mov ax,[sscount]
call display_16
ret
;------------------------------------------------------------------
display_16:
mov rsi,char_ans+3 ; load last byte address of char_ans in rsi
mov rcx,4 ; number of digits
cnt: mov rdx,0 ; make rdx=0 (as in div instruction rdx:rax/rbx)
mov rbx,16 ; divisor=16 for hex
div rbx
cmp dl, 09h ; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add dl,30h ; calculate ASCII code
mov [rsi],dl ; store it in buffer
dec rsi ; point to one byte back
dec rcx ; decrement count
jnz cnt ; if not zero repeat
print char_ans,4 ; display result on screen
ret
;----------------------------------------------------------------
Blogger Comment
Facebook Comment