I've managed to write an assembly code that works for most of my memory segments but the issue is @i and @addr. They get mapped to r16 and r17 but to my understanding, this is wrong since those registers are reserved for static variables.
The assembler doesn't "know" anything about static variables. It translates assembly language programs to machine language. The HACK assembler has this convention, that unknown labels will be treated as variables and will be assigned to addresses from 16 onward. That's why i and addr are mapped to mem and mem.
Then there is the VM translator, which generates HACK assembly from a bunch of .vm files. One of its features is handling class-level or static fields. It does that by using the free variable mechanism of the HACK assembler. That is, it just uses the ClassName.fieldName in the assembly code and lets the HACK assembly handle this.
A different compiler may use the same mechanism differently. Or it may just skip it outright and just handle the address assignments by itself.
I'm not entirely sure what you're trying to achieve as a whole but I can see some of the problems. Cadet1620 wrote an excellent Introduction to Hack Assembly Language. Read it and try again with a simpler task. For example, the code fragment
seems to try to put in the register D the address of the ith local variable, but it's not doing that correctly. Try to fix it on your own.
(Hint: do you know the value of i at compile time?)