How to represent octal numbers in Assembly?

后端 未结 2 929
一生所求
一生所求 2020-12-21 07:04

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

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



        
相关标签:
2条回答
  • 2020-12-21 07:28

    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 x86 tag wiki for links to various assembler manuals (and lots of other useful resources and guides).

    0 讨论(0)
  • 2020-12-21 07:39

    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

    0 讨论(0)
提交回复
热议问题