
STACKADDR: word 0F000           ; beginning of stack area
STR1:      word 0E000
STR2:      word 0E100

;****************************************************************************

; LIBRARY FUNCTIONS

#include "gets.ixx"
#include "puts.ixx"
#include "writenum.ixx"

;****************************************************************************

; MAIN PROGRAM

START:     LDWA R15 STACKADDR   ; stack initialization
           SPWR R15             ; NOTE: every function receives input
                                ;       values/addresses in R1, R2, ...
                                ;       and provides output in R0

           LDWA R1 STR1
           CALL GETS

           LDWA R1 STR2
           CALL GETS

           LDWA R1 STR1
           LDWA R2 STR2
           CALL RECURSIVE_STRCMP
           MV R0 R1
           CALL WRITENUM
           HLT

;****************************************************************************


; int recursive_strcmp (char *s, char *t)
; {
;    if (*s != *t)
;       return 0;
;    else if (*s == '\0')
;       return 1;
;    else
;       return recursive_strcmp (s+1, t+1);
; }


RECURSIVE_STRCMP:  LDBR  R11 R1              
                   LDBR  R12 R2              
                   SUB R11 R12
                   JMPZ REC_CMP_L1
                   LDWI R0 0
                   RET

REC_CMP_L1:        MV  R11 R13
                   JMPNZ REC_CMP_L2
                   LDWI R0 1
                   RET

REC_CMP_L2:        INC R1
                   INC R2
                   CALL RECURSIVE_STRCMP
                   RET   ; semplicemente restituisce il valore a sua volta 
                         ; restituito dalla chiamata recursiva

