Ali Hussein
Ali Hussein

Reputation: 321

How to HLT the program without using HLT

How I can stop executing the program without HLT Written at the end of the code I have read that HLT can occur on there interrupt but I couldn't understand how

Upvotes: 0

Views: 715

Answers (1)

The HLT instruction does not actually terminate the program. As far as I can tell, its main use is putting the CPU in "idle" mode to reduce power consumption. But that only lasts until the next interrupt fires, then program execution will continue.

You should probably do a system call (a call into your OS), either to tell the OS to terminate your process, or to "yield" the processor (letting the OS HLT it for you in an appropriate fashion).

How exactly system calls work and which one you need depends on the OS your program is running on. On DOS, there's e.g. INT 21h (MOV AH, 4Ch; INT 21h will terminate your program IIRC), for Linux, look up "syscalls").

If you want to truly halt program execution, i.e. intentionally hang the computer, you can either:

  • enter into an infinite loop (here: JMP here), or
  • disable (maskable) interrupts using CLI, followed by HLT.

The second option might be more power efficient, however both are equally non-user friendly and probably somewhat pointless. :)

(Disclaimer: I haven't been doing system-level programming in a while, the above information might be a little rough around the edges.)

Upvotes: 1

Related Questions