Page 1 of 1
Cannot write zeroes to memory.
Posted: Sun Feb 16, 2014 11:11 am
by SirRahbek
Hello forum, i have this odd problem with some code.
It seems that i cannot write the value 0x00 to my memory, which is rather frustrating when trying to null terminate a string!
I have tested the code writing other values to memory, and then everything works fine.
Have anyone else encountered this problem before?
I am running my code in VirtualBox 4.3.6
Re: Cannot write zeroes to memory.
Posted: Sun Feb 16, 2014 11:36 am
by Combuster
My crystal ball says your problem description is incorrect.
Proof wanted.
Re: Cannot write zeroes to memory.
Posted: Sun Feb 16, 2014 12:20 pm
by SirRahbek
How would you like your proof? You can have the source if you want.
As for the description, let me try to make it more clear.
When i write: mov byte [ebx], 0x00 to the screen memory, to overwrite another char, that char does not dissappear as i would pressume it would
But if write: mov byte [ebx], "X", an X appears at the desired location.
Pardon my perhaps incorrect way of asking, but i am very new here.
Can you help me?
Re: Cannot write zeroes to memory.
Posted: Sun Feb 16, 2014 1:52 pm
by qw
Why would you want to zero-terminate the screen in the first place?
Re: Cannot write zeroes to memory.
Posted: Sun Feb 16, 2014 5:54 pm
by Brendan
Hi,
SirRahbek wrote:How would you like your proof? You can have the source if you want.
As for the description, let me try to make it more clear.
When i write: mov byte [ebx], 0x00 to the screen memory, to overwrite another char, that char does not dissappear as i would pressume it would
But if write: mov byte [ebx], "X", an X appears at the desired location.
When writing to display memory the video hardware has no reason to care which value you're writing. Therefore it's extremely unlikely that what you're describing is possible, and extremely likely that you're making some other mistake (e.g. wrong value in EBX when you think you're writing a zero) and got confused.
For this reason you should post the relevant pieces of your source code so that we can rule out all of the much more likely problems.
Cheers,
Brendan
Re: Cannot write zeroes to memory.
Posted: Mon Feb 17, 2014 1:24 am
by iansjack
The problem is not, as you have described it, that you cannot write a zero to a memory location (on the evidence that you have presented). All you have shown is that when you write (what you think is) zero to (what you think is) screen memory nothing changes. (And note that if you did write zero there it wouldn't blank out the character, but would display a different character.) Your hypothesis is that this means that you cannot write zero to memory.
In general, this is clearly impossible (although it might be possible if you were doing memory-mapped output to a particular register in a particular bit of hardware). Therefore, almost certainly, your hypothesis is wrong. So, something else is wrong. Rather than making more, probably incorrect, hypotheses why don't you run the code under a debugger so that you can gather real evidence about what is happening. Don't rely upon side effects (writing a zero to screen memory blanks a particular part of the screen) which your understanding of may be incorrect (in this case it is). Look dierectly at what happens to a memory location when you write a zero to it. I can guarantee you that the end result will be a zeroed memory location.
Your problem lies elsewhere.
Re: Cannot write zeroes to memory.
Posted: Thu Feb 20, 2014 1:09 pm
by siavoshkc
Write space char there " ".
Re: Cannot write zeroes to memory.
Posted: Thu Feb 20, 2014 2:01 pm
by AbstractYouShudNow
What value does ECX contain ?
Are you in real or protected mode (I'm guessing protected since you use 32-bit registers, but that ain't a rule)
What particular things have you done before this ?
Do you have any exception handlers registered ?
ecx probably doesn't contain the value you intended, and you are writing to some hardware. From the fact that you are trying to write to the string, I guess that you're beginning to implement drivers, so maybe are you writing to something that is *not* memory but just some piece of hardware that in reaction does something your os won't handle.