简体   繁体   English

实模式组装:在引导时不使用INT指令将字符打印到屏幕

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

The following site "Writing Boot Sector Code" provides a sample of code that prints 'A' to the screen when the system boots. 以下站点“编写引导扇区代码”提供了一个代码示例,可在系统引导时将“A”打印到屏幕上。 From what I have been reading don't you have to use INT opcode to get BIOS to do certain things? 从我一直在阅读的不是你必须使用INT操作码让BIOS做某些事情? How does the code below, from the site referenced above work without using interrupts? 以下代码如何从上面引用的站点工作而不使用中断? What portion of code actually tells the hardware to print 'A' to the screen? 代码的哪一部分实际告诉硬件将“A”打印到屏幕上?

Code in question: 有问题的代码:

.code16
.section .text
.globl _start
_start:
  mov $0xb800, %ax
  mov %ax, %ds
  movb $'A', 0
  movb $0x1e, 1
idle:
  jmp idle 

APPENDING TO ORIGINAL QUESTION 附加原始问题

If I use the following code does the BIOS call write to the text buffer for me? 如果我使用以下代码,BIOS调用是否会为我写入文本缓冲区? The buffer starting at address 0xb800? 缓冲区从地址0xb800开始?

   # Author: Matthew Hoggan
   # Date Created: Tuesday, Mar 6, 2012
   .code16                        # Tell assembler to work in 16 bit mode (directive)
   .section .text
   .globl _start                  # Help linker find start of program
   _start:
       movb $0x0e,     %ah        # Function to print a character to the screen                 
       movb $0x00,     %bh        # Indicate the page number
       movb $0x07,     %bl        # Text attribute
       mov  $'A',      %al        # Move data into low nibble                   
       int  $0x10                 # Video Service Request to Bios                             
   _hang:                         
       jmp  _hang                 
       .end   

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). 直接回答你的问题:行“movb $'A',0”有效地完成了对屏幕的打印(以下行,“movb $ 0x1e,1”指定它应该是什么颜色)。

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. 在文本模式下,视频硬件基于内存段0xB800开始绘制。 Whatever is at byte 0 defines the character to be drawn at the first text cell on the screen. 无论字节0是什么,都定义了要在屏幕上的第一个文本单元格绘制的字符。 The next byte defines the attributes (foreground color, background color, and blink status). 下一个字节定义属性(前景色,背景色和闪烁状态)。 This pattern repeats (char - attr - char - attr) throughout the entire screen. 这种模式在整个屏幕上重复(char - attr - char - attr)。

So, technically, my direct answer wasn't true. 所以,从技术上讲,我的直接回答并非如此。 The 2 'movb' statements simply stage the letter 'A' to be printed. 2'movb'语句只是将字母“A”打印出来。 'A' is not printed until the next time hardware refreshes the display based on the memory. 在下次硬件根据内存刷新显示屏之前,不会打印“A”。

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. 将数据段寄存器设置为0xb800可将设置为指向该缓冲区。 Check out this tutorial for more information. 有关更多信息,请查看本教程

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. 基本上当你调用INT 10h时,BIOS会通过将字符及其属性写入视频内存来执行几乎完全相同的例程。 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. 然而,知道如何自己编写和执行这些例程是很有用的,所以当你决定将CPU切换到32位保护模式时,你仍然可以在屏幕上打印字符,因为在那种模式下你将不再能够调用BIOS中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM