user1165418
user1165418

Reputation: 37

Interrupt Handlers in Operating System

What is the reason behind writing at least a part of interrupt handlers in assembly language?

Upvotes: 3

Views: 2878

Answers (2)

jumper
jumper

Reputation: 300

The interrupt handler always start executing in a very low level envrionment. Programming languages but assembly always needs system libraries and something called "runtime".

For example, it is not easy to manipulate the stack pointer register outside assembly languages.

In addition, the ABI also a barrier. The Application Binary Interface is too complex in the interrupt handling, especially for the context saving and restoring.

Upvotes: 2

Carl Norum
Carl Norum

Reputation: 224844

Usually you have to write at least some part of an interrupt routine in assembly. That's because in a lot of cases, an interrupt simply causes the processor to vector to some specific memory location and start executing code from that point.

Since your processor probably doesn't obey the calling convention of whatever higher-level lanugage you're using, you need to write some assembly code to fix that up, call some higher-level interrupt handling code, and then some more assembly code to clear the interrupt and return the system to normal execution. On an Intel chip, for example, you need to make the processor execute an iret instruction to return from the interrupt. There's no way to do that in any standard way in any high-level language.

Upvotes: 1

Related Questions