Sunday, 19 April 2015

concatB

section .data
concatstrmsg db 'Concatenation of two strings is',10
conln equ $-concatstrmsg
occurstr db 'occurences of substrings is ',10
occurstrln equ $-occurstr

section .bss
concatstr resb 40
concatstrlnn: equ $-concatstr
cntr resb 1
dispnum resb 2
Extern mainstr,substr,mstrl,sbstrl       
%include "m.asm"                   
                                 
section .text
global _main
_main:
global concat,subcnt               
concat:xor rcx,rcx               
    mov cx,[mstrl]               
    mov rsi,mainstr                   
    mov rdi,concatstr               
    call l1   
    mov rsi,substr               
    mov cx,[sbstrl]               
    call l1
         disp concatstrmsg,conln       
    disp concatstr,concatstrlnn
    ret
   
    l1:
     mov al,[rsi]               
    mov [rdi],al               
    inc rsi                   
    inc rdi                   
    dec rcx                   
    jnz l1                   
    ret
                       
subcnt:
mov ebp,mainstr               
mov esi,mainstr               
mov edi,substr               
mov rcx,[sbstrl]               
xor rbx,rbx                   
mov bx,[mstrl]               
sub rbx,rcx                   
inc rbx                   
b1:cld                   
repe cmpsb                   
jne b2
inc byte[cntr]               
b2:inc ebp
mov esi,ebp               
mov edi,substr               
mov rcx,[sbstrl]
dec rbx
jnz b1
disp occurstr,occurstrln
mov rax,[cntr]               
call display8
ret


display8:mov rcx,2   
    mov rsi,dispnum+1       

L:    mov     rdx,0           
    mov     rbx,10       
    div     rbx
    cmp     dl, 09h       
    jbe      add30
    add      dl, 07h 

add30:
    add     dl,30h       
    mov     [rsi],dl       
dec     rsi               

    dec     rcx           
    jnz     L
    disp dispnum,2       
    ret

No comments:

Post a Comment