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 10 14 18 1c 20 24 28 2c 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 10 14 18 1c 20 24 28 2c 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 i10 10 14 18 1c 20 24 28 2c 30 34

10 Lect3-10 Position independent code i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i10 10 14 18 1c 20 24 28 2c 30 34 i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i10 10 14 18 1c 20 24 28 2c 30 34 38 3c 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 i10 10 14 18 1c 20 24 28 2c 30 34 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 10 14 18 1c 20 24 28 2c 30 34 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 10 14 18 22 26 30 34 38 42 46 50 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 00000108 esp ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 0000030f 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 00000006 eax ???????? ebx ???????? edx 00000108 esp ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 00000314 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 00000006 eax ???????? ebx ???????? edx 00000104 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314` 319: 00000300 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 00000006 eax ???????? ebx ???????? edx 00000104 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 00000302 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 00000006 eax ???????? ebx ???????? edx 00000104 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 00000307 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 00000006 eax 00000005 ebx ???????? edx 00000104 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 0000030c 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 0000001e eax 00000005 ebx 00000000 edx 00000104 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 0000030e 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 0000001e eax 00000005 ebx 00000000 edx 00000108 esp ???????? 00000319 ???????? 100 104 108 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: 00000319 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 0000001e eax 00000005 ebx ???????? edx 00000108 esp edx 0000031c ???????? 100 104 108 300: 301: 303: 305: 307: 308 309: 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 0000001e eax ???????? ebx ???????? edx ???????? 0f8 edx ret address ???????? 100 104 108 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 00000006 ???????? 100 104 108 ???????? 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 ???????? 100 104 108 ???????? 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 00000006 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 0 1 2 3 4 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 1 3400 Pentium 4 EE1705 1500 Itanium 22161 2 3200 Pentium 4 Xeon1563 1700 POWER4+1776 3 2200 Opteron1477 3400 Pentium 4 EE1561 4 2200 Athlon 64 FX1447 2200 Opteron1514 5 3200 Pentium 4 E1421 1150 Alpha 213641482 6 3000 Pentium 4 Xeon MP1408 3200 Pentium 4 E1441 7 1500 Itanium 21404 2200 Athlon 64 FX1423 8 3400 Pentium 41393 1250 Alpha 21264C1365 9 2000 Athlon 641335 1320 SPARC64 V1350 10 1700 POWER4+1158 3200 Pentium 4 Xeon1347 11 2200 Athlon XP1080 2800 Pentium 41327 12 1250 Alpha 21264C928 3000 Pentium 4 Xeon MP1283 13 1350 SPARC64 V905 1300 POWER41281 14 1150 Alpha 21364877 2000 Athlon 641250 15 1300 POWER4848 1200 UltraSPARC III Cu1118 16 2000 Athlon MP766 1280 UltraSPARC IIIi1063 17 1200 UltraSPARC III Cu722 2200 Athlon XP982 18 1280 UltraSPARC IIIi704 833 Alpha 21264B784 19 1000 Pentium M687 800 Itanium701 20 875 PA-RISC 8700+678 875 PA-RISC 8700+674

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 05 02 00 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 w word 1 data 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 opcode add immediate to accumulator 0 0 0 0 0 1 0 add ax,2

48 Lect3-48 Instruction description SUB subtract O D I T S Z A P C 001010dwoorrrmmm disp * * * * * * ea=5  14 sub r,r sub r,m sub m,r 8088 3 13+ea 24+ea 8086 3 9+ea 16+ea 80286 2 7 7 80386 2 7 6 80486 1 2 3 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