display | more...

(This was written to complete information found in the node interrupt 10h. I assume basic assembly knowledge, and that you want to try and use interrupt 10h. PLEASE DO NOT VOTE ON THIS NODE UNLESS YOU KNOW OR HAVE USE FOR ATTRIBUTE BYTES!

In command line prompts (text modes on computers) each character on screen actually takes up two bytes of memory. ASCII codes are only one byte big, so what is the other byte for? Setting the attributes! If you're using interrupt 10h in assembly to write stuff on the screen, you will notice that some of the functions as for an attribute byte.

The attribute byte is 8 bits long. The 8 bits are separated into 3 sections.

Blinking bit   Background Color   Foreground Color
           0          101         0101

As you can see, that's 8-bits or one byte long.

Blinking bit:
    1: Blinking!
    0: Not blinking!

Background color:
    000: Black
    001: Blue
    010: Green
    011: Cyan
    100: Red
    101: Magenta
    110: Brown
    111: White

Foreground (Text) Color:
    0000: Black
    0001: Blue
    0010: Green
    0011: Cyan
    0100: Red
    0101: Magenta
    0110: Brown
    0111: White
    1000: Grey
    1001: Light Blue
    1010: Light Green
    1011: Light Cyan
    1100: Light Red
    1101: Light Magenta
    1110: Yellow
    1111: Bright White

You might notice for the foreground color that all the colors starting with a 1 bit are just brighter versions of the colors starting with a 0 bit.

Some sample assembly code:

To write a blinking light blue '$' with a black background to the cursor location on screen:

mov ah, 9 ;Write Character and Attribute
mov al, '$' ;Puts ASCII code of '$' into AL
mov bh, 0
mov bl, 10001001b ;The attribute byte!
mov cx, 1
int 10h

If I moved into BL, 01110000b I would have black text on a white background. If I moved into BL, 10001100b I would have blinking light red text on a black background. Now you know how to fully manipulate on-screen text using assembly!

Source: Assembly Language for Intel-Based Computers: Third Edition by Kip R. Irvine, published by Prentice Hall. I did not copy verbatim. Instead I tried to improve and give a better explaination than the book does. Please /msg me for factual and spelling errors!

Log in or register to write something here or to contact authors.