Page 1 of 1

Why use jmp $ to halt the system?

Posted: Sat Sep 01, 2007 1:20 pm
by neon
Hey everyone,

I have a question out of complete curiosity :D

I have seen alot of code use an infinity loop to "halt" execution. My question is "why"?

i.e., why not use HLT or a combination of CLI and HLT?

Is it just personal preference?

Using CLI in combination with HLT will completely halt the system, and is more efficient then a jmp $ instruction.

Using HLT alone halts the processor, but still allows execution of interrupts (Which can restart the processor, when needed)

Is there any specific reason?

Just curious,

Thanks :D

Posted: Sat Sep 01, 2007 1:37 pm
by frank
For some reason I just feel that a hlt is not as final as jmp $. But I usually use

Code: Select all

loop:
hlt
jmp loop:
in my code.

Posted: Sat Sep 01, 2007 2:10 pm
by Dex
I uses the same as frank, if not it will run at near 100% in single-tasking OS.
You can find lots of case of why do coders do this and that, eg: in Pmode why do coders do pusha and popa, instead of pushad or popad ?.

Posted: Sat Sep 01, 2007 4:33 pm
by Combuster
even CLI + HLT can still be restarted (with an NMI, that is) An infinite loop can't be passed over in such a fashion. The reason to use a halt-loop construct is to conserve energy.

If you really want to lock up the computer, try to trigger the F00F bug :twisted:

Posted: Sat Sep 01, 2007 6:28 pm
by neon
Combuster wrote:even CLI + HLT can still be restarted (with an NMI, that is) An infinite loop can't be passed over in such a fashion. The reason to use a halt-loop construct is to conserve energy.

If you really want to lock up the computer, try to trigger the F00F bug :twisted:
lol--I just might do that! :evil: :D

You are correct about the NMIs though--I did not think of that. :)