clearing heap in djgpp

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
GLneo

clearing heap in djgpp

Post by GLneo »

hi all, i know thers some built in varables that define heap position but i can't seem to figure out how to zero out the heap???
AR

Re:clearing heap in djgpp

Post by AR »

Do you mean the .bss Section or the actual heap? The compiler shouldn't have any concept of what the heap even is, you will have to manually zero the memory once it's been allocated.

To zero the .bss, you'll need to modify your linker script so that you have something like:

Code: Select all

{
       bss = .;
       *(.bss)
       bssend = .;
}
bsslength = bssend - bss;
Then in your opening Assembly code you would have something like:

Code: Select all

.extern bss
.extern bsslength
mov $bss, %edi /* I don't have my code or compiler on hand but this should be close enough to figure out */
mov $bsslength, %ecx
xor %eax, %eax
rep
stosb
You can also optimize by dividing by 4 in the link script (bsslength = (bssend - bss) / 4;) and then using stosd to set 4bytes at a time instead of 1.

@Solar: My GAS (Cygwin i686-pc-elf 2.16.1) won't assemble STOSD, it accepts STOSB and STOSW but won't take STOSD [.code32], what have I done now?
GLneo

Re:clearing heap in djgpp

Post by GLneo »

thx that helped, stosd doesn't work for me ether??? stosw works so i used it ;)
mkr

Re:clearing heap in djgpp

Post by mkr »

AR wrote:@Solar: My GAS (Cygwin i686-pc-elf 2.16.1) won't assemble STOSD, it accepts STOSB and STOSW but won't take STOSD [.code32], what have I done now?
Don't you mean 'STOSL' instead?

mkr
AR

Re:clearing heap in djgpp

Post by AR »

That helps, bloody obvious solution again, comes from knowing both Intel and GAS Syntax assembly and being reasonably fluent in both.
Post Reply