【发布时间】:2019-05-21 19:25:59
【问题描述】:
我正在开发一个程序集引导加载程序。我需要帮助来获取用户的输入。我使用这样的代码在屏幕上打印(start)。在getInput 中,我试图从用户那里获取输入,但没有成功。那么,我该怎么做呢?
org 0x7C00
BITS 16
start:
cli ; Disable interrupts
mov si, bootMsg1 ; Point SI to message
mov ah, 0x0E ; Indicate BIOS we're going to print chars
.loop lodsb ; Loads SI to AL
or al,al ; Checks if the end of string
jz seperate
or al,al
jz halt ; Jump to halt at the end
int 0x10 ; Otherwise, call interrupt for printing the char
jmp .loop ; Next iteration of loop
...
getInput:
cli
mov ah, 08 ; Indicate BIOS to get input
int 21h
mov ah,02
mov DL,AL
int 21h
MOV AH,4Ch ; Function to exit
MOV AL,00 ; Return 00
INT 21h
halt: hlt ; CPU command to halt the execution
bootMsg1: db "Slight Bootloader 1, Welcome!",13,10 ; Message
bootMsg2: db"------------",13,10
【问题讨论】:
-
Int 21h 是 DOS 中断,只有在运行 DOS 时才可用。在引导加载程序中,您仅限于 BIOS 中断。请参阅Ralf Brown's Interrupt List 了解更好的方法。
-
如果你是汇编新手,可能更容易开始编写 DOS 程序,因为 API 更丰富,环境限制更少。
标签: assembly operating-system kernel boot