Some ASM questions

Programming, for all ages and all languages.
Qoppa
Posts: 6
Joined: Sat Nov 08, 2008 8:33 pm

Re: Some ASM questions

Post by Qoppa »

OK, thanks. Just wanted to be sure I wasn't missing something important.

The code for my puts function:

Code: Select all

word *screenmem = (word *) 0x000B8000;

void puts(const char *str)
{
	int i;
	for(i = 0; i < strlen(str); i++)
		memsetw(screenmem + i, (color << 8) | str[i], 1);
}
It prints it just fine. The text just flickers...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Some ASM questions

Post by Combuster »

Qoppa wrote:(written by someone on this board... I forget who)
If you bothered to look at the link...
Just to note, there's also a DX there (which is not quite a byte...)

As for your code: there are signed conversions, and color can have bit 7 set which causes blinking as well - try a black background.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Qoppa
Posts: 6
Joined: Sat Nov 08, 2008 8:33 pm

Re: Some ASM questions

Post by Qoppa »

Combuster wrote:As for your code: there are signed conversions, and color can have bit 7 set which causes blinking as well - try a black background.
That was it, thank you!

Sorry for not remembering who's signature I found the site in. As a beginner, it's really useful/interesting to look through.
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: Some ASM questions

Post by CodeCat »

If the most significant bit is set, it can be interpreted as both blinking text and brighter background depending on a setting in the VGA I/O memory area. If the blinking is fast (Bochs by default has a rather high blink rate) then it looks like what you described. It's also best to use specifically unsigned quantities, especially with char. Char is not required to be either signed or unsigned, so you should always specify it if you depend on its (lack of) signedness. And as Combuster said, if a signed value is casted to a larger value, it is sign-extended, which will result in extending the value with 1-bits if the original value had its most significant bit set. I.e. 8 bits 1000 0001 (-127 signed, 129 unsigned) is sign-extended to 16 bits 1111 1111 1000 0001 (-127 signed, 65409 unsigned).

Also, what type does color have? If it's a char, then shifting it left by 8 places will shift all the bits off the end, and you get zero. You need to cast it to a short first before shifting so that there is additional room for the shift.

I assume that you didn't get around to handling cursor position, newlines and scrolling yet.
Post Reply