Open main menu

CDOT Wiki β

Changes

Assembler Basics

122 bytes added, 15:51, 19 January 2016
Format of an Assembly Language program
<font color="red">.text</font>
<font color="red">.global</font> <font color="blue">_start</font>
<font color="blue">stdout</font> = <font color="orange">1</font>
<font color="blue">_start:</font>
<font color="green">mov</font> $<font color="blue">len</font>,%<font color="blue">rdx</font> /* message length */
<font color="green">mov</font> $<font color="blue">msg</font>,%<font color="blue">rsi</font> /* message location */
<font color="green">mov</font> $<font color="orangeblue">1stdout</font>,%<font color="blue">rdi</font> /* file descriptor stdout */
<font color="green">mov</font> $<font color="orange">1</font>,%<font color="blue">rax</font> /* syscall sys_write */
<font color="green">syscall</font>
A symbol may be set in one of two three ways:# Using a directive (in the example above, len line)# Using an assignment (in the example above, orstdout line)
# As a label (such as _start or msg in the example above). A label set in this way is identified by the trailing 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.