Question

I'm currently working on building a simple OS from scratch , so i'm testing some boot sector code and i'm simulating it using Qemu.

My boot sector code is supposed to print 'A' when the OS boots.

Here is the first version of the boot sector code (with out using a function call)

[org 0x7c00]

mov al,'A'
mov ah,0x0e  ; int 10/ ah = 0eh -> scrolling teletype BIOS routine
int 0x10

jmp $

times 510 -( $ - $$ ) db 0
dw 0xaa55

after executing the binary file that nasm has produced using :

qemu-system-i386 test.bin

the outcome is correct and the character 'A' appears where it should be

but , after trying to make use of a function that prints a character stored in al , nothing is printed on the screen

here is the second version of the test.asm file (including the function call this time)

[org 0x7c00]

mov al,'A'

call my_print_function

jmp $

times 510 -( $ - $$ ) db 0
dw 0xaa55


my_print_function:
    pusha  ; push all registers

    ; same code as the first version to print a character stored in al
    mov ah,0x0e  
    int 0x10

    popa ; pop all registers
    ret

so why isn't it functioning correctly ?

Any help would be greatly appreciated.

Thanks

Was it helpful?

Solution

You must have the signature of the boot sector at its end. I'm talking about this part:

times 510 -( $ - $$ ) db 0
dw 0xaa55

Right now your my_print_function falls outside of the bootsector and isn't even loaded by the BIOS.

You need to move this function to before the signature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top