Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Locating text and coloring text.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Ok. Im new at assembly and so far i can Print text on the screen at location 1, 1. What I want is to print text in different locations with different colors. I dont know how to do this yet. I am using TASM 3.1. I want it to be in 16 bit, and how do i do this in 32 bit as well.

Thanks.
 
You can use BIOS interrupt 10h:

"Write character and attribute at cursor position"
AH = 09h
AL = character to display
BH = page number
BL = attribute
CX = number of times to write character

"set cursor position"
AH = 02h
BH = page number
DH = row (00h is top)
DL = column (00h is left) Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Hi,

The easiest and quickest way is to write directly to the text mode screen memory.

for real mode (16bit):

mov ax,0B800h
mov ds,ax ;data segment base=0B8000h
mov bx,0h ;start of data segment
mov al,02Ah ;an asterisk
mov ah,01Fh ;white foreground, blue background
mov [bx],ax ;put word into screen memory

for real mode (32bit):

xor ax,ax
mov ds,ax ;data segment base=0h
mov ebx,0B8000h ;note ebx for 32bit
mov al,02Ah ;an asterisk
mov ah,01Fh ;white foreground, blue background
mov [ebx],ax ;note ebx for 32bit

note ax is a word of al,ah you could use:
mov ax,01F2Ah

you'll have to work out the colours yourself and how to make the colours flash.

in real mode there isnt really much difference between 32bit and 16bit operands as you always use a real mode data segment. the difference is that using 32bit registers the data segment can be greater than 64k.

recap:
text screen memory (page zero) starts at 0B8000h
for each column add 02h to bx or ebx.
for each row add 0A0h to bx or ebx.
the first byte of each word is the character to display and the second byte represents the colours.

Play! and have good fun.
Straiph
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
Thanks, but when I said 32bit, i meant win 32. If this is really hard, then just say so and dont explain how cause i wont understand probly. Thanx
 
Oh, woops, I dont really know much about win32 stuff, AmkG will. I'll shut up now.
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
Ok, this doesnt work. How is it suposed to be?

.model tiny
.stack
.data
m1 db "Hello$"
.code
main proc
mov ax,0B800h
mov ds,ax ;data segment base=0B8000h
mov bx,0h ;start of data segment
mov al,02Ah ;an asterisk
mov ah,01Fh ;white foreground, blue background
mov [bx],ax ;put word into screen memory
push seg m1
pop ds
mov ah, 09
lea dx, m1
int 21h
mov ax, 4c00h
int 21h
main endp
end main

thx
 
I copied the text straight from your post into TASM v5.0, it assembled first time and the dos exe results in a white 'H' with a blue background followed by grey 'ello' with a black background.

I didnt even have to make any changes.

to get TASM v5.0 'FREE' follow this link

"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
NOTE: TASM v5.0 is the 500k link at the bottom. "People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
PS: see FAQ - Tutorials "People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
sorry, but i cant get the thing to even compile. How do I use tasm 5.0 or tasm32 or whatever it is?
 
Did you look at FAQ - Tutorials - 'How do I make my first program in DOS mode?'
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
yes. I got it to compile(not in tasm 3.1) in 5.0, but it doesnt have any colors. It just prints Hello at location 1, 1 and thats it.
 
ok. I used a bas to asm converter to convert this program:
COLOR 5, 1
LOCATE 3, 3
PRINT "Hello"

Then i used the converter and got this. It is lengthy and confusing, but it works. Why wont the other work?

; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
;ÚÄÄÄÄÄÄÄ´ ASM Source created with BASM v3.0 (c) 1995 Kevin T. Diggins ÃÄÄÄÄÄÄ¿
;³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
;³ File Name: C:\ASSEMBLY\BASTOA~1\N.ASM ³
;³ Creation Date: 06-14-2002 ³
;³ Creation Time: 14:59:54 ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

.286p

MaxString Equ 81

Code Segment Byte Public
Code Ends

Data Segment Word Public
Data Ends

Stak Segment Word Stack
DW 128 DUP (?)
Stak Ends

Dummy Segment Para Public
Dummy Ends


Code Segment
Assume CS:Code,DS:Data,ES:Nothing,SS:Stak

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
; Release Unused Memory
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

Mov BX,Seg Data
Mov DS,BX ;Set data segment
Mov BX,Seg Dummy ;End of pgm
Mov AX,CS ;Start of pgm
Sub BX,AX ;Calc pgm size
Add BX,16 ;Paragraphs in Stack + 1
Mov AH,4AH ;Shrink mem
Int 21h ;Thru Dos
Push DS
Pop AX
Mov ES,AX ;Set ES to DS
Mov DefSeg,AX ;Set DefSeg to DS
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Call GetCursor
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
; ;Translation begins
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;
;color 5 1
;
Mov FgColor,5
Mov BgColor,1
Call SetAttribute
;
;locate 3 3
;
Mov $Ycur,3
Mov $Xcur,3
;
;Print "Hello"
;
Mov SI,Offset $tring_01
Call PrintStr
Call SetCursor

Call DoCrLf

ExitToDos:

Mov AH,4Ch
Xor AL,AL
Int 21h




GetCursor Proc Near
Mov AH,3
Xor BH,BH
Int 10h
Xor AX,AX
Mov AL,DL
Inc AL
Mov $Xcur,AX
Mov AL,DH
Inc AL
Mov $Ycur,AX
Ret
GetCursor Endp




SetCursor Proc Near
Mov AX,$Xcur
Mov DL,AL
Dec DL
Mov AX,$Ycur
Mov DH,AL
Dec DH
Mov AH,2
Int 10h
Ret
SetCursor Endp




Len Proc Near
Push CX
Push SI
Push DI
Mov DI,SI
Xor AL,AL
Mov CX,0ffffh
Cld
Repnz Scasb
Not CX
Dec CX
Mov AX,CX
Pop DI
Pop SI
Pop CX
Ret
Len Endp




SetAttribute Proc Near
Push CX
Mov AX,BgColor
Mov BX,FgColor
Shl AX,4
Add AX,BX
Xor Ah,Ah
Cmp AX,128
Jl SkipXor
Xor AX,128
SkipXor:
Mov $Attr,AX
Pop CX
Ret
SetAttribute Endp




PrintStr Proc Near
Call Len
Push AX
Mov CX,AX
Cmp CX,0
Jle PS_3
Mov BX,$Attr
Mov AX,$Ycur
Mov DI,$Xcur
Push DS
Push ES
Dec AX
Dec DI
Cmp DI,0
Jg PS_1
Xor DI,DI
PS_1:
Mov DX,80
Mul DX
Add DI,AX
Shl DI,1
Mov AX,0B000H
Mov ES,AX
Mov AH,0FH
Int 10H
Cmp AL,07H
Je PS_2
Mov AX,0B800H
Mov ES,AX
PS_2:
Cld
Movsb
Mov ES:[DI],BL
Inc DI
Loop PS_2
Pop ES
Pop DS
PS_3:
Pop AX
Add $Xcur,AX
Ret
PrintStr Endp




DoCrLf Proc Near
Mov $Xcur,1
Inc $Ycur
Cmp $Ycur,26
Jne CrLf_1
Dec $Ycur
CrLf_1:
Mov DX,Offset $CrLf
Mov AH,9
Int 21h
Mov BX,$Xcur
Mov DL,BL
Dec DL
Mov BX,$Ycur
Mov DH,BL
Dec DH
Xor BX,BX
Mov AH,2
Int 10h
Ret
DoCrLf Endp




ShowHideCursor Proc Near
Cmp AX,0
Je Sh1
Mov CL,13
Mov CH,12
Mov AH,01
Int 10h
Jmp Sh2
Sh1:
Xor CL,CL
Mov CH,1
Mov AH,1
Int 10h
Sh2:
Ret
ShowHideCursor Endp


Code Ends


Data Segment

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ System Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

$Xcur DW 1
$Ycur DW 1
$Attr DW 7
$CrLf DB 13,10,'$'
FgColor DW 7
BgColor DW 0
Err DW 0
DefSeg DW 0
$Var0 DW 0
$Var1 DW 0
$Var2 DW 0
$Var3 DW 0
$Var4 DW 0
$Var5 DW 0
$Var6 DW 0
$Var7 DW 0
$Var8 DW 0
$Var9 DW 0
$Var10 DW 0
$Var11 DW 0
$Var12 DW 0

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Users Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

$tring_01 DB "Hello",0

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ System Un-Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ


;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Users Un-Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Data Ends

End
 
The BASM assembly works but the turtorial doesnt.

Strange, in the default screen mode putting 01F2Ah into location B800:0000 should put a white asterisk with a blue background at the top left of the screen!

Maybe the current screen mode isnt colour, you could try changing the screen mode by inserting the following in the tutorial:

mov ax,03h ;80x25 colour text mode
int 010h

Other than that I dont know. It works on my PC.
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
AHA. It works now. It has a blue background with white text for the H and the ello is in grey text w/ black bg. Thanks for your help straiph. Mabe the problems had something to do with XP. It seems to cause trouble every now and then on stuff. Mostly when im trying to program in qbasic, c++ or asm.

thx
 
Yes it's definitely an OS problem. Pops up on Win NT also. Best thing to do sometimes is to press Alt-enter but doesn't always solve the problem. It's probably better to do DOS16 programming on Win98.
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Phew, Im glad you solved it. My experience is that the less you have to deal with 3rd party operating systems the less problems you have.
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
My experience is that the less you have to deal with 3rd party operating systems the less problems you have.

== Write your own operating system...

Right straiph?? :) :) :) "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top