1 / 54

Lecture 3: control transfer instructions

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

jemima
Download Presentation

Lecture 3: control transfer instructions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Jumps • Unconditional jumps • Conditional jumps • Computed jumps

  4. Unconditional Jumps 10 i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp 20 i10 14 jmp address 18 1c 20 24 28 2c 30 34

  5. Conditional jumps i1 jle 24 10 i1 jle 24 i3 i4 jmp 2c i6 i7 i8 i9 i10 14 18 1c i3 i4 jmp 2c i6 i7 20 24 28 2c i8 i9 i10 30 Basic blocks 34

  6. Jump conditions (1) instruction jump jz jump if zero jc jump if carry jo jump if overflow js jump if sign jnz jump if not zero jnc jump if not carry jno jump if not overflow jns jump if not sign

  7. Jump conditions (2) instruction jump jg jnle jump if greater jge jnl jump if greater or equal jl jnge jump if less jle jng jump if less or equal je jump if equal ja jnbe jump if above jae jnb jump if above or equal jb jnae jump if below jbe jna jump if below or equal 2’s complement binary

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

  9. Absolute vs. relative address 10 i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i10 14 • Absolute jump to address n • Relative jump n bytes further/back 18 1c 20 24 28 2c 30 34

  10. 2c Position independent code 10 10 14 i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i10 14 18 i1 jmp 24 i3 i4 i5 i6 i7 i8 jmp pc-10 i10 18 1c 1c 20 20 24 24 28 28 2c 2c 30 30 34 34 38 3c

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

  12. loop Loop instruction 10 loop address i1 i2 mov ecx,5 i4 i5 i6 i7 i8 loop 1c i10 14 Decrement ecx Jump to address if ecx <> 0 18 1c 20 24 28 2c 30 34

  13. loop Programmed loop 10 i1 i2 mov ecx,5 i4 i5 i6 i7 i8 sub ecx,1 jnz 1c 14 18 1c 20 24 28 2c 30 34

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

  15. Function call 10 i1 i1 i2 call 34 14 i2 18 call 34 i7 i8 i9 i10 ret 22 i4 26 i5 30 i6 34 i7 38 i4 i5 i6 i8 42 i9 46 i10 50 ret ca5-15

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

  17. s=? z=? 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 ???????? 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx ???????? edx ???????? esp 00000108 eip 0000030f ???????? 100 ???????? 104 ???????? 108

  18. s=? z=? 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 00000006 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx ???????? edx ???????? esp 00000108 eip 00000314 push 319 jmp 300 ???????? 100 ???????? 104 ???????? 108

  19. s=? z=? 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 00000006 300: 302: 304: 306: 307: 30c: 30e: 30f: 314` 319: ebx ???????? edx ???????? esp 00000104 eip 00000300 ???????? 100 00000319 104 ???????? 108

  20. s=0 z=0 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 00000006 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx ???????? edx ???????? esp 00000104 eip 00000302 ???????? 100 00000319 104 ???????? 108

  21. s=0 z=0 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 00000006 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx ???????? edx ???????? esp 00000104 eip 00000307 ???????? 100 00000319 104 ???????? 108

  22. s=0 z=0 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 00000006 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx 00000005 edx ???????? esp 00000104 eip 0000030c ???????? 100 00000319 104 ???????? 108

  23. s=0 z=0 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 0000001e 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx 00000005 edx 00000000 esp 00000104 eip 0000030e ???????? 100 00000319 104 ???????? 108

  24. s=0 z=0 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 0000001e 300: 302: 304: 306: 307: 30c: 30e: 30f: 314: 319: ebx 00000005 edx 00000000 esp 00000108 eip 00000319 ???????? 100 00000319 104 ???????? 108

  25. s=0 z=0 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 eax 0000001e 300: 301: 303: 305: 307: 308 309: 30e: 310: 311: 312: 317: 31c: ebx 00000005 edx ???????? esp 00000108 ???????? 0fc edx 100 0000031c 104 ???????? 108

  26. 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 s=0 z=0 Saving registers eax 0000001e ebx ???????? edx ???????? ???????? 0f8 ebx 0fc edx 100 ret address 104 ???????? 108

  27. Control Flow Graph 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

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

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

  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 ???????? 0fc esp ret address 100 00000006 104 ???????? 108

  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); }

  32. 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 Local Variables ???????? 0fc esp ???????? 100 ret address 104 ???????? 108

  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. 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 Complete Picture stack frame esp result esp+4 edx esp+8 ebx esp+c ret address esp+10 00000006

  35. Stack frames p1 p2 p3 p4 Activation tree

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

  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. i1 i2 i3 i4 int 3 i5 i1 i6 i2 i7 i3 i8 i4 int 2 i5 i10 i6 i11 Interrupt routine 3 t Interrupts Vector table 0 1 2 3 4

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

  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. Overview • Jumps • Loops • Procedure call and return • Interrupts • System operations • Measuring performance • Instruction decoding • Compilers, linkers, and loaders

  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. 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. Benchmark programs • Whetstone, Dhrystone • EEMBC, Mediabench • TPC-benchmarks • SPEC (Standard Performance Evaluation Corporation): Spec92, Spec95, Spec2000, Spec2006 (SpecInt, SpecFp, SpecRate) • Ziff-Davis

  45. Overview • Jumps • Loops • Procedure call and return • Interrupts • System operations • Measuring performance • Instruction decoding • Compilers, linkers, and loaders

  46. 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 data 2 w word opcode add immediate to accumulator Instruction decoding add ax,2 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

  47. 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 Instruction description SUB subtract O D I T S Z A P C 001010dwoorrrmmm disp * * * * * *

  48. Overview • Jumps • Loops • Procedure call and return • Interrupts • System operations • Measuring performance • Instruction decoding • Compilers, linkers, and loaders

  49. Program development source object file compiler object file object files executable file linker libraries

More Related