1 00:00:00,490 --> 00:00:02,320 Continue with the divide by zero handler. 2 00:00:03,190 --> 00:00:09,970 As you can see we have added push and pop instructions. What the push instructions do is saving the state of cpu 3 00:00:09,970 --> 00:00:13,120 when interrupt or exception occurs. 4 00:00:13,930 --> 00:00:21,060 When that happens, only some of registers are saved, such as rip and rsp registers. 5 00:00:21,070 --> 00:00:25,570 In the handler, we will use and modify registers to perform specific tasks. 6 00:00:26,560 --> 00:00:32,140 Therefore when we return from the handler, the value of registers may have changed 7 00:00:32,140 --> 00:00:36,260 of CPU is not the same as it was before the entropic and the state of cpu is not the same as it was before the interrupt occurs. 8 00:00:36,760 --> 00:00:42,430 So in order to restore the state of cpu after the interrupt handling is done, we store all the general purpose registers 9 00:00:42,430 --> 00:00:44,080 on the stack. 10 00:00:44,980 --> 00:00:52,030 In 64-bit mode, we have 16 general purpose registers. Rsp is pushed on the stack 11 00:00:52,030 --> 00:00:53,650 when cpu calls the handler, 12 00:00:53,770 --> 00:00:56,080 So here we push 15 registers. 13 00:00:58,290 --> 00:01:04,440 After we handle the interrupt, we pop the original value in those registers and return. 14 00:01:06,200 --> 00:01:11,980 Stack is like a last-in first-out structure. So we pop the value on the stack in reverse order. 15 00:01:13,420 --> 00:01:19,390 Ok now, if the interrupt is fired, the handler will save all the general purpose registers first, 16 00:01:20,510 --> 00:01:27,230 do its work and then pop the value on the stack back to those registers. 17 00:01:27,230 --> 00:01:32,500 When we return from the handler, the previous work CPU is doing is resumed just like the interrupt never happened. 18 00:01:34,430 --> 00:01:40,840 As you see, when divided by zero handler is called, we just stop here. So we don’t test the code in this lecture 19 00:01:40,850 --> 00:01:41,480 . 20 00:01:42,760 --> 00:01:47,790 In next video, we will discuss the timer interrupt and test it in that example. 21 00:01:49,340 --> 00:01:50,750 That's it for this lecture. 22 00:01:50,780 --> 00:01:52,040 See you in the next video.