3

I am studying x86_64 assembler (yasm) with this textbook. There I have met the following lines that define file access flags:

O_RDONLY        equ    000000q
O_WRONLY        equ    000001q
O_RDWR          equ    000002q

The question is what do their values mean? What q stands for?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
LRDPRDX
  • 631
  • 1
  • 11
  • 23

1 Answers1

10

In NASM/YASM it is a suffix that means the number is in Octal. From the documentation

3.5.1. Numeric Constants

A numeric constant is simply a number. NASM allows you to specify numbers in a variety of number bases, in a variety of ways: you can suffix H, Q or O, and B for hex, octal, and binary, or you can prefix 0x for hex in the style of C, or you can prefix $ for hex in the style of Borland Pascal. Note, though, that the $ prefix does double duty as a prefix on identifiers (see Section 3.1), so a hex number prefixed with a $ sign must have a digit after the $ rather than a letter.

Some examples:

mov ax,100              ; decimal
mov ax,0a2h             ; hex
mov ax,$0a2             ; hex again: the 0 is required
mov ax,0xa2             ; hex yet again
mov ax,777q             ; octal
mov ax,777o             ; octal again
mov ax,10010011b        ; binary
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • Strange I have not found the answer on the first google search page. But here is an extension of it: Is there some real reason to specify those constants in octal? Why do not do it in hex or dec? – LRDPRDX Mar 17 '18 at 17:52
  • @BogdanSikach They are probably made octal because privileges are usually expressed as octal values in the man pages. They could be expressed in bits or hex as well. It was just a developer's choice.I'm not sure of the reasoning. – Michael Petch Mar 17 '18 at 17:56
  • @BogdanSikach: presumably for consistency with other constants defined nearby. But note that `O_RDONLY` and other `O_` constants are mode args for [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html), not Unix file permission modes like 0664 (or 664q) for `chmod` / `stat` or for `umask`. – Peter Cordes Mar 17 '18 at 19:27