Dear stack overflow users!
Trying to learn assembly here, and I have stumbled upon the fact that thus far, I have found three ways to create variables using assembly(AT&T syntax):
.equ
makes a variable
.skip
reserves a specific amount of storage for a variable
.quad/long/word/byte
creates a small variable.
The only difference I have gathered thus far, is that the .quad
method could lead to the variable getting executed under specific conditions(and that .skip
kind of works like heap memory? I think?).
So at the very least, I wanted to know, are there any reasons to use any specific method? And which one do you think is the best to use to store things like strings, integers, and maybe some input from the user?
Edit: following fuz's explanation, I have constructed the following code, to test the differences:
.data
bar: .int 128
.equ bob, 128
.bss
buf: .skip 128
buf1: .skip bar
buf2: .skip bob
.text
.global main
main:
mov $256, %rax
mov %rax, bar
mov %rax, bob
mov %rax, buf
ret
Expected behaviour:
All works except for buf1: .skip bar
, and mov %rax, bob
.
Actual behaviour:
All works except for buf1: .skip bar
. The error test.s:11: Error: .space specifies non-absolute value
has appeared.
Questions:
Why was I able to change bob
at runtime?