rewrite function getReg()