1

Consider I have a label in assembly (at&t syntax, x86-64) like this:

test_tabel:
    mov test_label,%eax #1
    mov (test_label),%eax #2
    mov $test_label,%eax #3

Can someone kindly tell what's the difference between these three as I saw them a lot but can't really understand what each really means (address, value etc...)

Now in case I have a variable in .data section (let's suppose it's of size int ie 4 bytes) what's the difference between those 3:

mov var,%eax #4
mov var,%eax #5
mov $var,%eax #6
Dan
  • 99
  • 6
  • 1
    Didn't you mean your 5th line to read `mov (var), %eax`, with the parenthesis. You've made it identical to the 4th line! – Sep Roland Oct 07 '21 at 17:34
  • 1
    Note that `mov $test_label,%eax` may be a problem, since an address is generally 64 bits and you're loading it into a 32-bit register. Normally `lea test_label(%rip), %rax` should be used instead. – Nate Eldredge Oct 07 '21 at 17:52

1 Answers1

3

(1) and (2) are identical and load 4 bytes from memory at test_label into eax. (3) loads the address of test_label into eax.

A variable is just a label, so there's nothing special going on with your second set of examples.

(4) and (5) are identical to (1) and (2) in behaviour, (6) is identical to (3) in behaviour.

fuz
  • 88,405
  • 25
  • 200
  • 352