如何关闭机器?我正在构建自己的小型操作系统
汇编中的 hlt 指令可以像停止处理器一样关闭计算机吗?如果可以使用我所说的来完成,这是正确的方法吗?
能不能关掉机器?
start:
xor ax, ax; ;clear ax
mov bx, ax; ;clear bx
cli ;stop all interrupts
hlt ;halt the cpu
如果这不是正确的方法,如果这不会关闭系统,请告诉我正确的方法。
Can the hlt instruction in assembly shutdown a computer it as it halts the processor? if it can be done using what i have told, is it the right way?
Can hlt shutdown the machine?
start:
xor ax, ax; ;clear ax
mov bx, ax; ;clear bx
cli ;stop all interrupts
hlt ;halt the cpu
If this is not the way to be done of if this will not shutdown the system please tell me the right way to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
hlt
指令停止 x86,直到发生中断。除非禁用所有中断,否则处理器只会停止一毫秒左右。要关闭现代计算机的电源,请使用ACPI(高级配置和电源接口)。
The
hlt
instruction stops the x86 until an interrupt occurs. Unless all interrupts are disabled, that will stop the processor for only a millisecond or so.To power down a modern computer, use the ACPI (Advanced Configuration and Power Interface).
停止指令不会关闭电源。
它将处理器置于非执行状态。
通常,您可以在处理器重置时退出暂停状态。
在某些微控制器中,特定中断还可以使处理器脱离暂停状态。
关闭电源是主板/BIOS 特定操作。
halt instruction does not turn off the power.
it puts the processor into a non-executing state.
usually, you can come out of the halt state upon processor reset.
in some microcontrollers, specific interrupts can also bring the processor out of the halt state.
power off is a motherboard/bios specific operation.
通过使用这两行代码:
您可以停止 x86 pc 的可启动程序:
将其另存为“prog.asm”,然后使用“nasm”创建启动扇区:
现在您可以使用“qemu”来测试它:
注意:删除上面提到的这两行会导致虚拟机使用最大可用 CPU 周期。
编辑:添加了“cld”指令。正如 Michael 所提到的,有必要确保 text_string 是从左到右加载的。
By using these two lines of code:
you could halt a bootable program for x86 pc:
Save it as "prog.asm", then use "nasm" to create boot sector:
Now you could use "qemu" to test it:
Note: Removing those two lines mentioned above, causes your virtual machine to use maximum cpu cycles available.
Edit: Added "cld" instruction. As mentioned by Michael, it was necessary to make sure text_string is loaded from left-to-right.