[A89] Re: dumb assembly questions
[Prev][Index][Thread]
[A89] Re: dumb assembly questions
> 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).
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).
Use BSS when you can; it saves a lot of space.
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.
-Scott