This is the source code with a boot menu and can be tested with qemu emulator.
I need to use the Sonet 3.5 artificial inteligence to search infos and make this source code better, but I learn assembly in the past.
The compile commands of the source code:
mythcat@localhost:~/fasm$ ./fasm.x64
flat assembler version 1.73.32
...
mythcat@localhost:~/fasm$ ./fasm.x64 bootloader.asm bootloader.bin
flat assembler version 1.73.32 (16384 kilobytes memory, x64)
2 passes, 512 bytes.
The test with qemu tool:
mythcat@localhost:~/fasm$ qemu-system-x86_64 -drive format=raw,file=bootloader.bin
Let's see the source code:
; Simple Bootloader with Menu for QEMU
; Written in FASM
org 0x7C00
format binary
start:
; Clear the screen
xor ax, ax
mov ds, ax
mov es, ax
mov ah, 0x0
int 0x10
; Display the menu
call display_menu
main_loop:
; Wait for key press
call wait_for_input
; Check key pressed
cmp al, '1'
je handle_option1
cmp al, '2'
je handle_option2
; Invalid option, restart
jmp main_loop
handle_option1:
; Option 1 selected
mov si, option1_msg
call display_message
call wait_for_input ; Wait for any key
jmp start ; Return to menu
handle_option2:
; Option 2 selected
mov si, option2_msg
call display_message
call wait_for_input ; Wait for any key
jmp start ; Return to menu
display_menu:
; Display the menu
mov si, menu
call print_string
ret
wait_for_input:
; Wait for a key press
xor ax, ax
int 0x16
ret
print_string:
; Print string at DS:SI
mov ah, 0x0E
@@:
lodsb
test al, al
jz @f
int 0x10
jmp @b
@@:
ret
display_message:
; Print message at DS:SI
call print_string
ret
menu db 'Simple Bootloader Menu', 13, 10
db '1. Option 1', 13, 10
db '2. Option 2', 13, 10
db 'Select an option: ', 0
option1_msg db 13, 10, 'You selected Option 1!', 13, 10
db 'Press any key to return to menu...', 13, 10, 0
option2_msg db 13, 10, 'You selected Option 2!', 13, 10
db 'Press any key to return to menu...', 13, 10, 0
rb 510-($-$$)
db 0x55, 0xAA
This is the result: