@Sam,
imho the last formula is correct. But I suggest, that you should implement your project step for step:
1. first try the construct with a simple example (like Ref(Mov(C,2,S),-1)), so you can control immediately whether that's what you really want to do!
2. then try to test extending this...