Open main menu

CDOT Wiki β

Changes

Assembler Basics

510 bytes added, 21:44, 17 September 2014
Format of an Assembly Language program
An assembly-language program consists of:
# [[Symbol|Symbols]] that are constants which correspond to memory addresses , registers, or other values.
# Instructions - Mnemonics for an operation followed by zero or more arguments.
# Data - Values used by the program for things such as initial variable values and string or numeric constants.
<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="orange">1</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>
<font color="green">mov </font> $<font color="orange">0</font>,%<font color="blue">rdi </font> /* exit status */ <font color="green">mov </font> $<font color="orange">60</font>,%<font color="blue">rax </font> /* syscall sys_exit */ <font color="green">syscall</font>
<font color="red">.data</font>
In this program, which was written using GNU Assembler (gas) syntax, text is coloured according to its type:
* <font color="red">directives</font>
* <font color="green">instructions</font>
* <font color="blue">symbols</font>
* <font color="orange">expressions</font>
* <font color="black">other syntax elements, such as prefixes and separators</font>
A symbol may be set in one of two ways: