0

I have a line of assembly code below (in AT&T assembly lang):

movl myvar, %eax

I am a bit confused as to how this would work because %eax is a 32-bit register and myvar seems like a label which is basically an address. Can you store addresses in registers?

For instance, lets say myvar is a label with an address like 1234. Wouldn't that line of code be saying movl 1234, %eax? Can that 1234 which is a memory address be stored in %eax without having to do movl $1234, %eax or movl $myvar, %eax?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • it's x86 assembly. AT&T is just a syntax, x86 is the architecture – phuclv Mar 11 '22 at 17:00
  • 1
    Yes, you can store an address in a register. But that's not what that instruction does. It reads the contents of memory at that address and puts the value in eax. To put the address in eax, you would use $, as in your last sentence. – prl Mar 11 '22 at 17:01
  • Related: [How to load address of function or label into register](https://stackoverflow.com/q/57212012) but that's for x86-64. It only mentions `mov $myvar, %eax` as an option for non-PIE 64-bit executables on Linux (where static addresses are in the low 32). – Peter Cordes Mar 11 '22 at 17:04
  • Also, when a register is a destination, it's normally called a *load*. e.g. your instruction loads from memory into EAX. With `mov $myvar, %eax`, you'd be loading an immediate constant (the symbol address). – Peter Cordes Mar 11 '22 at 17:06

0 Answers0