Sign up ×

a divide expression in my code is " a / b ". when it is compiled to assemble, there is a trap-testing instruction(teq in MIPS assemble) following the normal divide instruction.
will all compiler add this kind of trap instruction behind the normal divide instruction? I'm not familar with this situation. Thanks very much.

share|improve this question

1 Answer 1

Most compilers won't specify the results when you do a divide by zero. Since you didn't indicate what language or compiler you're using, it's impossible to be more specific than that.

P.S. Being able to read the assembly output from the compiler is a huge advantage in cases like this.

share|improve this answer
I use C++, gcc for MIPS. – Eric Mar 9 '11 at 3:33
I have read the assembly output from the compiler, I have seen a trap-testing instruction(teq in MIPS) behind the divide instruction. – Eric Mar 9 '11 at 3:37
@Eric, what I'm trying to say is that you can do the same thing with whichever compiler and processor architecture you need. C++ in particular does not specify the results of a divide by zero, you'll have to investigate your specific compiler. – Mark Ransom Mar 9 '11 at 4:00

Your Answer


