如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)


問題描述

如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)

如何在沒有 HLT 的情況下停止執行程序寫在我讀過的代碼的末尾,HLT 可以在那裡發生中斷,但我不明白是怎麼回事


參考解法

方法 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.)

(by Ali Husseinstakx ‑ no longer contributing)

參考文件

  1. How to HLT the program without using HLT (CC BY‑SA 2.5/3.0/4.0)

#emu8086






相關問題

使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')

emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)

為什麼這個彙編代碼不刪除擴展名為“.lnk”的文件? (Why doesn't this assembly code delete the file with ".lnk" extension?)

將 C 代碼轉換為 8086 程序集 (Converting C code into 8086 assembly)

循環無法打印字母 (Loop does not work to print alphabets)

如何使用 call 和 ret 更改堆棧內容? (how to change stack content with call and ret?)

彙編語言中的putch函數通過堆棧 (putch function in assembly language through stack)

如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)

使用 8086 彙編計算 10 的階乘 (Computing the factorial of 10 using 8086 assembly)

你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)

在彙編語言中得到錯誤的結果 (Getting wrong result in Assembly language)

我的氣泡代碼是彙編語言嗎? (is my code for bubble right at assembly language?)







留言討論