Changes

Jump to: navigation, search

Assembler Basics

353 bytes added, 21:48, 17 September 2014
Format of an Assembly Language program
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.
* .data is a similar directive which specifies that the following instructions/data should be placed in the .data section of the output ELF file. In the case of this program, they could alternately be placed in the .rodata section, which is for read-only data (data which is write-protected in memory), because the string is not modified by the program.
* .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.
Note that symbols are not variables - they are constants that are calculated at compile-time.
Note also that the syntax will vary from assembler to assembler and from architecture to architechturearchitecture.
<!--

Navigation menu