What's the difference between the following gas
assembly?
x: .long 500
And:
x = 500
Can both be used interchangeably or, if not, why is one preferred over the other?
They’re not interchangeable. The first one:
x: .long 500
creates a 4-byte space in memory initialized with the given value. The label x
represents the address of that memory location.
The second one:
x = 500
doesn’t create any memory. It sets the symbol x
to the value 500, not to an address.