.text
.arm
.global _start
_start:
        b reset
        b loop
        b loop
        b loop
        b loop
        nop
        b loop
        b loop

/* ==============================
*  TEST CODE
*  ==============================
*/
reset:
        mov r1,#VECT1
        mov r2,#VECT2
        mov r9,#0 @ contador 
        
/* bucle principal 
* se recorre VEC1 hasta el final y por cada lectura, llama a la funcion comparar
*/ 
otro:
        ldrb r4,[r1],#1
        cmp r4,#0
        beq salir 
        bl comparar
        b otro

/* =========================================================
*  funcion comparar
*  compara las cadenas VEC1(comenzando desde la posicion 
*  apuntada por r1-1) y VEC2 hasta el final de VEC2
*  =========================================================*/
comparar: 
        sub r5,r1,#1  @ utiliza como puntero inicial de VEC1 la posicion anterior a r1 
        mov r6,r2     @ el puntero de VEC2 apunta al comienzo del mismo 
otracmp:
        ldrb r8,[r6],#1 @ lee VEC2

        cmp r8,#0        @ si VEC2 llega al final, incrementa r9 (son iguales ) y sale 
        addeq r9,r9,#1
        beq retorno

        ldrb r7,[r5],#1  @ lee VEC1 
        cmp r7,r8        
        beq otracmp      @ si son iguales compara siguiente, si son distintos sale
retorno: 
        mov pc,lr

salir: 
loop:   b loop

/* ==============================
*  CONTANTES
*  ==============================
*/
VECT1:  .asciz "esto es una prueba de palabras"
VECT2:  .asciz "es"
        .balign 4

        .end

