Cannot write zeroes to memory.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SirRahbek
Posts: 3
Joined: Sun Feb 16, 2014 11:05 am

Cannot write zeroes to memory.

Post 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
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: Cannot write zeroes to memory.

Post by Combuster »

My crystal ball says your problem description is incorrect.

Proof wanted.
"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 ]
SirRahbek
Posts: 3
Joined: Sun Feb 16, 2014 11:05 am

Re: Cannot write zeroes to memory.

Post 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?
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Cannot write zeroes to memory.

Post by qw »

Why would you want to zero-terminate the screen in the first place?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Cannot write zeroes to memory.

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Cannot write zeroes to memory.

Post 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.
User avatar
siavoshkc
Member
Member
Posts: 40
Joined: Wed Feb 19, 2014 11:10 am

Re: Cannot write zeroes to memory.

Post by siavoshkc »

Write space char there " ". :mrgreen:
Check out my FSB Data Integrity Tester at http://fsbdit.sourceforge.net/.

Siavosh
AbstractYouShudNow
Member
Member
Posts: 92
Joined: Tue Aug 14, 2012 8:51 am

Re: Cannot write zeroes to memory.

Post 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.
Post Reply