handler is called only with "int 0" not with "int i = 5/0"

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
matan
Posts: 13
Joined: Sat May 02, 2015 4:15 am
Libera.chat IRC: matan

handler is called only with "int 0" not with "int i = 5/0"

Post by matan »

i'm writing my kernel in C++ and i got the GDT and IDT working and when i tested the 0 interrupt with "int 0" right after the "lidt" , it works just fine and my handler is called , but when i write "int i = 5/0;" in C++ , nothing happens.

what's the problem ? i thought the CPU automatically does "int 0" when trying to divide by zero.
Unsigned
Posts: 24
Joined: Thu Sep 20, 2012 6:46 pm

Re: handler is called only with "int 0" not with "int i = 5/

Post by Unsigned »

I had the same problem, it's because the optimizer.
Do this instead:

Code: Select all

volatile int i=5;
volatile int j=0;
i=i/j;
What the optimizer is doing is trying to calculate the result of the operation and assign the correct value. Since it's not possible to divide by 0, nothing is done.
For example, if you do this:

Code: Select all

int i=100/4;
No 100 and no 4 will be part of the executable. Instead, the optimizer will convert it to this:

Code: Select all

int i=25;
And the i variable may or may not be modified. For example: if it's going to be used only once, it's value will only be in some register while calculating it, and it may not be saved anywhere.
Post Reply