Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASM: too many memory references for `mov'

It's me again, I have a new problem in my idt.S file (Intel syntax compiled with gcc). When I try to compile the following code:

load_idt:
        mov edx, (esp + 4) ; On this line
        lidt (edx)
        sti
        ret

I get an error that I really don't know how to fix:

Error: too many memory references for `mov'
like image 820
xSlendiX Gaming Avatar asked Mar 03 '19 15:03

xSlendiX Gaming


1 Answers

If you are assembling with GCC using something like:

gcc -c -m32 -masm=intel idt.S -o idt.o

The problems are:

  • You will need to add the directive .intel_syntax noprefix to the top of your file. By default GCC assembles .s and .S files assuming Intel syntax requires the % prefix on all the registers. That directive eliminates that requirement.
  • In Intel syntax memory operands use square brackets [ and ] rather than parentheses ( and ).
  • Comments start with # instead of ;.

The code should look like:

.intel_syntax noprefix

load_idt:
        mov edx, [esp + 4] # On this line
        lidt [edx]
        sti
        ret
like image 168
Michael Petch Avatar answered Oct 22 '22 11:10

Michael Petch