4

For example for hexadecimal numbers we can use 0x98398 or 8790h.

How can octal numeric constants be written? Does this work?

mov eax, 70o
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ehsan Akbari
  • 51
  • 1
  • 3

2 Answers2

8

NASM supports 70o, 70q, 0o70, and 0q70 for octal.

I'd recommend the 0q70 version, to avoid the risk of future (human) readers mistaking the lower-case-o for a zero. I'm not a fan of the trailing suffix style for hex, either, because it's easy to miss. It helps to use the opposite case from the rest of the constant, but a leading 0x or 0q is clearer. (And for hex, avoids the need for a leading 0 to make it a numeric constant instead of a symbol name.)

As for hex-constant support, it will certainly vary by assembler, so just check your assembler manual. e.g. most DOS/Windows-only assemblers don't support 0xDEADBEEF, only 0DEADBEEFh style, so I'd guess they have fewer options for octal, too.

See the tag wiki for links to various assembler manuals (and lots of other useful resources and guides).

Community
  • 1
  • 1
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    Just an observation that if you are using YASM `0q` and `0o` prefix won't work. – Michael Petch Sep 22 '18 at 19:27
  • ps: I've found the trailing h notation nice for multiple short 2-digit hex constants; it visually gets out of the way nice, especially if none of them need an extra leading 0 like 0FFh vs. 0xFF. For octal, you're even more unlikely to just want 2 digits, and octal constants will be rare in most code (e.g. just a file mode) so use something as obvious as possible. – Peter Cordes Jun 02 '23 at 06:22
2

Depends on the assembler, but most of the assemblers including NASM allow 0o, o standing for octal. Just like you use 0x where x stands for Hexadecimal.

    mov     ax,310q         ; octal 
    mov     ax,310o         ; octal again 
    mov     ax,0o310        ; octal yet again 
    mov     ax,0q310        ; octal yet again 

Source of information: Here .

Again it's not 0o or the syntax above for all assemblers. It might vary by assemblers , but NASM does indeed use the above-mentioned syntax as you can see the link provided for more information. If you have other assemblers in mind, check out their manuel like for FASM: Here . GAS: Here

Loquitor
  • 19
  • 6
amanuel2
  • 4,508
  • 4
  • 36
  • 67