ON ERROR:ON ERROR OFF:PRINT REPORT$;" at ";ERL:END

DIM A$(10,20)

FOR X%=0 TO 10
  FOR Y%=0 TO 20
    A$(X%,Y%) = "This is element ("+STR$X%+","+STR$Y%+")" + CHR$0
  NEXT
NEXT

DIM code% 1024
FOR pass% = 0 TO 2 STEP 2
    P% = code%
[   OPT  pass%

.test
    STMFD    R13!,{0-12,14}

    LDMIA    R9!,{0,1}  ; addr and type of Y
    LDR      R8,[R0]

    LDMIA    R9!,{0,1}  ; addr and type of X
    LDR      R7,[R0]

    LDMIA    R9!,{0,1}  ; addr and type of A$()

    ;-- it seems an array is defined to be a pointer to a structure, so
    ;   we must follow R0 to the real structure. (Although in this case
    ;   it just points to the following word..

    LDR      R0,[R0]

    ;-- R0 now points to the base of the array structure. It contains:
    ;   +0   11     size of 1st dimension
    ;   +4   21     size of 2nd dimension
    ;   +8   0
    ;   +12  231    total number of elements
    ;   +16..       the string pointers
    ;               each string is pointerword (byte aligned) + length byte

    LDMIA    R0!,{1,2}
    ADD      R0,R0,#2*4  ; R0 is now at +16

    ;-- Find address of our entry

    MLA      R1, R7,R2, R8  ; R1 = x_entry * y_size + y_entry
    ADD      R1,R1,R1,LSL#2 ; R1 = entryno * 5
    ADD      R1,R1,R0       ; R1 = address of stringptr + lengthbyte

    ;-- Get byte-aligned word

    LDRB     R0,[R1],#1
    LDRB     R14,[R1],#1 : ORR R0,R0,R14,LSL#8
    LDRB     R14,[R1],#1 : ORR R0,R0,R14,LSL#16
    LDRB     R14,[R1],#1 : ORR R0,R0,R14,LSL#24

    ;-- get length byte

    LDRB     R1,[R1]

    ;-- display it

    SWI      "OS_WriteN"

    LDMFD    R13!,{0-12,PC}^

]
NEXT

X%=3
Y%=4

CALL test,A$(),X%,Y%