X86 Assembly/Comments

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

[edit] Comments

When writing code, it is very helpful to use some comments to explain what is going on. A comment is a section of regular text that the assembler ignores when turning the assembly code into the machine code. In assembly, comments are usually denoted with a semicolon ";". GAS uses "#".

Here is an example:

Label1:
   mov ax, bx    ;we move bx into ax
   add ax, bx    ;add the contents of bx into ax
   ...

Everything after the semicolon, on the same line, is ignored. Let's show another example:

Label1:
   mov ax, bx
   ;mov cx, ax
   ...

Here, the assembler never sees the second instruction "mov cx, ax", because it ignores everything after the semicolon.

[edit] HLA Comments

The HLA assembler also has the ability to write comments in C or C++ style, but we can't use the semicolons. This is because in HLA, the semicolons are used at the end of every instruction:

mov(ax, bx); //This is a C++ comment.
/*mov(cx, ax);  everything between the slash-stars is commented out. 
                This is a C comment*/

C++ comments go all the way to the end of the line, but C comments go on for many lines from the "/*" all the way until the "*/". For a better understanding of C and C++ comments in HLA, see Programming:C or the C++ Wikibooks.