+ push ebp
+ mov ebp, esp
+ push ebx
+
+ mov ebx, [ebp + 8]
+ mov eax, GATE_TRAP
+ cmp ebx, 32 ; determine if it's an IRQ or an exception (trap)
+ jb .notirq
+ mov eax, GATE_INTR
+.notirq:
+ shl ebx, 1
+ lea ebx, [ebx * 8 + idt] ; ebx <- pointer to gate descriptor
+ ; type|dpl goes to the 3rd dword of the descriptor (dpl is 0)
+ or eax, (GATE_DEFAULT | GATE_PRESENT)
+ mov [ebx + 8], eax
+ ; address low 16bits go to the first dword of the descriptor
+ mov eax, [ebp + 12]
+ mov [ebx], ax
+ ; address high 16bits go to the last dword of the descriptor
+ shr eax, 16
+ mov [ebx + 12], eax
+ ; selector (kcode:1) goes to the second dword of the descriptor
+ mov dword [ebx + 4], 08h
+
+ pop ebx
+ pop ebp