【问题标题】:How can I get user input in my assembly bootloader?如何在我的程序集引导加载程序中获取用户输入?
【发布时间】: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


【解决方案1】:

使用Int 16h/AH=00h
一些输出为Int 21h/AH=08h

Int 16h has input utilities, Int 10h has output (video) utilities.


示例。
等待用户按键,然后“重启”。

BITS 16

xor ax, ax
int 16h

int 19h

TIMES 510 - ($-$$) db 0
dw 0aa55h

【讨论】:

  • 没有用,怎么办?什么也没发生。你能给我举个例子吗?
  • 注意:我使用 VirtualBox o 测试并且我用访客捕获了键盘/鼠标(所以引导加载程序)
  • @BurakYeniçeri 请参阅更新的答案以获取最小示例。用 VirtualBox 测试。请记住正确设置您的引导环境,该示例仅用于演示int 16h/ah=00h 的工作原理。
  • 我需要另一件事。我需要获取用户按下了哪个键。如何将其作为字符串值获取?
  • @BurakYeniçeri int 16h/ah=00hax 中返回密钥的扫描码及其根据 bios 键盘布局的 ASCII 转换。如果你搜索这个网站,你会发现很多例子。
猜你喜欢
  • 1970-01-01
  • 2014-06-09
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多