Search code examples
arraysassemblyx86nasmatt

Declaring Arrays In x86 Assembly


I am learning Assembly and I need to make a large array. I have looked around at how to declare arrays and I have come across this.

array db 10 dup(?)

Where an array of 10 uninitialized bytes is declared. I tried this and tried to assemble it and get "error: comma expected after operand 1". I realized that the '?' is not supported in x86 so I made it a constant and got the same error. I ended up doing this.

array db 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

This worked! But the problem is, I need large arrays (~100-400 integers) and their values will not always be known. I could write out 400 0's but I figured there must be an easier way. So is there a better way to declare large arrays?

I am using x86_64 Assembly on an Intel-Based Macbook Pro with AT&T syntax.


Solution

  • Did you try TIMES directive.Use this code for declaring an array of a given size.

    array TIMES 8 DB 0
    

    This will create an array of size 8

    Refer to this link for more.