Re: A89: Beginner


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

Re: A89: Beginner





There are three kinds of sections: CODE, DATA and BSS.
CODE is for program (obviously), DATA is for initialized data and BSS is for
uninitialized data.

The advantage of BSS over DATA is that no space will be reserved for it
in the executable, thus making it smaller. The disadvantage is that all
variables in the BSS are automatically initialized to zero when the program
starts. DATA variables can have startup values different from zero since
they are loaded along with CODE from the executable.

The operating system/startup code is responsible for allocating and clearing
(zeroing) the BSS space.


Example (in C):

/* (this is the top level, i.e. not inside a function) */

char a[100000];	/* this huge array WOULD NOT make the executable larger */

char b[100000]="foo"; /* this one WOULD because it's initialized */


Note that it would have been much smarter to declare 'b' uninitialized and
then setting the first elements to 'f','o' and 'o' respectively "by
ourselves". This would save (almost) 100,000 bytes in the executable!!!

When it comes to assembler programming on the TI89/92+, BSS is *not*
supported by TI-OS. However, the various kernels available have (a rather)
limited support for it:

main:
	...
	...

	section bss		; tell assembler that a BSS follows
var1	ds.l	4		; reserve four longwords (note: not ds.l)
var2	ds.w	1		; reserve one word
var3	ds.b	16384		; reserve 16kb
	...
	end

'var1', 'var2' and 'var3' will be put in the BSS section and they will not be
included in the .89z-file. The program will NOT be >16k in size (as one
might think), instead it needs those 16k memory ONLY WHEN IT RUNS.
The BSS variables are "allocated" automagically when the program starts and
"freed" when it exits. (You could not, for example, store a highscore list in
the BSS since it would be lost when the program exited!)

Ehrm... hope it made sense to *someone*... it's really hard to explain it to
people who doesn't have a clue about it... please ask again if you have any
doubts or fears about BSS! 

//Johan


On Tue, May 18, 1999 at 11:34:53AM -0700, Matt Baker wrote:
> 
> I know that this does not help any, but I am interested to find out what it 
> is also.  My guess would be that it is just a way to declare the start of a 
> data segment.  Why would one use BSS?  Is there any advantages?
> 
> Thanks,
> 
> Matt.
> 
> >What does BSS mean.  Ive seen it in several places, but nobody I talk to
> >knows what it is.
> 
> 
> _______________________________________________________________
> Get Free Email and Do More On The Web. Visit http://www.msn.com
> 


References: