Search code examples
assemblyoperating-systemkernelboot

How can I get user input in my assembly bootloader?


I'm working on a assembly bootloader. I need help with getting input from the user. I use such code to print on the screen (in start). In getInput, I tried to get input from user but has not been worked. So, how could I do it?

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

Solution

  • Use Int 16h/AH=00h.
    Some output as Int 21h/AH=08h.

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


    Example.
    Wait for the user to press a key and then "reboot".

    BITS 16
    
    xor ax, ax
    int 16h
    
    int 19h
    
    TIMES 510 - ($-$$) db 0
    dw 0aa55h