Your university will have an office that deals with the transfer of intellectual property. You need to talk to them.
You need to research your agreement as a student with your university. In many cases, the University is the assignee of your intellectual property. This doesn't mean that you are not the developer, and that you're not entitled to any proceeds/licensing fees/etc. that might result. It means that your share might be predetermined by agreement, and you might not have any say as to what the university does with the intellectual property.
My suspicion is that it's likely that your adviser is not entitled to use your code without some licensing agreement with the university, though the university might choose to issue him that license at no charge as part of their spin-off agreement.
I'm not sure if your agreement with the university allows you to just pick up an algorithm that you developed as a student and use it. You might need to license it from the university as well-- in which case, your interest involve making sure that any licensing agreement between the university and your mentor is a NON EXCLUSIVE license.
I am not a lawyer. If this is valuable stuff, I suggest you hire one. In any case, I strongly recommend that all this stuff gets hashed out ASAP, for the benefit of you, your mentor, and the university. For all concerned, this needs to be bulletproof, and the software will need to be able to hold up to a licensing audit. Nobody would like a lawyer to come in and shut down a business with a cease and desist.
If you used significant non-university resources to develop the algorithm (i.e., your own computer, a compiler you paid for, etc.) you should make a list of this and keep it handy.
This is tricky. I suspect that if things go as routine, the university and your mentor's company might not make this bulletproof, leaving them open to legal action on your part. Just by bringing it up, you might force them to cover their bases, and hurt your own interests. Once again, if this is valuable, you need to hire a lawyer, and I suggest you do it BEFORE approaching the university.