[A89] Re: dumb assembly questions


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

[A89] Re: dumb assembly questions




DISCLAIMER: haven't touched 68k for more than 6 months.

> > 1. What is BSS?
>
> In Short: If you're making an ASM program that uses a kernel (ie DoorOS,
> TEOS, etc) and you have data that doesn't need to be saved after the program
> runs, store it in BSS space.
>
> If the space is reserved outside the BSS block, then that space is reserved
> inside the program.  For every dc.b (value) you have, the program will be
> one byte larger.  If the program is stored in RAM, then the data stored in
> those byte(s) remain the next time you run that program (if it's stored in
> Archive memory, then no changes to that data will be remembered).
>
> BSS offers the advantage that any space reserved in it will not increase the
> size of the compiled program.  You could have an 800-byte program and 5,000
> bytes of data reserved in the BSS block, and the program will only be about
> 800 bytes.  The tradeoff is that BSS data require a kernel, are not
> remembered the next time you run the program, and must be initialized by the
> program (Xavier Vassor once said that BSS data are initialized to zero, but
> I haven't found that to be the case when I've used it).

There is a certain logic no not initalizing the BSS blocks; after all, how
should the kernel know what you are going to store there? It is still good
programming to make sure temp variables and stuff are initialized correctly in
your own program, too, just to be sure. :)

> Keep in mind that BSS data cannot be declared using the "dc.x ##" format,
> but must instead use "ds.x ##".  Mistakenly trying to use "ds.w 0" to
> reserve a single word with an initial value of zero, as you might do outside
> the BSS block, will reserve zero bytes, meaning any writes to that byte will
> actually right to the next byte (and give you a real headache when
> debugging).

IIRC data in the BSS can be declared both ways - it's just not initialized to
the value you specify. The space is reserved though.
And "ds.w 0" will never reserve a blank word (at least it never should... I
guess it's implementation-specific). "ds.x 7" will reserve a memory area of 7
x:es, (bytes, words or longwords).

> Use BSS when you can; it saves a lot of space.

Not always. Small temporary variables should be allocated on the stack (easier
in C than in asm, of course), but when moving variables in and out of the BSS
block I've noiticed that the program can shrink when moving in both directions.
Must have something to do woth the fact that BSS variables have to be accessed
with absolute addresses, whereas in-code variables can be accessed with fixed
addresses that are relocated - sometimes one is more space-efficient, sometimes
the other. It all depends on the code I guess...

> Asside to Sebastian: can you modify the old A68k assembler to generate an
> error or warning when it encounters "ds.x 0"?  I can't see any reason anyone
> would want to do that.
>
> > 2. does lea sprite(pc),a0 = move.l #sprite,a0 ?
>
> Not quite.  Functionally, they're identical.  But using lea with an address
> relative to PC will, I believe be a byte smaller (and faster?).  Use lea,
> not move.l.

You must use "move.l" with BSS variables though, since they aren't relative to
your code. I actually had to ask David about this once - still annoyed that I
couldn't figure it out myself :)

--
 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF v5.1 Quote follows:

"You like it?" he said to Mort, in pretty much the same tone of voice
people used when they said to St George, "You killed a *what*?"
        -- Mort tastes scrumble for the first time
           (Terry Pratchett, Mort)