fix a bug in getReg() function