Real Mode Assembly: Print Char to Screen without INT Instruction on Boot

前端 未结 3 1947
夕颜
夕颜 2021-02-09 17:50

The following site \"Writing Boot Sector Code\" provides a sample of code that prints \'A\' to the screen when the system boots. From what I have been reading don\'t you have to

相关标签:
3条回答
  • 2021-02-09 18:28

    Basically when you call INT 10h, BIOS will execute a routine that does almost the same thing, by writing characters and their attributes to video memory. It is, however useful to know how to write and execute these routines yourself so if and when you decide to switch the CPU into 32-bit protected mode, you can still print characters to the screen because in that mode you will no longer be able to call BIOS interrupts.

    0 讨论(0)
  • 2021-02-09 18:42

    At boot, you're in a default screen mode - in this case a text screen mode. Your example program is writing directly into the character buffer that's displayed on the screen for that text screen mode. Setting the data segment register to 0xb800 is getting things set up to point at that buffer. Check out this tutorial for more information.

    0 讨论(0)
  • 2021-02-09 18:44

    Direct answer to your question: The line "movb $'A', 0" effectively completes the print to the screen (and the following line, "movb $0x1e, 1" specifies what color it should be).

    Longer answer: The video hardware draws the screen based on the contents of memory. When in text mode, the video hardware starts drawing based on memory segment 0xB800. Whatever is at byte 0 defines the character to be drawn at the first text cell on the screen. The next byte defines the attributes (foreground color, background color, and blink status). This pattern repeats (char - attr - char - attr) throughout the entire screen.

    So, technically, my direct answer wasn't true. The 2 'movb' statements simply stage the letter 'A' to be printed. 'A' is not printed until the next time hardware refreshes the display based on the memory.

    0 讨论(0)
提交回复
热议问题