Re: Feature Request: Add Intel/NASM Syntax Option for Inline Assembly
LIU Hao via Gcc-help <[email protected]> Tue, 16 Dec 2025 10:10:10 +0800
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
在 2025-12-16 06:42, Tadeo The rocket builder via Gcc-help 写道:
> Would it be possible to add support for Intel syntax in inline assembly?
> For example:
> - Keep the existing __asm__ keyword with AT&T syntax for compatibility
> - Add a new keyword like __asm_intel__ or __asmnasm__ for Intel/NASM syntax
> - Or add a syntax flag/attribute to switch between syntaxes
>
> This would greatly help OS developers who primarily use NASM for their .asm
> files and want consistent syntax when using inline assembly in C code.
NASM is essentially a new dialect. Given how assembly templates are hard-coded in GCC source, it would
require adding a third dialect here and there.
Besides, GCC passes inline assembly to the assembler without parsing, so it doesn't do translation; in
that case you need Clang, which does not support NASM syntax either.
> I'm currently developing CoolisOS (an x86-64 operating system) and this
> feature would make the codebase more maintainable.
>
> Thank you for considering this request!
My best advice is to build everything with `-masm=intel` and stick to MASM syntax; it's supported by all
compilers and provides best compatibility.
There's a pitfall, however:
MASM: vaddps ymm0, ymm1, DWORD BCST [rax]
LLVM: vaddps ymm0, ymm1, DWORD PTR [rax]{1to8}
NASM: vaddps ymm0, ymm1, DWORD [rax]{1to8}
GAS accepts both MASM and LLVM syntax, but all the other assemblers choke on each other's syntax. It's
quite tricky.
--
Best regards,
LIU Hao
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEYmSQWY4DEzq4FUs4hfveZl3ogBsFAmlAv4IFAwAAAAAACgkQhfveZl3ogBu8 qw/8D2U2CEHK7ZHx3e1Ap0/EA31Ht9IHyLho/fi7EnDu/9YBzzMF0mbYpyg/j1p5oD2tKqb4mLT8 UtLorrwByqqsMJIOoGR55Sq82lhDhv0qKkvSbPycvDmhhHegZ/kZMC/x+yHHBbbL3h6wOez9UlOp AqrQvbyjChHeCSfbmtsdEVkWY4G8hnUvD5MhddtCbjiv6XFQMHunnr/NK5ttDNDvi5YK4tHC8Bb0 fEyQA11WjcR3olooSx2RTdXlgcPAl/znz7LqJyEtta8xhqa9d9f7yZo9LL0qDJ0T4JlY6+L7BI3i qNx49kluWHMlBVjeS5RGTB4zhnBStT/iCf0Yrp6J3Mni9WGfQHuBncvnCkrAAS4wEYA2DkWafpUL IeiglKOvJufIUE6dFvvNZ3NmU8TahlN1tSjBNQFBeaAo4OgU6cioMbTg58Iw3dhDiB5wEGYBStZ2 yyIHdduHoUJBRYWXLmqDyAzN8vJQjM5qwiLhjNHckt+zB7x8hHOfHIh71NgzLGyXNQQF6uTNcCv7 fGw7qfpH9ofEMlAoKQJpdiTnw+QCNbzr692NL6s2bN77m6K6PImQpq0mHpgQdzRhaFDxRI+SFkTw Xhk7ggCCsyF3wHB05FtJR4lO+UmDuQmRUSX10LUet6nhhfeNNNjJh2SzogIgVJw1cLc5+Uoevc/V LZM= =PPxJ -----END PGP SIGNATURE-----