Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lect3-1 Lecture 3: control transfer instructions ICT Software & Data processing Postacademic course in ICT Part I: The hardware-software interface Module.

Similar presentations


Presentation on theme: "Lect3-1 Lecture 3: control transfer instructions ICT Software & Data processing Postacademic course in ICT Part I: The hardware-software interface Module."— Presentation transcript:

1 Lect3-1 Lecture 3: control transfer instructions ICT Software & Data processing Postacademic course in ICT Part I: The hardware-software interface Module 1: Computer architecture Prof. Koen De Bosschere Electronics Dept Ghent University

2 Lect3-2 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

3 Lect3-3 Jumps Unconditional jumps Conditional jumps Computed jumps

4 Lect3-4 Unconditional Jumps i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp 20 i10 jmp address c c 30 34

5 Lect3-5 Conditional jumps i1 jle 24 i3 i4 jmp 2c i6 i7 i8 i9 i10 i1 jle 24 i3 i4 jmp 2c i6 i7 i8 i9 i10 Basic blocks c c 30 34

6 Lect3-6 Jump conditions (1) instructionjump jzjump if zero jcjump if carry jojump if overflow jsjump if sign jnzjump if not zero jncjump if not carry jnojump if not overflow jnsjump if not sign

7 Lect3-7 Jump conditions (2) instructionjump jgjnlejump if greater jge jnljump if greater or equal jljngejump if less jlejngjump if less or equal jejump if equal jajnbejump if above jaejnbjump if above or equal jbjnaejump if below jbejnajump if below or equal binary 2’s complement

8 Lect3-8 Static vs. Computed address jmp 100mov ebx,100 jmp ebx

9 Lect3-9 Absolute vs. relative address Absolute jump to address n Relative jump n bytes further/back i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i c c 30 34

10 Lect3-10 Position independent code i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i c c i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i c c c 2c

11 Lect3-11 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

12 Lect3-12 Loop instruction i1 i2 mov ecx,5 i4 i5 i6 i7 i8 loop 1c i c c loop address Decrement ecx Jump to address if ecx <> 0 loop

13 Lect3-13 Programmed loop i1 i2 mov ecx,5 i4 i5 i6 i7 i8 sub ecx,1 jnz 1c c c loop

14 Lect3-14 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

15 Lect3-15 Function call ca5-15 i1 i2 call 34 i4 i5 i6 i7 i8 i9 i10 ret i1 i2 call 34 i1 i2 call 34 i7 i8 i9 i10 ret i7 i8 i9 i10 ret i4 i5 i6 i4 i5 i6

16 Lect3-16 Function call and return int fivefold(int n) { if (n > 0) return n * 5; else return 0; } int g; main() { g = fivefold(6 ); } int fivefold(int n) { if (n > 0) return n * 5; else return 0; } int g; main() { g = fivefold(6 ); }

17 Lect3-17 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax ???????? eax ???????? ebx ???????? edx esp ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: f eip s=? z=?

18 Lect3-18 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax eax ???????? ebx ???????? edx esp ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: eip s=? z=? push 319 jmp 300

19 Lect3-19 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax eax ???????? ebx ???????? edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314` 319: eip s=? z=?

20 Lect3-20 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax eax ???????? ebx ???????? edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: eip s=0 z=0

21 Lect3-21 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax eax ???????? ebx ???????? edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: eip s=0 z=0

22 Lect3-22 Code fivefold: cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax eax ebx ???????? edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: c eip s=0 z=0

23 Lect3-23 Code fivefold : cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax e eax ebx edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: e eip s=0 z=0

24 Lect3-24 Code fivefold : cmp eax,0 jg positive xor eax, eax ret positive: mov ebx, 5 imul ebx ret main: mov eax, 6 call fivefold mov g, eax e eax ebx edx esp ???????? ???????? : 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: eip s=0 z=0

25 Lect3-25 Saving registers fivefold : push edx cmp eax,0 jg positive xor eax, eax pop edx ret positive: mov ebx, 5 imul ebx pop edx ret main: mov eax, 6 call fivefold mov g, eax e eax ebx ???????? edx esp edx c ???????? : 301: 303: 305: 307: : 30e: 310: 311: 312: 317: 31c: ???????? 0fc s=0 z=0

26 Lect3-26 Saving registers fivefold: push edx push ebx cmp eax,0 jg positive xor eax, eax pop ebx pop edx ret positive: mov ebx, 5 imul ebx pop ebx pop edx ret main: mov eax, 6 call fivefold mov g, eax e eax ???????? ebx ???????? edx ???????? 0f8 edx ret address ???????? ebx 0fc s=0 z=0

27 Lect3-27 Control Flow Graph fivefold: push edx push ebx cmp eax,0 jg positive positive: mov ebx, 5 imul ebx pop ebx pop edx ret xor eax, eax pop ebx pop edx ret

28 Lect3-28 Control Flow Graph positive: push edx push ebx mov ebx, 5 imul ebx pop ebx pop edx ret xor eax, eax ret fivefold: cmp eax,0 jg positive

29 Lect3-29 Control Flow Graph positive: push edx mov edx, 5 imul edx pop edx ret xor eax, eax ret fivefold: cmp eax,0 jg positive

30 Lect3-30 Parameter Passing via stack fivefold: mov eax,[esp+4] cmp eax,0 jg positive xor eax, eax ret 4 positive: mov ebx, 5 imul ebx ret 4 main: push 6 call fivefold mov g, eax ret address ???????? ???????? 0fc esp

31 Lect3-31 Local Variables int fivefold(int n) { int result; if (n > 0) result = n * 5; else result = 0; return result; } int g; main() { g = fivefold(6); } int fivefold(int n) { int result; if (n > 0) result = n * 5; else result = 0; return result; } int g; main() { g = fivefold(6); }

32 Lect3-32 Local Variables fivefold: sub esp,4 cmp eax,0 jg positive xor eax,eax mov [esp], eax jmp end positive: mov ebx, 5 imul ebx mov [esp], eax end: mov eax,[esp] add esp,4 ret main: mov eax, 6 call fivefold mov g, eax ???????? ret address ???????? ???????? 0fc esp

33 Lect3-33 Control Flow Graph fivefold: sub esp,4 cmp eax,0 jg positive positive: mov ebx, 5 imul ebx mov [esp],eax xor eax, eax mov [esp],eax jmp end end: mov eax,[esp] add esp,4 ret

34 Lect3-34 Complete Picture fivefold: push ebx push edx sub esp, 4 mov eax, [esp+10] cmp eax,0 jg positive xor eax,eax mov [esp], eax jmp end positive: mov ebx, 5 imul ebx mov [esp], eax end: mov eax,[esp] add esp, 4 pop edx pop ebx ret 4 main: push 6 call fivefold mov g, eax result edx ebx ret address esp esp+4 esp+8 esp+c esp+10 stack frame

35 Lect3-35 Stack frames p1 p2 p3 p4 Activation tree

36 Lect3-36 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

37 Lect3-37 Interrupts Jump to a routine via a number instead of an address The addresses of the routines are stored in an address table (the so-called vector table) Used to catch errors, or as an interface to the operating system

38 Lect3-38 Interrupts i1 i2 i3 i4 i5 i6 i7 i8 int 2 i10 i11 int 3 t i1 i2 i3 i4 i5 i6 Interrupt routine 3 Vector table

39 Lect3-39 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

40 Lect3-40 System operations Controlling the machine: manipulation of the processor state –interrupts on/off –changing the privilege level –halt instruction –switching from big-endian to little-endian –memory management (caches, virtual memory, etc.)

41 Lect3-41 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

42 Lect3-42 MIPS & MFLOPS MIPS: Million instructions per second MFLOPS: Million floating point operations per second Problems: –Depends on the architecture (multiply accumulate = 1 or 2 instructions?) –Depends on de the program

43 Lect3-43 Benchmark programs The only reliable performance metrics = execution time Always mention the program + input? Ideally: your own application Difficult to realize (porting) That’s why ‘typical programs’ are used: benchmarks

44 Lect3-44 Benchmark programs Whetstone, Dhrystone EEMBC, Mediabench TPC-benchmarks SPEC (Standard Performance Evaluation Corporation): Spec92, Spec95, Spec2000, Spec2006 (SpecInt, SpecFp, SpecRate) Ziff-Davis

45 Lect3-45 #MHz Processor int peak MHz Processor fp peak Pentium 4 EE Itanium Pentium 4 Xeon POWER Opteron Pentium 4 EE Athlon 64 FX Opteron Pentium 4 E Alpha Pentium 4 Xeon MP Pentium 4 E Itanium Athlon 64 FX Pentium Alpha 21264C Athlon SPARC64 V POWER Pentium 4 Xeon Athlon XP Pentium Alpha 21264C Pentium 4 Xeon MP SPARC64 V POWER Alpha Athlon POWER UltraSPARC III Cu Athlon MP UltraSPARC IIIi UltraSPARC III Cu Athlon XP UltraSPARC IIIi Alpha 21264B Pentium M Itanium PA-RISC PA-RISC

46 Lect3-46 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

47 Lect3-47 Instruction decoding w word 1 data opcode add immediate to accumulator add ax,2

48 Lect3-48 Instruction description SUB subtract O D I T S Z A P C dwoorrrmmm disp * * * * * * ea=5  14 sub r,r sub r,m sub m,r ea 24+ea ea 16+ea Pentium 1 2 3

49 Lect3-49 Overview Jumps Loops Procedure call and return Interrupts System operations Measuring performance Instruction decoding Compilers, linkers, and loaders

50 Lect3-50 object file object files Program development source compiler object file linker libraries executable file

51 Lect3-51 Compiler Different phases –Lexical analysis: a, 12, then, (, while –Syntactic analysis: if (a>b) then … –Semantic analysis: type-checking –Optimization –Code generation –Scheduling

52 Lect3-52 Object file object file instructions extra information global variables

53 Lect3-53 Linker linker

54 Lect3-54 Loader loader stack heap memory Dynamically allocated memory


Download ppt "Lect3-1 Lecture 3: control transfer instructions ICT Software & Data processing Postacademic course in ICT Part I: The hardware-software interface Module."

Similar presentations


Ads by Google