While in Phd I developed a lot of code that I want to turn into start-up. Can I do this? I was working 3 years on a project, that I came up with on my own, worked on my own, published 2 papers on it. I want to drop out of Phd (or take leave) and do start up at this point using my code. 

Can I do it? Or because I developed this code while doing my Phd it cannot be used for commercial purposes?

EDIT: I am in US, top university for CS.
I'm not aware of any blanket prohibition, anywhere, that say that you can't use code developed during a PhD for a commercial venture - but most Universities in the US will have some kind of intellectual property agreement in place to state what the process is for doing this.

You will need to check with officials at your University to see what agreements you are subject to - but you should go a step farther than this. Specifically, you should see what departments might exist that can actually help you.

In the US at least - and I'm sure many other institutions around the world - there are departments specializing in intellectual property, "knowledge transfer", corporate spin-offs, start-ups, entrepreneurship, etc. These can be a rich source of support and networking, if they are available to you, even if you have intellectual property agreements that assign various rights to the University. 

Universities want to earn money for these projects, as I'm sure you do as well, and 100% of $0 is $0. Universities often heavily facilitate the process of converting this work into money, and it is not abnormal for even a place that has heavily restricted intellectual rights assignments agreements to assign use rights and royalty agreements that have zero cost for the first $200,000+ US dollars in income. There are often even startup grants available, accelerators (even if they are not called that - places that provide space and equipment to help starting businesses), introductions to investors, showcases, and more. You won't know until you ask and look for them, as where they are located tends to vary heavily by institution. 

For the exact nature of the agreements that apply to you, we can't say; I've seen everything from "the student owns their own work" to "anyone funded assigns all rights and ownership to the University", and I'm sure there are agreements everywhere in between. You are right to check them out in advance of a major decision, but this is so specific that you'll need to talk with multiple people are your specific institution to see what applies to you. You may also need to speak with an outside legal professional (lawyer experienced in this area, etc) to verify, but your local administrators are your best first point of contact to see how things work.