Open main menu

CDOT Wiki β

Changes

Assembler Basics

11 bytes added, 08:14, 22 September 2014
Format of an Assembly Language program
A symbol may be set in one of two ways:
# Using a directive (in the example above, len line), or
# As a label (such as _start or msg in the example above). A label set in this aay is identified by the trailing semi-colon, and is set to the current memory location in the instruction or data sequence. Labels may be used for loading/storing information, or as the target of branches/jumps.
* _start is a label which is equivalent to the memory location of the first instruction in the program.
* msg is a label which is equivalent to the memory location of the first byte of the string "Hello, World!\n"
* .set is a directive which sets a symbol (len) equal to the value of an expression (in this example, ". - msg" meaning the current memory location minus the value of the label "msg"). Note that the GNU assembler accepts <code>a=1</code> as equivalent to <code>.set a,1</code> -- both are counted as directives regardless of the presence of the <code>.set</code> keyword.
Note that symbols are not variables - they are constants that are calculated at compile-time. However, they may contain an address at which a variable is stored.