943,931 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 2469
  • Assembly RSS
Oct 12th, 2009
0

Changing Text Colour with NASM Assembly

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

Assembly Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
MichaelSammels is offline Offline
36 posts
since Nov 2008
Oct 13th, 2009
0
Re: Changing Text Colour with NASM Assembly
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:
Assembly Syntax (Toggle Plain Text)
  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:
Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: total rookie,pls help me
Next Thread in Assembly Forum Timeline: Array input question in assembly





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC