Your problem is that you initialize the shift register to zero within the subroutine, meaning it will get reset with every iteration of the FOR loop.
You need to put the shift register on the border of the for loop. However, you can use straight "wire math" to do the entire thing much more efficiently and without any loops and formula nodes. See attached rough modification (please verify correct operation, I have not fully debugged it).