Does anyone know how to change the colour of strings using x86 NASM Assembler? I've found tutorials like this:

mov  ah,  09h 
mov  al,  97 
mov  bx,  100b
mov  cx,  01h 
int  10h

Which prints the letter "A" once in the colour you choose. This is a handy tutorial, but I would like to be able to print the entire screen text (i.e more than one string) in the same colour. Anyone have any ideas?

Color text-mode memory lies at segment 0xb800 and is 4000 bytes
in length 80*25*2 cuz each visible character on the screen
is accompanied by a text attribute byte.
00000000 Text Attribute Byte
XXBGxxFG
The low-nibble defines the foreground and the high-nibble
the background, and there is a way to disable the blink
bit.

Function 9 - Output Char And Attribute At Hardware Cursor
CX-Repeat
BH-Display Page
BL-Attribute
AL-Character
AH-9
INT 0x10

To clear the screen to one f/b color try this code:

clrscr:
mov dx, 0 ; Set cursor to top left-most corner of screen
mov bh, 0
mov ah, 0x2
int 0x10
mov cx, 2000 ; print 2000 chars
mov bh, 0
mov bl, 0x21 ; green bg/blue fg
mov al, 0x20 ; blank char
mov ah, 0x9
int 0x10
ret

This code writes a blue 'A' char to 0,0:

mov cx, 0xb800
mov es, cx
mov ax, 0x141
mov [es:0], ax
waitkey:
mov ah, 0x6
mov dl, 0xff
int 0x21
jz waitkey
ret
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.