Reputation: 75
I face a strange bug in assembly (8086) while using dosbox. I am trying to print text, colored green. this is my main, when i called the function:
mov bl,2h ; set the color (green)
mov dx,OFFSET str_msg ; set the string to print
call WRITE_TEXT_IN_COLOR
call NEW_LINE
and this is the function WRITE_TEXT_IN_COLOR
proc WRITE_TEXT_IN_COLOR
mov ah,9
mov cx,200 ; number of chars that will be painted
int 10h
int 21H
ret
endp WRITE_TEXT_IN_COLOR
now, when i run the program, it's print the 'required' text, along with a long strig of 'dddddd' i will really appreciate possible solutions.
Upvotes: 1
Views: 1484
Reputation: 9899
Your code can work if the count in CX is exactly equal to the actual length of the message. If CX has a number larger than the length of the message then BIOS will display the excess in whatever character code was in the AL register (that you forgot to setup)
I propose the following changes
mov bx,0002h ; set the color (green) AND select page 0
mov dx,OFFSET str_msg ; set the string to print
call WRITE_TEXT_IN_COLOR
call NEW_LINE
and
proc WRITE_TEXT_IN_COLOR
mov ax,0920h ;AH=Function number AL=Space character
mov cx,200 ; number of chars that will be painted
int 10h ;BIOS function 09h
int 21H ;DOS function 09h
ret
endp WRITE_TEXT_IN_COLOR
Upvotes: 1