I am trying to convert my C++ code to MASM code. I got trouble with 2D arrays.
Please help me!
Problem: Find the longest common substrings
My C++ code:
#include<stdio.h>
#include<string.h>
char s[20],t[20];
int b[20][20];
int n,m;
void substr(int i,int j) {
    if (i&&j) {
        if (b[i][j]==1) {
            substr(i-1,j-1);
            printf ("%c",s[i]);
        } else if (b[i][j]==2)
            substr(i-1,j);
        else substr(i,j-1);
    }
}
int main() {
    int f[20][20];
    gets(s+1);
    gets(t+1);
    m=strlen(s+1);
    n=strlen(t+1);
    for (int i=1; i<=m; i++)
        for (int j=1; j<=n; j++)
            if (s[i]==t[j]) {
                f[i][j]=f[i-1][j-1]+1;
                b[i][j]=1;
            } else {
                if (f[i-1][j]>=f[i][j-1]) {
                    f[i][j]=f[i-1][j];
                    b[i][j]=2;
                } else {
                    f[i][j]=f[i][j-1];
                    b[i][j]=3;
                }
            }
    printf("\n::: OUTPUT :::\n");
    if(n==0){
        printf("There is no common substring of S and T!");
    } else {
        printf("The longest substring: \"");
        substr(m,n);
        printf("\".");
    }
    return 0;
}
And my ASM code:
    .model small
; input s, m is lenght of s
    input macro s,m 
        push ax
        push dx                                  
        mov ah, 0Ah 
        lea dx, s
        int 21h                 
        mov al, s + 1 
        xor ah, ah
        mov m, ax
        pop ax
        pop dx     
    endM 
   
    substr macro i,j
        push ax
        push bx
        push cx
    if_s:
    loopij:
        cmp i,0
        jne halt
        cmp j,0
        jne halt
        if_2s:
            cmp b[i][j],1 
            jne else_if
            dec i
            dec j
            substr(i,j)
            lea dx, s[i]
            mov ah, 9
            int 21h
            jmp halt
         else_ifs:
             cmp b[i][j],2
             jne else
             dec i
             substr(i,j)
             jmp halt
          elses:          
             dec j
             substr(i,j)
             jump halt
        jmp loopij 
        ret       
     halt:
     pop ax
     pop bx
     pop cx
endm
.stack 100h
.data 
    newline db 10,13, "$"
    s db  255, ?, 255 dup(0)
    t db  255, ?, 255 dup(0)
    m dw ?
    n dw ?
    i dw ?
    j dw ?
    arr1 db i dup(0)
         db j dup (0)
    arr2 db i dup (0)
         db j dup (0)
.code  
main proc        
    mov  ax,@data
    mov  ds,ax
    input s, m
    call newln
    input t, n
    call newln
    xor ax, ax
    inc ax
    mov i, 2
loopi:
    add ax, m
    cmp i, ax
    ja outloopi
    mov j, 2
loopj:
    mov ax, 1
    add ax, n 
    cmp j, ax
    ja outloopj
    if_:
        mov dx, s[i]
        cmp dx, t[j]
        jne else
        mov cx, f[i-1][j-1]
        mov f[i-1][j-1], cx
        mov b[i][j],1
    else:
        else_if:
            cmp f[i-1][j], f[i][j-1]
            jb else_else
            mov cx,f[i-1][j] 
            mov f[i][j], cx
            mov b[i][j],2
        else_else:
            mov cx,f[i][j-1] 
            mov f[i][j], cx                
            mov b[i][j],3
    jmp loopj
outloopj:
    jmp loopi 
outloopi:       
    substr m, n
    mov  ax,4ch
    int  21h  
main endp
newln proc
    mov ah, 9
    lea dx, newline
    int 21h
    ret
newln endp
end main
How to declare a 2D array in ASM?
How to work with 2D arrays in ASM?
Can I convert 2D array into single dimension array in this case?
Thanks a lot!
 
    