I am new to x86 assembly, and am having trouble finding resources on nested arrays and what they would look like when declared with something in c like: long arr[5][10];
. Can anyone provide a little insight into what the assembly would translate to? Thanks.

- 328,167
- 45
- 605
- 847

- 47
- 9
-
There is no concept of arrays in assembly - just raw memory. You allocate some memory (on the stack or the heap) and write data to it. – ForceBru Feb 20 '22 at 23:09
1 Answers
Did you try looking at compiler output? (https://godbolt.org/ / How to remove "noise" from GCC/clang assembly output?).
Bytes are just bytes; the assembler doesn't know or care how the instructions in your program are going to use them.
If this is at global scope, normally something like GAS .section .bss
; .zero 4*5*10
which is exactly identical to .zero 200
to reserve 200 bytes in the BSS. Or .comm arr, 200
to do the same thing without switching sections. There are many synonyms for .zero
/ .space
and so on to fill bytes, see the GAS manual.
Or in NASM, resd 5*10
in section .bss
. Or of course resq
if your long
is 64-bit.
As a local variable, that would just be part of the space reserved on the stack.
Assembly doesn't have types in the same sense that C does, so long arr[5][10]
is just a chunk of 200 or 400 bytes of memory, same as char arr[200]
or long arr[5*10]
. C integer types are a compile-time thing, influencing which instructions the compiler uses to access the data.

- 328,167
- 45
- 605
- 847