1

I'm writing a simple OS in assembly but I can't figure out how to shutdown the computer.

I've tried to use hlt like this

 .shutdown:
   mov si, msg_shutdown
   call print_string
   hlt

but it doesn't work. I know that int 19h will restart the computer but is there an interrupt for shutdown?

I'll appreciate some help. Thanks.

Johnny Mnemonic
  • 3,822
  • 5
  • 21
  • 33

2 Answers2

1

hlt only halts the CPU until an interrupt occurs.

cli
hlt

may do what you want. You might also wish to disable NMIs, but I think if we get a NMI we're in big trouble anyway. You might also want to leave interrupts enabled, and reboot if the user hits "esc" or some such, otherwise back to hlt. If you actually want to shut the power off... mmm, that's more complicated...

Edit: Re-reading your question, I guess you do want to shut the power off(?). Look around here: http://wiki.osdev.org/Shutdown

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Frank Kotler
  • 3,079
  • 2
  • 14
  • 9
  • Usually you'd want to put `hlt` in a loop, especially if you leave interrupts enabled so ctrl+alt+del can still work. – Peter Cordes Oct 08 '22 at 17:53
-1

reboot :

reboot:
    jmp 0xffff:0000h

shutdown :

shutdown:
    mov ax, 5307h
    mov cx, 3
    mov bx, 1
    int 15h

halt :

halt:
    cli
    hlt
Adam
  • 33
  • 4