There is interrupt what is shut down computer:
shutdown:
mov ax, 0x1000
mov ax, ss
mov sp, 0xf000
mov ax, 0x5307
mov bx, 0x0001
mov cx, 0x0003
int 0x15
ret ;if interrupt doesnt work
Why are manipulations for register A and selector SS? I tried to remove first three lines and it anyway works.
First, mov ax, ss
seems to be a typo and probably should be mov ss, ax
. Then these three instructions set the stack pointer to 1000:f000
.
You need to have a stack set up, with ss:sp
pointing to memory that can be safely written, before invoking the software interrupt. Otherwise, where do the return address and flags get pushed? And the interrupt handler itself may be expecting to have a certain amount of stack space available (I don't know whether the BIOS is guaranteed to switch stacks).
So that's presumably what those lines are meant to accomplish. Perhaps the shutdown
subroutine is jumped to from somewhere that doesn't necessarily have a valid stack, or the programmer just wasn't willing to rely on the caller's stack being valid. If the code worked without these lines in your tests, presumably it's because you were calling it with a stack that was already valid.