x86: lea asm-Instruktion

Gast #2115048
Lesenswert?

Hallo,
1
void test(void) {
2
    int x = 0xAB, y = 0xBA;
3
    int * px = &x;
4
}

gcc -c main main.c -Wall -std=c99
objdump -d main | grep -A 12 "<test>:"
1
08048406 <test>:
2
 8048406:  55                     push   %ebp
3
 8048407:  89 e5                  mov    %esp,%ebp
4
 8048409:  83 ec 10               sub    $0x10,%esp
5
 804840c:  c7 45 f4 ab 00 00 00   movl   $0xab,-0xc(%ebp)
6
 8048413:  c7 45 fc ba 00 00 00   movl   $0xba,-0x4(%ebp)
7
 804841a:  8d 45 f4               lea    -0xc(%ebp),%eax
8
 804841d:  89 45 f8               mov    %eax,-0x8(%ebp)
9
 8048420:  e8 dc ff ff ff         call   8048401 <run>
10
 8048425:  e8 d7 ff ff ff         call   8048401 <run>
11
 804842a:  c9                     leave  
12
 804842b:  c3                     ret


-$0xC%(epb) zeigt doch auf x

wieso braucht man lea?
wieso geht folgendes nicht ...

mov %(ebp), %eax
sub $0xC, %eax
#2115179
Lesenswert?

Georg A. schrieb:

> Speicher ja, Ausführungszeit wohl nicht. Jedenfalls nicht ab >Pentium...
> Das wird eh alles in Micro-Ops übersetzt.

Das schon. Aber fragt sich in welche. Da wird nämlich eine einzige 
3-Adress-Operation draus, und die ist meist schneller als 2 voneinander 
abhängige 2-Adress Operationen.

Speicheroperationen hat man so oder so nicht drin. Erst danach.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren