Hi there,

I'm getting some memory from DOS and looping over it writing data to it. Then when I loop over it again, straight after its been written to, and output its values, towards the end, there is some garbage!

I cut and pasted the memory allocation code so that now it does it twice. In other words, the pointer to the new memory block is written too twice and, with the second block of memory and the rest of the code the same, the garbage doesn't exist!

My intuition tells me that this shouldn't be possible but it is happening on 2 different machines. What's even more strange is that, when writing to the memory buffer, before moving onto the next word, I read the word in memory that had just been written too and ALL of the words have the correct value.

Thus, how on earth can you write to memory and then after doing so, read from the same memory and the values of some of the bytes (always in the same place) be different? And yet this problem goes away if I ask for a different block of memory from DOS?

S.
Posted on 2004-01-12 13:11:58 by Station
Your talking virtual DOS. Here's an example of what you'll see at address 00000000h and same real mode address 0000:0000h

Physical address 00000000h in Windows:

00000000 16 E8 00 F0 16 E8 00 F0-C3 E2 00 F0 16 E8 00 F0 ................
00000010 16 E8 00 F0 54 FF 00 F0-68 7E 00 F0 16 E8 00 F0 ....T...h~......
00000020 A5 FE 00 F0 87 E9 00 F0-6F EF 00 F0 6F EF 00 F0 ........o...o...
00000030 6F EF 00 F0 6F EF 00 F0-57 EF 00 F0 6F EF 00 F0 o...o...W...o...
00000040 DD 10 00 C0 4D F8 00 F0-41 F8 00 F0 34 98 00 F0 ....M...A...4...
00000050 39 E7 00 F0 59 F8 00 F0-2E E8 00 F0 D2 EF 00 F0 9...Y...........
00000060 A4 E7 00 F0 F2 E6 00 F0-6E FE 00 F0 53 FF 00 F0 ........n...S...
00000070 53 FF 00 F0 A4 F0 00 F0-C7 EF 00 F0 D4 51 00 C0 S............Q..
00000080 F2 E6 00 F0 16 E8 00 F0-16 E8 00 F0 16 E8 00 F0 ................

Same address in DOS mode:

0000:0000 68 10 A7 00 8B 01 70 00-16 00 A8 03 8B 01 70 00 h.....p.......p.
0000:0010 8B 01 70 00 B9 06 12 02-40 07 12 02 FF 03 12 02 ..p.....@.......
0000:0020 46 07 12 02 0A 04 12 02-3A 00 A8 03 54 00 A8 03 F.......:...T...
0000:0030 6E 00 A8 03 88 00 A8 03-A2 00 A8 03 FF 03 12 02 n...............
0000:0040 A9 08 12 02 99 09 12 02-9F 09 12 02 5D 04 12 02 ............]...
0000:0050 A5 09 12 02 0D 02 E0 02-B8 09 12 02 8B 05 12 02 ................
0000:0060 02 0C 12 02 08 0C 12 02-13 0C 12 02 AD 06 12 02 ................
0000:0070 AD 06 12 02 A4 F0 00 F0-37 05 12 02 D4 51 00 C0 ........7....Q..

I think the segments are shifted to new locations in memory and no longer pertain to an actual physical address. In fact when I did a search for this DOS table I found it right near the program that gave me this data dump (Debug.exe). This is the actual interrupt vector table for both modes. As you work your way up in memory they become the same in both again which is the BIOS parameter area. The infamous 40:XXXX address.
Posted on 2004-01-14 09:51:20 by mrgone