After I deleted all the blank lines and indented it, it looks like it probably would do as you envisage. However, as you have posted code without any indication of processor type I have no idea if your code is correct or not. It would also help if you indicated which compiler you are using.