0

What are the various lengths of variable declarations in x86? The ones that I know of are:

  • .byte (1)
  • .int (2)
  • .long (4)
  • .quad (8)
  • .string, ascii, .word, .half (some aliases too?)

Is there a good reference that shows all the possible variable lengths you can declare in x86 (64)?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
David542
  • 104,438
  • 178
  • 489
  • 842
  • depends on the assembler.I assume you are talking about gas here? – old_timer Aug 28 '20 at 03:06
  • @old_timer yes, I can't find `gas` as a tag though in the question. – David542 Aug 28 '20 at 03:07
  • what did the assembler documentation say? – old_timer Aug 28 '20 at 03:07
  • @old_timer I couldn't find anything in `man` but here is a list of directives I could find from a google search: https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_7.html – David542 Aug 28 '20 at 03:10
  • @old_timer actually thanks for pointing out that it depends on the assembler. I've only ever used `gas` for assembling so I thought this was just an "assembly thing" and not necessarily tied to a specific assembler. – David542 Aug 28 '20 at 03:15
  • Man is not going to describe the language. Assembly language is specific to an assembler not the target. .byte and such leans toward this might have been gnu rather than say DB which is more of an older masm style for example. – old_timer Aug 28 '20 at 03:17
  • and these types of directives may vary by target within gas, so you have to be prepared for that too. – old_timer Aug 28 '20 at 03:17
  • https://sourceware.org/binutils/docs/as/Byte.html#Byte – old_timer Aug 28 '20 at 03:18
  • 1
    they are not really variables, that is a high level language concept. – old_timer Aug 28 '20 at 03:18
  • https://sourceware.org/binutils/docs/as/Word.html#Word The size of the number emitted, and its byte order, depend on what target computer the assembly is for. so within gas this one for example is dependent on the target. – old_timer Aug 28 '20 at 03:21
  • same for .int The byte order and bit size of the number depends on what kind of target the assembly is for. – old_timer Aug 28 '20 at 03:22
  • @old_timer thanks for your help. Want to post an answer and I can accept it? – David542 Aug 28 '20 at 04:28
  • The `gas` tag was renamed `gnu-assembler` because of conflict with Google Apps Script: [What can be done to prevent \[gas\] tag ambiguity?](https://meta.stackoverflow.com/q/399396) / [Rename \[gas\] to \[gnu-assembler\]](https://meta.stackoverflow.com/q/397525). Unfortunately "gas" doesn't even bring up gnu-assembler as an auto-complete option :/ – Peter Cordes Aug 28 '20 at 04:53
  • https://sourceware.org/binutils/docs/as/ is the current manual, links in https://stackoverflow.com/tags/x86/info. AFAIK, the largest directive is `.quad`. If you want wider, use multiple quad elements. So I don't think you could write a single decimal constant wider than 64 bits. (For hex it doesn't matter, you can split it up at any byte boundary without changing the digits.) – Peter Cordes Aug 28 '20 at 04:54
  • @PeterCordes thanks, here are the directives from your link: https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops. Are the `gas` directives similar to other assemblers, or is each a world of its own? – David542 Aug 28 '20 at 04:56
  • 2
    GAS is only similar to other traditional Unix assemblers, like classic MIPS assembler, in its directives. Most other x86 assemblers use `dd 1, 2` / `dq 1, 2` (e.g. NASM, which does support wider single chunks. However it still doesn't support integers constants wider than 64-bit. e.g. `do` (octword) / `dy` (ymmword 32 bytes) don't support integer constants as opernads. https://nasm.us/doc/nasmdoc3.html#section-3.2.1). MASM I think also supporting `DWORD 1, 2` etc. – Peter Cordes Aug 28 '20 at 05:00
  • Related: [What was the original reason for the design of AT&T assembly syntax?](https://stackoverflow.com/q/42244028) / [Questions about AT&T x86 Syntax design](https://stackoverflow.com/q/4193827) have some history, but mostly about the instruction syntax, not the directives. – Peter Cordes Aug 28 '20 at 05:03

0 Answers0