Apparently asm
/ assembly
has never(?) been supported as a syntax-highlighting language, and the somewhat decent highlighting we got in the past was from auto-detection (presumably as some other language with #
or ;
comment characters.)
highlight.js auto-detection happens to produce way worse results for assembly than whatever prettify.js did, so in practice there is a real regression here.
Assembly language really doesn't need much highlighting to be readable; it's already syntactically simple and has a regular line format. But it does benefit significantly from fading comments into a colour that stands out less than the rest of the code.
The rest of this answer was written without realizing asm wasn't (ever?) supported; the highlight.js languages including x86asm
are not enabled on Stack Overflow / SE, so of course using them doesn't help.
Language auto-detection for assembly language seems to be broken. For example, note the lack of highlighting in the question on Printing an integer as a string with AT&T syntax, with Linux system calls instead of printf. After editing my answer to use ```lang-assembly on the main code block, that block has highlighting but the others don't. (And does actually look decent.)
Separately, syntax highlighting for NASM (a different asm syntax that uses ;
as the comment character) is (was?) broken. In Unexpected result of subtracting a NASM macro in an expression, ```lang-nasm or lang-assembly leads to a mess that's arguably worse than nothing, because of single-quote used as English punctuation in a comment. Same result with <!-- language: lang-assembly -->
.
(Update: no longer as bad as a couple weeks ago. An apostrophe in comments seems to only affect the end of the contracted word, not the entire rest of the block. But this NASM syntax is block is still not very usefully highlighted, e.g. comments aren't grayed, and only the 0
in 0x..
is in red. At least it's not clearly or much worse than nothing. x86asm
is listed in the supported languages and highlight.js's x86 asm highlighter is supposed to be for NASM syntax. x86asm
results in no highlighting; I had to use lang-x86asm
to get the current highlighting.)
section .rodata ; groups read-only together inside the .text section msg: db "Thank you" var: db 0x34, 0x33, 0x32, 0x31 ; dd 0x31323334 ; Since you're passing these bytes to write(2), writing them separately is probably less confusing. (x86 is little-endian, so they will come out "backwards") ;; apparently you want to include var as part of the message, for some reason msglen equ $ - msg ; $ is the current position
Previously, this meta answer wasn't getting any syntax highlighting; that's changed now.
SO asm answers tend to be more heavily commented than you'd do in real life, because the target audience is people that don't understand the basics of asm. And SO code blocks are more cramped horizontally than a normal text editor so it encourages leaving comments closer to the end of the code, making it worse if they're visually harder to ignore. (Especially in some poorly formatted beginner questions and answers where comments are ragged and literally no space is left after instructions.)
Different flavours of assembly language use different comment characters, so this is a somewhat thorny problem. Some use #
to decorate numeric literals (e.g. ARM), so treating ;
, #
, and @
as comment characters won't always work.
As discussed in comments, highlight.js has highlighters for a few different asm syntaxes, no generic asm.
By looking at tags like [arm]
as well as [assembly]
, Stack Overflow should (in theory) be able to pick the right asm syntax highlighting.
For cases like explicit lang-asm
overrides in the markdown (which isn't explicit enough: doesn't say which flavour), Stack Overflow could (in theory) still auto-detect which syntax to highlight for based on the ISA tag. e.g. for a post with [c] [x86]
tags, a lang-asm
block could still pick x86 highlighting.
Except that doesn't disambiguate MASM vs. NASM vs. [gnu-assembler]
syntax, with GAS using a different comment character (#
) than most other x86 assemblers (;
). Many questions aren't tagged with a specific assembler syntax name, just x86. (Most non-x86 ISAs only have one syntax in wide usage; this is mostly an x86 problem.)
To make matters more complicated GAS .intel_syntax noprefix
still uses GAS directive and comment character, same as when GAS is in AT&T syntax mode. So [att]
syntax questions aren't the only ones where #
is the right comment character, even if we could rely on all questions that happen to use AT&T syntax being tagged [att]
.
But unless / until that happens, I guess we should be tagging asm blocks with one of:
lang-x86asm
lang-armasm
(I guess this is Keil's ARMASM for directive syntax, not GAS? Instruction syntax is the same between both, though.)lang-avrasm
I haven't dug into how Stack Overflow dispatches anything to those internally supported highlight.js things.