Presentation is loading. Please wait.

Presentation is loading. Please wait.

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.

Similar presentations


Presentation on theme: "University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture."— Presentation transcript:

1 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture

2 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 2 Intel Processors A stable platform for nearly 20 years –8086 (1978) 8 bits –80186 (1980) 8 or 16 bits –80286 (1982) 16 bits –80386 (1985) 32 bits (33 MHz) –Pentium 4 (2001) 32 bits (3.2 GHz)

3 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 3 Micro-instructions The ‘invoer’ is moved from memory to two registers (a,d), followed by operation subl int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl%ebp movl%esp, %ebp movl12(%ebp), %edx movl8(%ebp), %eax subl%edx, %eax popl%ebp ret Register file ALU Gcc -S

4 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 4 Disassemblers Objdump –d subtract.o │ gdb>disas subtract (page 205) 00000022 : 22:55 push %ebp 23:89 e5 mov %esp,%ebp 25:8b 55 0c mov 0xc(%ebp),%edx 28:8b 45 08 mov 0x8(%ebp),%eax 2b:29 d0 sub %edx,%eax 2d:5d pop %ebp 2e:c3 ret 2f:90 nop The ‘l’ behind subl is omitted (refers to the standard 32-bits dataformat of IA32: ‘long word’ {int, float, pointer})

5 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 5 Procedure call Stack is part of virtual memory Every called procedure gets frame on the stack Kernel virtual memory Memory mapped region for shared libraries Run-time heap (created at runtime by malloc) User stack (created at runtime) Unused 0 Memory invisible to user code 0xc0000000 0x08048000 0x40000000 Read/write data Read-only code and data Loaded from the hello executable file printf() function 0xffffffff Calling procedure push parameter2 on stack Push parameter1 on stack Call subroutine Clean parameters off stack

6 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 6 Stack-based languages Languages that Support Recursion –e.g., C, Pascal, Java –Code must be “Reentrant” Multiple simultaneous instantiations of single procedure –Need some place to store state of each instantiation Arguments Local variables Return pointer Stack Allocated in Frames –state for single procedure instantiation

7 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 7 Stack Frames (gdb) info stack #0 subtract() #1 main() (gdb) up / down (gdb) info frame pointers Arglist Locals Saved registers Stack Pointer ( %esp ) Frame Pointer ( %ebp ) Return Addr Saved Registers + Local Variables Argument Build Old %ebp Arguments Caller Frame Older Frames

8 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 8 Call Chain Example Code Structure yoo(…) { who(); } who(…) { amI(); amI(); } amI(…) { amI(); } yoo who amI Call Chain –Procedure amI recursive amI

9 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 9 Stack Pointer %esp yoo %ebp Stack Operation yoo Call Chain yoo(…) { who(); }

10 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 10 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); }

11 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 11 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); }

12 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 12 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

13 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 13 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

14 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 14 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

15 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 15 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

16 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 16 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); } amI

17 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 17 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who Call Chain amI(…) { } amI

18 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 18 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); } amI

19 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 19 yoo(…) { who(); } Stack Pointer %esp yoo %ebp Stack Operation yoo who Call Chain amI

20 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 20 Machine language Calling routine push parm2 push parm1 call subroutine Callee push %ebp mov %esp, %ebp …. body of subroutine pop %ebp ret Current frame Caller’s frame Saved %ebp Saved registers, local variables, and temporaries Argument build area Return address Argument 1 Argument n Frame pointer %ebp Stack pointer %esp Stack “top” Stack “bottom” Increasing address +4 +8 +4+4n –4 Earlier frames

21 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 21 Subroutine Call and Return –Push address of next instruction onto stack –Start executing instructions at Dest –Pop value from stack –Use as address for next instruction call Dest 80 Dest ret 90

22 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 22 IA32/Linux Register Usage Integer Registers –Two for the stack %ebp, %esp –Three are callee-save %ebx, %esi, %edi save on stack prior to using –Three are as caller-save %eax, %edx, %ecx save on stack prior to calling subroutine –Register %eax also stores returned value %eax %edx %ecx %ebx %esi %edi %esp %ebp Caller-Save Temporaries Callee-Save Temporaries Special

23 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 23 Summary The Stack Makes Recursion Work –Private storage for each instance of procedure call Instantiations don’t clobber each other Addressing of locals + arguments can be relative to stack positions –Can be managed by stack discipline Procedures return in inverse order of calls Added as wrapper around ‘your’ code by compiler

24 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 24 Summary IA32 Procedures Combination of Instructions + Conventions –Call / Ret instructions –Register usage conventions Caller / Callee save %ebp and %esp –Stack frame organization conventions

25 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 25 Conclusion We understand know how the simplest of subroutines is translated in micro- instructions int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl%ebp movl%esp, %ebp movl12(%ebp), %edx movl8(%ebp), %eax subl%edx, %eax popl%ebp ret Gcc -S

26 University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 26 Assignment Practice Problem 3.2 (page 142) 1.Movl $0x4050, %eaxImmediate → Register 2.Movl %ebp, %espRegister → Register 3.Movl (%edi,%ecx), %eaxMemory → Register 4.Movl $-17, (%esp)Immediate → Memory 5.Movl %eax, -12(%ebp)Register → Memory


Download ppt "University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture."

Similar presentations


Ads by Google