Changes

Jump to: navigation, search

Assembler Basics

189 bytes added, 11:47, 24 January 2014
Format of an Assembly Language program
# Using a directive (in the example above, len line), or
# As a label (such as _start or msg in the example above). A label 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.
 
In the program above:
* .start is a directive (equivalent to the longer directive ".section .start") which specifies that the following instructions/data should be placed in the ".start" section of the output ELF file.
* .global (or .globl) is a directive which makes the following symbol visible to the linker. Otherwise, symbols are normally lost by link time. In this case, the linker needs to know the value of the special symbol _start in order to know where execution is to begin in the program (which is not always at the start of the .text section).
* .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.
* _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"
Note that symbols are not variables - they are constants that are calculated at compile-time.

Navigation menu