首页 > 解决方案 > BIOS Interrupt 0x10 Does Not Print/Display Anything

问题描述

I am trying to print a string using assembly (FASM) and the BIOS interrupt 0x10.
I declared the string, and used a loop to load the string character by character into memory and print the individual characters via int 0x10.

I tested my code in QEMU, but the string never got printed out. I tried to print only a single character and that did not work.

Here is the bootloader code boot.asm:

format COFF 
public _start

_start:

    org 0x7C00
    mov si, msg
    mov ah, 0x0E     ; Set interrupt code

    print:
        lodsb        ; Load the character
        or al, al    ; Check for 0x0
        jz hang
        int 0x10     ; Call interrupt
        jmp print


hang:
    jmp hang         ; Infinite loop

msg db 'This is a test sentence.', 0x0
times 510 - ($-$$) db 0
db 0xAA
db 0x55

Here is linker.ld:

ENTRY(_start);
SECTIONS
{
    . = 0x7C00;
    .text : AT(0x7C00)
    {
        _text = .;
        *(.text);
        _text_end = .;
    }
    .rodata :
    {
        *(.rodata)
    }

    .data :
    {
        *(.data)
    }

    .bss :
    {
        *(COMMON)
        *(.bss)
    }

}

The code was built via the following commands:

fasm boot.asm boot.o
i686-elf-gcc -T linker.ld -o test.bin -ffreestanding -O2 -nostdlib boot.o

and was run via this command: qemu-system-i386 -L "%QEMU%" -machine type=pc-i440fx-3.1 -kernel test.bin

What is certainly odd is that if I remove the format COFF from boot.asm, assemble it with: fasm boot.asm boot.bin , turn it it to a .img file via copy /b boot.bin boot.img, and use QEMU to test it, it actually prints the string.

Any thoughts on why nothing gets printed in the original code but it does with the modified one? Have I done/understood/overlook something?
Any help is appreciated.

标签: assemblyinterruptqemubootloaderfasm

解决方案


推荐阅读