Simple Boot Loader in Assembly
Terminal Commands:
nasm boot1.asm -f bin -o boot1.bin
dd if=boot1.bin bs=512 of=myhd.img
qemu myhd.img
Help for boot1.asm:
'INT 0x10' is a BIOS video interrupt. All video related calls are made through this interrupt.
To use this interrupt, we need to set the values of some registers as follows.
AL => With ASCII value of character to display
AH => With 0x0E ;
Teletype mode (This will tell bios that we want to print one character on screen)
BL => With Text Attribute (This will be the fore ground and background color
of character to be displayed. 0x07 in our case.)
BH => With Page Number (0x00 for most of the cases)
Once all the registers are filled with appropriate values, we can call interrupt.
Implementation in Assembly
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7c00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
mov si, HelloString
call PrintString
jmp $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
mov ah, 0x0E ;Tell BIOS that we need to print one charater on screen.
mov bh, 0x00 ;Page no.
mov bl, 0x07 ;0x07 is lightgrey font on black background
int 0x10 ;Call video interrupt
ret ;Return to calling procedure
PrintString:
next_character:
mov al, [si]
inc si
or al, al
jz exit_function
call PrintCharacter
jmp next_character
exit_function:
ret
HelloString db 'Nice Work Dude......................',0
times 510-($-$$) db 0 ;Fill the rest of sector with 0
dw 0xAA55 ;Add boot signature at the end of bootloader
nasm boot1.asm -f bin -o boot1.bin
dd if=boot1.bin bs=512 of=myhd.img
qemu myhd.img
Help for boot1.asm:
'INT 0x10' is a BIOS video interrupt. All video related calls are made through this interrupt.
To use this interrupt, we need to set the values of some registers as follows.
AL => With ASCII value of character to display
AH => With 0x0E ;
Teletype mode (This will tell bios that we want to print one character on screen)
BL => With Text Attribute (This will be the fore ground and background color
of character to be displayed. 0x07 in our case.)
BH => With Page Number (0x00 for most of the cases)
Once all the registers are filled with appropriate values, we can call interrupt.
Implementation in Assembly
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7c00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
mov si, HelloString
call PrintString
jmp $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
mov ah, 0x0E ;Tell BIOS that we need to print one charater on screen.
mov bh, 0x00 ;Page no.
mov bl, 0x07 ;0x07 is lightgrey font on black background
int 0x10 ;Call video interrupt
ret ;Return to calling procedure
PrintString:
next_character:
mov al, [si]
inc si
or al, al
jz exit_function
call PrintCharacter
jmp next_character
exit_function:
ret
HelloString db 'Nice Work Dude......................',0
times 510-($-$$) db 0 ;Fill the rest of sector with 0
dw 0xAA55 ;Add boot signature at the end of bootloader
Comments
Post a Comment