I am learning 8086 assembly. I need to change the background colour of the screen using 8086 assembly. I saw a few tutorials where they could set only a portion of the screen. I don't want to do this by DOS Interrupts whereas all the tutorials are in DOS Interrupts. It would be good if anyone show me the code to set the whole portion of the screen(background colour) using BIOS Interrupts.
Asked
Active
Viewed 3.9k times
4
-
You write directly to video memory. Assuming your screen is displaying page 0 (and by default it most likely will, the video memory is at physical address 0xb8000 (or 0xb800:0x0000). Each cell on the screen has a character and attribute byte (forming a 16-bit _WORD_ pair). The character comes first in memory then the attribute (foreground/background color). Address 0xb8000 would contain the character to display at coord 0,0. 0xb8001 would contain the attribute byte, 0xb8002 would be char at coord 0,1 and its attribute at 0xb8003 etc. – Michael Petch Mar 18 '16 at 17:33
-
If a screen is 80x25 that would require 2 bytes for each of the characters on the screen so that is (80*25)*2=4000. – Michael Petch Mar 18 '16 at 17:34
-
any code will be great. pls – Mar 18 '16 at 17:34
-
To clear an 80x25 screen you would set all the characters on the screen to a space character and then set the attribute byte with the background color you wish to use. – Michael Petch Mar 18 '16 at 17:34
-
Can you give me some code? – Mar 18 '16 at 17:35
-
lol...sry. I thought it could give me some clarification. Sorry about that. – Mar 18 '16 at 17:37
-
I also misread the very end, I thought it said *without* BIOS interrupts. My method wouldn't have relied on an interrupt to actually clear the screen. Fifo's answer is the correct one, however you will have to modify it to conform to a bootloader. – Michael Petch Mar 18 '16 at 17:39
-
"Modify it to conform to a bootloader"? why? – Mar 18 '16 at 17:41
-
can I inject the code provifef by fifo to my bootloader? – Mar 18 '16 at 17:47
-
1If you have the general wrapper/code for a bootloader already, in theory you should be able to drop Fifo's code into it (I upvoted his answer because it does appear to be correct). – Michael Petch Mar 18 '16 at 17:47
-
Something that didn't occur to me. Are you trying to change the background color of the screen without removing the text already on the screen? – Michael Petch Mar 18 '16 at 18:25
-
Actually I am bit confused b/w I am stuck in an another problem. When I insert my USB into my system, it asks me to format it. I even have BIOS parameter block within my sample boot loader. – Mar 18 '16 at 18:34
-
Isn't that same as the file system? – Mar 18 '16 at 18:35
-
No, its not the same as the file system. Depending on whether the BPB is placed in the Master Boot Record or a Volume boot Record it simply gives basic information about the drive/partition. You still must properly format it. Without seeing your bootloader it is very hard to give a definitive answer, however that would be something you can ask in a new question. Depending on how how you wrote to the USB drive, it is possible that if you have Windows format the drive for you, that it will rewrite your bootloader in the process. – Michael Petch Mar 18 '16 at 18:40
-
I wrote an answer yesterday about writing a bootloader (and a second stage in that case) for use on USB media that didn't have a BPB. But maybe it might inspire you to get over your current hurdle. The information pertained to development in a Windows environment with NASM. That question and my answer are here: http://stackoverflow.com/questions/36044706/how-to-make-bootloader-to-load-the-second-sector-of-a-usb/36052385#36052385 – Michael Petch Mar 18 '16 at 18:46
-
I wrote an answer that may be of some value to people who see this question. http://stackoverflow.com/a/36222237/3857942 – Michael Petch Mar 25 '16 at 22:10
2 Answers
10
You can change the background and foreground color for all the screen by using BIOS function 06h
MOV AH, 06h ; Scroll up function
XOR AL, AL ; Clear entire screen
XOR CX, CX ; Upper left corner CH=row, CL=column
MOV DX, 184FH ; lower right corner DH=row, DL=column
MOV BH, 1Eh ; YellowOnBlue
INT 10H
The numbers suit the text video mode of 80x25.
One of the best sources of information on BIOS and DOS Interrupts for the IBM PC is Ralf Brown's Interrupt List. INT 10h is the general BIOS interrupt for video routines. A complete list of the INT 10h routines can be found here. I have used the BIOS routine INT 10h/AH=06 which is documented as:
VIDEO - SCROLL UP WINDOW
AH = 06h AL = number of lines by which to scroll up (00h = clear entire window) BH = attribute used to write blank lines at bottom of window CH,CL = row,column of window's upper left corner DH,DL = row,column of window's lower right corner Return: Nothing

Michael Petch
- 46,082
- 8
- 107
- 198

Fifoernik
- 9,779
- 1
- 21
- 27
-
-
@CameraJohn So what you are asking is how to update the background color of the screen without overwriting the text that already exists? – Michael Petch Mar 18 '16 at 18:52
-
@CameraJohn : If you are using NASM this answer should work: http://stackoverflow.com/a/32686665/3857942 . That code was written as a function. You set _AL_ to foreground/background color you want. `mov al, 01eh` would be yellow on blue. Then you do a `call setTextAttributes` . That code assumes an 80x25 screen layout (video mode 3) – Michael Petch Mar 18 '16 at 19:02
-
@CameraJohn : it is a bit more complex if you need to preserve the original foreground color. You could use the answer I linked to and modify it to read the current attribute, create a new attribute combining the foreground color that is at the current location and combine it with your background color and then write that to the display. – Michael Petch Mar 18 '16 at 20:04
3
This is blue screen:
mov ah, 09h
mov cx, 1000h
mov al, 20h
mov bl, 17 ; This is Blue & White.
You can change 17 to other color numbers;
- 0 = Black
- 1 = Blue
- 2 = Green
- 3 = Aqua
- 4 = Red
- 5 = Purple
- 6 = Yellow
- 7 = White
- 8 = Gray,
- 9 = Light Blue.
Example:
mov bl, 47
This is Red & White.

diswithend
- 71
- 8
-
2And then what, after putting those values in CPU registers? Presumably `int 10h` like in the question you posted using similar values ([How do I print text on the blue screen?](https://stackoverflow.com/q/51464053)), but a different `bl` value. You should link to the docs for that BIOS call, like Fifoernik's answer does. – Peter Cordes Jul 22 '18 at 12:14
-
2`mov bl, 47` is incorrect. You want those values in hex. Should be `mov bl, 47h` .Same with `mov bl, 17` it should be `mov bl, 17h` – Michael Petch Jul 22 '18 at 15:26