Changing Text Colour with NASM Assembly

Thread Solved

Join Date: Nov 2008
Posts: 11
Reputation: MichaelSammels is an unknown quantity at this point 
Solved Threads: 0
MichaelSammels's Avatar
MichaelSammels MichaelSammels is offline Offline
Newbie Poster

Changing Text Colour with NASM Assembly

 
0
  #1
Oct 12th, 2009
Does anyone know how to change the colour of strings using x86 NASM Assembler? I've found tutorials like this:

  1. mov ah, 09h
  2. mov al, 97
  3. mov bx, 100b
  4. mov cx, 01h
  5. 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?
Last edited by MichaelSammels; Oct 12th, 2009 at 8:01 am.
Thanks,

Michael
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 133
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
Oct 13th, 2009
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:
  1. clrscr:
  2. mov dx, 0 ; Set cursor to top left-most corner of screen
  3. mov bh, 0
  4. mov ah, 0x2
  5. int 0x10
  6. mov cx, 2000 ; print 2000 chars
  7. mov bh, 0
  8. mov bl, 0x21 ; green bg/blue fg
  9. mov al, 0x20 ; blank char
  10. mov ah, 0x9
  11. int 0x10
  12. ret

This code writes a blue 'A' char to 0,0:
  1. mov cx, 0xb800
  2. mov es, cx
  3. mov ax, 0x141
  4. mov [es:0], ax
  5. waitkey:
  6. mov ah, 0x6
  7. mov dl, 0xff
  8. int 0x21
  9. jz waitkey
  10. ret
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC