Iterating over an array in..

.. Hack Assembly Language!

arr.asm
// for(int i = 0; i < 10; i ++) {
//     arr[i] = -1;
// }
 
@25
D = A
@array
M = D
 
@10
D = A
@arrayLength
M = D
 
// set counter to 0
@0
D = A
@counter
M = D
 
(LOOP)
// if (arrayLength - counter == 0) jump to END
    @counter
    D = M
    @arrayLength
    D = D - M
    @END
    D;JEQ
 
// else 
    //set R[array + counter] = -1 ..
    @array
    D = M
    @counter
    D = D + M
    A = D
    M = -1
    // .. increment counter
    @counter
    M = M + 1
 
    // jump back to LOOP
    @LOOP
    0;JMP
 
(END)
@END
0;JMP