4.3 Memory allocation

This section is now obsoleted by section 4.5. Skip it!

I mean it, skip this section!

Since we have already discussed memory addressing modes, it is only appropriate to start discussing how memory is allocated (reserved) in an assembly program.

The .comm and .lcomm directives are used to reserve a number of bytes in a program. The following is an example:

.lcomm dogBiscuit 20

This code reserves 20 bytes and give the address of the first byte a symbolic name of dogBiscuit. You can also do the same with .comm:

.lcomm dogBiscuit 20

The difference between .comm and .lcomm is that .lcomm defines local symbols, while .comm defines gloabl symbols. In the context of assembly programs, local means local to the source file, and global means global to all other files that will be linked by ld.

In general, you should use .lcomm by default. Exposing symbolic names without good reason can lead to lots of problems down the line. Not exposing symbols when they should have been simply results in linker errors, which are relatively easy to fix (compared to accessing the wrong chunk of memory when a program runs).

Copyright © 2009-04-16 by Tak Auyeung