how to write the interrupt instruction in assembly language and what the diferrent between subroutine and interrupt in assembly language??
anybody can help me??

Dani AI

Generated

and outlined the basic difference between interrupts and subroutines. The notes below add concrete, x86-focused details that are often missing: exact instruction syntax, what the CPU saves automatically, the correct return instruction, a minimal handler skeleton, and where handlers live in real mode vs protected/OS-managed systems.

Invoking a software interrupt on x86 uses the int instruction with an 8‑bit vector: int 0xNN. On entry the CPU pushes processor state (FLAGS, CS, and IP/EIP/RIP); some exception vectors also push an error code. If the trap crosses privilege levels the CPU switches stacks using the TSS. Handlers must restore the saved state and return with iret (or iretd/iretq in 32/64‑bit), not ret. Example of a software interrupt invocation (historical example used by some 32‑bit Linux code):

mov eax, 1
int 0x80

A minimal real‑mode interrupt service routine (ISR) skeleton preserves registers, does work, and finishes with iret:

my_isr:
    pusha
    pushf
    ; --- handler work here ---
    popf
    popa
    iret

Installation notes and pitfalls: in real mode the IVT lives at physical address 0x0000; vector N is stored at byte offset 4*N as offset (word) then segment (word). In protected mode the IDT and gate descriptors control which software interrupts user code may invoke (DPL checks). Under modern OSes, ISRs and IRQ handlers belong in kernel/driver code and should be registered through the OS API rather than patching tables directly. Always follow the ABI/OS expectations for preserved registers, interrupt masking, and concurrency (per‑CPU/locking) when writing handlers.

Recommended Answers

All 3 Replies

how to write the interrupt instruction in assembly language and what the diferrent between subroutine and interrupt in assembly language??
anybody can help me??

Interrupts occur due to events, e.g. a timer overflow, or a change of state of a hardware input to the microprocessor. Typically through your software code, interrupts can be enabled or disabled, i.e. when a specific event occurs the running code will be "interrupted" and the interrupt code will execute. One typically doe NOT call an interrupt routine. When done, the interrupt returns further processing (e.g. through a RETR statement which re-enables the interrupt) to the main program from where it went off.

Subroutines are pieces of code that perform a certain function, and which are called by the main program whenever that function is required. So you have to CALL the subroutine. E.g. a subroutine to count the number of occurences of a string in a file.
When done, the subroutine returns processing (e.g. through a RET statement) to the main program.

Clear ?

Best regards,

Hans

In 32-bit protected mode, interrupts are used as exception handlers, like what Athelas said. They are essentially handled exclusively by the operating system and the hardware. And in 32-bit pmode, you can't call an interrupt from your program (unless your program is the kernel or a driver.)

In 16-bit real mode, interrupts can be called by any program and in older operating systems (like DOS) they were used when a program wanted to communicate with the kernel. For example, int 21h was often used for I/O in DOS.

Hello Iklila, for which platform / processor are you coding your assembly program ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.