Re: A92: BSS


[Prev][Next][Index][Thread]

Re: A92: BSS




At 03:20 PM 3/24/98 -0800, Anton Ivanov wrote:
>What is BSS?  What's the advantage over just using dc.x statements in a prog?

A BSS section is a block of uninitialized memory. Since it is
uninitialized, the data within it does not need to be defined in stored
program. It is allocated upon runtime.

There are three types of sections: Code, Data, and BSS. The practical
difference between Code and Data sections is that, in Data sections, unused
space is padded with zeroes, but in Code sections, it is padded with NOPs
($4E71).

The advantage of using a BSS section is that whatever you put in it will
not add to the size of a program. The disadvantage is that, if something
that you put in a BSS section needs to be initialized, you must do the
initialization manually.

If you try to initialize something that's in a BSS section, the
initialization will be ignored. The only thing the assembler will record is
the size. So if, inside a BSS section, you do
 str: dc.b "This won't make it into the compiled program.",0
 num: dc.l 38759
what will happen is that there will be 46 bytes of uninitialized memory at
"str" and 4 bytes of uninitialized memory at "num".

Note that some operating systems may initialize a BSS section with zeroes.
However, this is not standard behavior and it should never be assumed that
this is done. Just make sure that any given byte in a BSS section is
guaranteed to be written before it is read. Bugs can often result when this
is not done.

For a good example of using BSS, look at flib.asm.

(For the curious, BSS stands for "Block Started by Symbol".)

---
David Ellsworth
davidell@earthling.net
IRC: eXocomp
ICQ: 2300673


References: