-1

I am trying to write a boot sector that prints a string to the screen. I am using nasm. My tutorial says that when calling int 10h you have put the value 07h into bl. This is the color of your text. I tried changing the value of bl to 08h but it did not print anything! So I tried changing it to 06h and still nothing! Is it possible to change the color using the value in bl? If so what value matches what color?

If I change the value in ah will int 10h do something else (for example scan text into al)?

old_timer
  • 69,149
  • 8
  • 89
  • 168
Isaac D. Cohen
  • 797
  • 2
  • 10
  • 26

1 Answers1

5

In order to print a character, you need to put:

  1. 9 in AH (write instruction)
  2. The character in AL
  3. The page number in BH
  4. The colour attribute in BL (high 4 bits are background, low 4 bits are foreground)
  5. The number of characters to write in CX
  6. Call BIOS interrupt 10h

So:

mov ah, 9  ; Write instruction for int 0x10
mov al, 64 ; A
mov bh, 0  ; Page number
mov bl, 4  ; Red on black (00000100 - High 0000 is black, low 0100 is red)
mov cx, 1  ; Writes one character
int 10h

About you're last question, yes. Interrupt 10h is the BIOS video services. It has many functions, all controlled by the value of AH. Each one has different arguments.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Macmade
  • 52,708
  • 13
  • 106
  • 123
  • I tried what you said and it prints "A", but in white on black not red on black. – Isaac D. Cohen Aug 08 '13 at 18:33
  • 1
    On which hardware/VM are you testing this? – Macmade Aug 08 '13 at 18:36
  • I just noticed what I was doing wrong. My tutorial said to put 0Eh into ah. Now I tried 9 like you said and it works... I wonder why. – Isaac D. Cohen Aug 08 '13 at 19:33
  • 1
    0Eh is a different BIOS video services function (see the link in my answer). It also writes a character at the current cursor position, but with the current attributes. There's no argument for the colour attribute with 0Eh. If you want to change the colour attributes when printing a character, you need to use 09h instead. – Macmade Aug 08 '13 at 22:07