1
votes

Can I use semicolons in GAS for comment characters?

I am using GAS 2.30 with the Intel syntax as below.

.intel_syntax noprefix

.section .text

# Program entry point
.globl _start

_start:

    # Put the code number for system call
    mov eax, 1

    # Return value
    mov ebx, 0

    # Kernel call
    int 0x80

This works nicely except that I have to use '#' as a comment character instead of ';'.

The main reason why it matters is that the editor that I have (SublimeText 3.2.2, build 3211) only has syntax highligting for ARM or NASM assembly syntax, neither of which understands '#' for comments and as I am following materials that mainly use Intel syntax, this is something I would just like to keep consistent with what I am reading about.

I checked the Intel manuals, the 5000+ pages PDF document, and unless I missed it somehow, it says nothing about comments although an introductory page by Intel uses semicolons for comments.

My question is if there is maybe a switch to let GAS use semicolons instead of pound signs in this context or is that perhaps one of the little differences to simply get used to?

I understand that GAS will also accept /, // and /* */ but none of these is understood by SublimeText.

Interestingly enough, telling SublimeText to use Bash syntax highlighting is quite a good solution as in the screenshot below but perhaps there is a way to configure GAS to use semicolons too? Thanks.

GAS assembly syntax highlighting in SublimeText

1
You can't switch the comment character, but you could preprocess the file if you really wanted. I assume it's simpler to edit the syntax highlight configuration. You could also just use nasm if there is proper highlighting for that. Note that directives also differ and probably break highlighting anyway for gas.Jester
@Jester - Thanks. In addition to various tutorials, the main book that I am reading is "Modern X86 Assembly Language Programming" which uses MASM whereas I am on Linux. GAS with Intel syntax seems to be closer to MASM than NASM and that is one of the reasons why I am using GAS, i.e. among other things, I want to minimise the number of changes to code samples I have to make while reading the book.user14222280
you can do something like ;# or #; and see if your syntax highlighter is happier.old_timer
intel docs are going to be related to whatever intel assembler they created or maintain, assembly language is specific to the tool not the target, so gas assembly is not expected to be identical to any other. if it happens to be then great, but if not then that is expected. they like to use the semicolon to separate instructions mov eax,1 ; mov ebx 0, possibly for inline assembly that is fed into the assembler after preprocessing. even though historically a lot of assembly languages used it for comments.old_timer
It seems like the gas folks have a habit of insuring that gas assembly language is incompatible with the native tool from the processor vendor, just part of life, take it or leave it.old_timer

1 Answers

3
votes

No, gas has no command-line switch or directive for this. The comment characters are hardcoded.

However, it looks like it wouldn't be too hard to change them in the gas source and compile a custom version, if you really want that. At a glance you would want to add ; to i386_comment_chars and line_comment_chars, and remove it from line_separator_chars.