enea wrote
in
Pseudocode a[123]= 0
ASM
@123
D=A
@a
A=D+A   / why this and not A=D?
M=0
 
A=D would set A = 123, so the code would set RAM[123] = 0 instead of a[123] = 0.
    @123
    D=A     // D = 123
    @a      // A = address of array 'a', element 0
    A=D+A   // Update A to address of 'a' element 123
    M=0     // Set a[123] to 0
enea wrote
Pseudocode a[123]= 17
ASM
@123
D=A
@a
A=D+A   
@17
D=A
@a
M=D
is it correct?
 
    A=D+A   // Update A to address of 'a' element 123
    @17     // Sets A = 17, overwriting the A just set.
    D=A
    @a
    M=D     // Sets a[0] = 17
Setting a[123] to an arbitrary value is a bit tricky.
You need to compute the address of a[123] and save it in a temporary variable in RAM, for instance R15.
Then load 17 into D.
Reload the temporary variable into A, and
finally set a[123] to D.
--Mark