More MIPS: Recursion. Computer Science 104 Lecture 9

Size: px
Start display at page:

Download "More MIPS: Recursion. Computer Science 104 Lecture 9"

Transcription

1 More MIPS: Recursion Computer Science 104 Lecture 9

2 Admin Homework Homework 1: graded. 50% As, 27% Bs Homework 2: Due Wed Midterm 1 This Wed 1 page of notes 2

3 Last time What did we do last time? 3

4 Last time What did we do last time? More MIPS! Functions: jal jr Calling conventions Stack Frames, saving registers Worked bubble sort example 4

5 Review: MIPS Registers 0 zero constant 0 1 at reserved for assembler 2 v0 expression evaluation & 3 v1 function results 4 a0 arguments 5 a1 6 a2 7 a3 8 t0 temporary: caller saves t7 16 s0 callee saves s7 24 t8 temporary (cont d) 25 t9 26 k0 reserved for OS kernel 27 k1 28 gp Pointer to global area 29 sp Stack pointer 30 fp frame pointer 31 ra Return Address (HW) 5

6 Review: Calling a function Calling Procedure Step-1: Setup the arguments: The first four arguments (arg0-arg3) are passed in registers $a0-$a3 Remaining arguments are pushed onto the stack (in reverse order arg5 is at the top of the stack). Step-2: Save caller-saved registers Save registers $t0-$t9 if they contain live values at the call site. Step-3: Execute a jal instruction. 6

7 Called Routine Review: Callee setup Step-1: Establish stack frame. Subtract the frame size from the stack pointer. addiu $sp, $sp, - <frame-size> Typically, minimum frame size is 32 bytes (8 words). Step-2: Save callee saved registers in the frame. Register $fp is always saved. Register $ra is saved if routine makes a call. Registers $s0-$s7 are saved if they are used. Step-3: Establish Frame pointer Add the stack <frame size> - 4 to the address in $sp addiu $fp, $sp, <frame-size> - 4 7

8 On return from a call Review: Returning Step-1: Put returned values in registers $v0. (if a value is returned) Step-2: Restore callee-saved registers. Restore $fp and other saved registers. [$ra, $s0 - $s7] Step-3: Pop the stack Add the frame size to $sp. addiu $sp, $sp, <frame-size> Step-4: Return Jump to the address in $ra. jr $ra 8

9 Today More MIPS! Recursion Won t be required on the exam But you could use recursion if you want And good MIPSing practice anyways Extra time? I ll work example problems, answer review questions, etc 9

10 Recursion Why do we want recursion? Because recursion is a wonderful thing! Canonical recursion example? Factorial 10

11 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } int x = fact(3); 11

12 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } main x??? int main (void) { int x = fact(3); 12

13 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } main x??? factorial n 3 return C0 C0 int main (void) { int x = fact(3); 13

14 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } main x??? factorial n 3 return C0 C0 int main (void) { int x = fact(3); 14

15 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 15

16 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 16

17 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 factorial n 1 return C1 17

18 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 factorial n 1 return C1 18

19 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 factorial n 1 return C1 factorial n 0 return C1 19

20 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 factorial n 1 return C1 factorial n 0 return C1 20

21 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); fact returned 1 factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 factorial n 1 return C1 21

22 int fact (int n) { if (n <= 0) { Factorial in C main x??? } } return 1; C1 return n * fact (n 1); fact returned 1 factorial n 3 return C0 factorial C0 int main (void) { int x = fact(3); n 2 return C1 22

23 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } fact returned 2 main x??? factorial n 3 return C0 C0 int main (void) { int x = fact(3); 23

24 Factorial in C int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } main x 6 int main (void) { int x = fact(3); 24

25 int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } Observe: Parameter n in $a0 Need to put n-1 in $a0 to call Need n after call int main (void) { int x = fact(3); 25

26 int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } Observe: Parameter n in $a0 Need to put n-1 in $a0 to call Need n after call Conclusion: Need to move n to other reg Which one: $t0 or $s0? int main (void) { int x = fact(3); 26

27 int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } int main (void) { int x = fact(3); Observe: Parameter n in $a0 Need to put n-1 in $a0 to call Need n after call Conclusion: Need to move n to other reg Which one: $t0 or $s0? Would need save/restore => May as well use $s0 27

28 Convert C to Assembly int fact (int n) { if (n <= 0) { return 1; } return n * fact (n 1); } (We ll switch to emacs For this part) int main (void) { int x = fact(3); 28

29 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 1234 ABCD FF80 FFCC $ra 4000 Addr FF78 FF74 FF70 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 Value 29

30 Addr Value <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 FF78 FF74 FF70 FF68 FF64 FF60 $a $s $v0 ABCD $sp FF80 $fp FFCC $ra 4000 FF58 FF54 FF50 FF48 FF44 FF40 30

31 Addr Value <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 FF78 FF74 FF70 FF68 FF64 FF60 $a $s $v0 ABCD $sp FF70 $fp FFCC $ra 4000 FF58 FF54 FF50 FF48 FF44 FF40 31

32 Addr Value <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 FF78 FF74 FF70 FF68 FF64 FF60 FFCC $a $s $v0 ABCD $sp FF70 $fp FFCC $ra 4000 FF58 FF54 FF50 FF48 FF44 FF40 32

33 <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 $a $s $v0 ABCD $sp FF70 $fp FFCC $ra 4000 FF78 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 33

34 <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 $a $s $v0 ABCD $sp FF70 $fp FFCC $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 34

35 <<Frame Setup>> addiu $sp, $sp, -16 sw $fp, 0($sp) sw $ra, 4($sp) sw $s0, 8($sp) addiu $fp, $sp, 12 $a $s $v0 ABCD $sp FF70 $fp $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 35

36 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 1234 ABCD FF70 $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 36

37 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0003 ABCD FF70 $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 37

38 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0003 ABCD FF70 $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 38

39 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0003 ABCD FF70 $ra 4000 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 39

40 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0003 ABCD FF70 $ra 1044 FF68 FF64 FF60 FF58 FF54 FF50 FF48 FF44 FF40 40

41 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0003 ABCD FF60 $ra 1044 FF FF FF60 FF58 FF54 FF50 FF48 FF44 FF40 41

42 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0002 ABCD FF60 $ra 1044 FF FF FF60 FF58 FF54 FF50 FF48 FF44 FF40 42

43 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0002 ABCD FF60 $ra 1044 FF FF FF60 FF58 FF54 FF50 FF48 FF44 FF40 43

44 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0002 ABCD FF60 $ra 1044 FF FF FF60 FF58 FF54 FF50 FF48 FF44 FF40 44

45 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0002 ABCD FF60 $ra 1044 FF FF FF60 FF58 FF54 FF50 FF48 FF44 FF40 45

46 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0002 ABCD FF50 $ra 1044 FF FF FF60 FF FF FF50 FF48 FF44 FF40 46

47 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0001 ABCD FF50 $ra 1044 FF FF FF60 FF FF FF50 FF48 FF44 FF40 47

48 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0001 ABCD FF50 $ra 1044 FF FF FF60 FF FF FF50 FF48 FF44 FF40 48

49 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0001 ABCD FF50 $ra 1044 FF FF FF60 FF FF FF50 FF48 FF44 FF40 49

50 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0001 ABCD FF50 $ra 1044 FF FF FF60 FF FF FF50 FF48 FF44 FF40 50

51 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0001 ABCD FF40 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 51

52 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0000 ABCD FF40 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 52

53 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp 0000 ABCD FF40 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 53

54 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF40 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 54

55 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF40 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 55

56 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF40 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 56

57 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF40 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 57

58 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF40 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 58

59 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF40 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 59

60 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) Factorial in Assembly addiu $sp, $sp, 16 Notice how $sp and $fp describe the callers frame now Reg Value $a $s $v $sp $fp FF50 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 60

61 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF50 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 61

62 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF50 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 62

63 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF50 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 63

64 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF60 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 64

65 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF60 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 65

66 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF60 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 66

67 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF70 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 67

68 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF70 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 68

69 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF70 $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 69

70 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF70 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 70

71 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF70 $fp $ra 1044 FF FF FF60 FF FF FF50 FF FF FF40 71

72 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF70 $fp $ra 4000 FF FF FF60 FF FF FF50 FF FF FF40 72

73 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF70 $fp FFCC $ra 4000 FF FF FF60 FF FF FF50 FF FF FF40 73

74 <<Frame Cleanup>> lw $s0, 8($sp) lw $ra, 4($sp) lw $fp, 0($sp) addiu $sp, $sp, 16 $a $s $v $sp FF80 $fp FFCC $ra 4000 FF FF FF60 FF FF FF50 FF FF FF40 74

75 fact: <<frame setup>> move $s0, $a0 blez $s0, factendzero addi $a0, $a0, -1 jal fact # Addr 1040 mul $v0, $v0, $s0 factret: <<frame cleanup>> $a jr $ra factendzero: li $v0, 1 b factret $s0 $v0 $sp $fp FF80 FFCC $ra 4000 FF FF FF60 FF FF FF50 FF FF FF40 75

76 main: li $a0, 3 jal fact move $a0, $v0 Value returned in $v0 Stack /callee saves restored Factorial in Assembly Reg Value $a $s $v $sp $fp FF80 FFCC $ra 4000 FF FF FF60 FF FF FF50 FF FF FF40 76

77 Recursion De-mystified? Recursion: Assembly: not required on midterm1 Generally good to know Hopefully de-mystified? P.S. Some languages only have recursion 77

78 Other ISAs We ve been studying MIPS x86: Intel, AMD very common, kind of ugly Variable length insns (1-22 bytes) Very complex insns Not a load-store ISA (can do mem + reg -> mem) PowerPC more like MIPS ( RISC ) Has some not-so RISC things: load-with-update ARM Good to know others exist, but our focus is MIPS 78

79 Remaining Time: Work Examples, Answer?s With any remaining time I ll Work examples (write C, asm, do binary math..) Answer questions Whatever. 79

Computer Systems Architecture

Computer Systems Architecture Computer Systems Architecture http://cs.nott.ac.uk/ txa/g51csa/ Thorsten Altenkirch and Liyang Hu School of Computer Science University of Nottingham Lecture 10: MIPS Procedure Calling Convention and Recursion

More information

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9. Code Generation I Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.7 Stack Machines A simple evaluation model No variables

More information

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I) Lecture Outline Code Generation (I) Stack machines The MIPS assembl language Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) A simple source language Stack- machine implementation of the

More information

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek Instruction Set Architecture or How to talk to computers if you aren t in Star Trek The Instruction Set Architecture Application Compiler Instr. Set Proc. Operating System I/O system Instruction Set Architecture

More information

Intel 8086 architecture

Intel 8086 architecture Intel 8086 architecture Today we ll take a look at Intel s 8086, which is one of the oldest and yet most prevalent processor architectures around. We ll make many comparisons between the MIPS and 8086

More information

Instruction Set Architecture

Instruction Set Architecture Instruction Set Architecture Consider x := y+z. (x, y, z are memory variables) 1-address instructions 2-address instructions LOAD y (r :=y) ADD y,z (y := y+z) ADD z (r:=r+z) MOVE x,y (x := y) STORE x (x:=r)

More information

MIPS Assembly Code Layout

MIPS Assembly Code Layout Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going through a few example programs and

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying

More information

Winter 2002 MID-SESSION TEST Friday, March 1 6:30 to 8:00pm

Winter 2002 MID-SESSION TEST Friday, March 1 6:30 to 8:00pm University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Instructors: Dr. S. A. Norman (L01) and Dr. S. Yanushkevich (L02) Winter 2002 MID-SESSION TEST Friday,

More information

Assembly Language: Function Calls" Jennifer Rexford!

Assembly Language: Function Calls Jennifer Rexford! Assembly Language: Function Calls" Jennifer Rexford! 1 Goals of this Lecture" Function call problems:! Calling and returning! Passing parameters! Storing local variables! Handling registers without interference!

More information

Translating C code to MIPS

Translating C code to MIPS Translating C code to MIPS why do it C is relatively simple, close to the machine C can act as pseudocode for assembler program gives some insight into what compiler needs to do what's under the hood do

More information

CSE 141 Introduction to Computer Architecture Summer Session I, 2005. Lecture 1 Introduction. Pramod V. Argade June 27, 2005

CSE 141 Introduction to Computer Architecture Summer Session I, 2005. Lecture 1 Introduction. Pramod V. Argade June 27, 2005 CSE 141 Introduction to Computer Architecture Summer Session I, 2005 Lecture 1 Introduction Pramod V. Argade June 27, 2005 CSE141: Introduction to Computer Architecture Instructor: Pramod V. Argade (p2argade@cs.ucsd.edu)

More information

Typy danych. Data types: Literals:

Typy danych. Data types: Literals: Lab 10 MIPS32 Typy danych Data types: Instructions are all 32 bits byte(8 bits), halfword (2 bytes), word (4 bytes) a character requires 1 byte of storage an integer requires 1 word (4 bytes) of storage

More information

Review: MIPS Addressing Modes/Instruction Formats

Review: MIPS Addressing Modes/Instruction Formats Review: Addressing Modes Addressing mode Example Meaning Register Add R4,R3 R4 R4+R3 Immediate Add R4,#3 R4 R4+3 Displacement Add R4,1(R1) R4 R4+Mem[1+R1] Register indirect Add R4,(R1) R4 R4+Mem[R1] Indexed

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 20: Stack Frames 7 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Where We Are Source code if (b == 0) a = b; Low-level IR code

More information

Machine-Code Generation for Functions

Machine-Code Generation for Functions Machine-Code Generation for Functions Cosmin Oancea cosmin.oancea@diku.dk University of Copenhagen December 2012 Structure of a Compiler Programme text Lexical analysis Binary machine code Symbol sequence

More information

Introduction to MIPS Assembly Programming

Introduction to MIPS Assembly Programming 1 / 26 Introduction to MIPS Assembly Programming January 23 25, 2013 2 / 26 Outline Overview of assembly programming MARS tutorial MIPS assembly syntax Role of pseudocode Some simple instructions Integer

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming Assemblers were the first programs to assist in programming. The idea of the assembler is simple: represent each computer instruction with an acronym (group of letters). Eg:

More information

Instruction Set Design

Instruction Set Design Instruction Set Design Instruction Set Architecture: to what purpose? ISA provides the level of abstraction between the software and the hardware One of the most important abstraction in CS It s narrow,

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects

More information

5 MIPS Assembly Language

5 MIPS Assembly Language 103 5 MIPS Assembly Language Today, digital computers are almost exclusively programmed using high-level programming languages (PLs), eg, C, C++, Java The CPU fetch execute cycle, however, is not prepared

More information

X86-64 Architecture Guide

X86-64 Architecture Guide X86-64 Architecture Guide For the code-generation project, we shall expose you to a simplified version of the x86-64 platform. Example Consider the following Decaf program: class Program { int foo(int

More information

EC 362 Problem Set #2

EC 362 Problem Set #2 EC 362 Problem Set #2 1) Using Single Precision IEEE 754, what is FF28 0000? 2) Suppose the fraction enhanced of a processor is 40% and the speedup of the enhancement was tenfold. What is the overall speedup?

More information

Compilers I - Chapter 4: Generating Better Code

Compilers I - Chapter 4: Generating Better Code Compilers I - Chapter 4: Generating Better Code Lecturers: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 304, William Penney Building Naranker Dulay (nd@doc.ic.ac.uk) Materials: Office: room 562 Textbook

More information

Computer Architectures

Computer Architectures Computer Architectures Parameters Passing to Subroutines and Operating System Implemented Virtual Instructions (System Calls) Czech Technical University in Prague, Faculty of Electrical Engineering Ver.1.10

More information

In the Beginning... 1964 -- The first ISA appears on the IBM System 360 In the good old days

In the Beginning... 1964 -- The first ISA appears on the IBM System 360 In the good old days RISC vs CISC 66 In the Beginning... 1964 -- The first ISA appears on the IBM System 360 In the good old days Initially, the focus was on usability by humans. Lots of user-friendly instructions (remember

More information

umps software development

umps software development Laboratorio di Sistemi Operativi Anno Accademico 2006-2007 Software Development with umps Part 2 Mauro Morsiani Software development with umps architecture: Assembly language development is cumbersome:

More information

Laboratorio di Sistemi Operativi Anno Accademico 2009-2010

Laboratorio di Sistemi Operativi Anno Accademico 2009-2010 Laboratorio di Sistemi Operativi Anno Accademico 2009-2010 Software Development with umps Part 2 Mauro Morsiani Copyright Permission is granted to copy, distribute and/or modify this document under the

More information

Instruction Set Architecture (ISA) Design. Classification Categories

Instruction Set Architecture (ISA) Design. Classification Categories Instruction Set Architecture (ISA) Design Overview» Classify Instruction set architectures» Look at how applications use ISAs» Examine a modern RISC ISA (DLX)» Measurement of ISA usage in real computers

More information

MIPS Assembler and Simulator

MIPS Assembler and Simulator MIPS Assembler and Simulator Reference Manual Last Updated, December 1, 2005 Xavier Perséguers (ing. info. dipl. EPF) Swiss Federal Institude of Technology xavier.perseguers@a3.epfl.ch Preface MIPS Assembler

More information

Computer Organization and Architecture

Computer Organization and Architecture Computer Organization and Architecture Chapter 11 Instruction Sets: Addressing Modes and Formats Instruction Set Design One goal of instruction set design is to minimize instruction length Another goal

More information

LSN 2 Computer Processors

LSN 2 Computer Processors LSN 2 Computer Processors Department of Engineering Technology LSN 2 Computer Processors Microprocessors Design Instruction set Processor organization Processor performance Bandwidth Clock speed LSN 2

More information

Recursive Fibonacci and the Stack Frame. the Fibonacci function. The Fibonacci function defines the Fibonacci sequence, using a recursive definition :

Recursive Fibonacci and the Stack Frame. the Fibonacci function. The Fibonacci function defines the Fibonacci sequence, using a recursive definition : --6 Recursive Fibonacci and the Stack Frame the Fibonacci function The Fibonacci function defines the Fibonacci sequence, using a recursive definition :, n = fibo n, n = fibo n + fibo n, n > The first

More information

A deeper look at Inline functions

A deeper look at Inline functions A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the

More information

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com CSCI-UA.0201-003 Computer Systems Organization Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified)

More information

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC Chapter 2 Topics 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC See Appendix C for Assembly language information. 2.4

More information

Figure 1: Graphical example of a mergesort 1.

Figure 1: Graphical example of a mergesort 1. CSE 30321 Computer Architecture I Fall 2011 Lab 02: Procedure Calls in MIPS Assembly Programming and Performance Total Points: 100 points due to its complexity, this lab will weight more heavily in your

More information

MICROPROCESSOR AND MICROCOMPUTER BASICS

MICROPROCESSOR AND MICROCOMPUTER BASICS Introduction MICROPROCESSOR AND MICROCOMPUTER BASICS At present there are many types and sizes of computers available. These computers are designed and constructed based on digital and Integrated Circuit

More information

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) Instruction Set Architecture (ISA) * Instruction set architecture of a machine fills the semantic gap between the user and the machine. * ISA serves as the starting point for the design of a new machine

More information

The Operating System and the Kernel

The Operating System and the Kernel The Kernel and System Calls 1 The Operating System and the Kernel We will use the following terminology: kernel: The operating system kernel is the part of the operating system that responds to system

More information

Code Generation & Parameter Passing

Code Generation & Parameter Passing Code Generation & Parameter Passing Lecture Outline 1. Allocating temporaries in the activation record Let s optimie our code generator a bit 2. A deeper look into calling sequences Caller/Callee responsibilities.

More information

Processor Architectures

Processor Architectures ECPE 170 Jeff Shafer University of the Pacific Processor Architectures 2 Schedule Exam 3 Tuesday, December 6 th Caches Virtual Memory Input / Output OperaKng Systems Compilers & Assemblers Processor Architecture

More information

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59 COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59 Overview: In the first projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

More information

Chapter 5 Instructor's Manual

Chapter 5 Instructor's Manual The Essentials of Computer Organization and Architecture Linda Null and Julia Lobur Jones and Bartlett Publishers, 2003 Chapter 5 Instructor's Manual Chapter Objectives Chapter 5, A Closer Look at Instruction

More information

18-447 Computer Architecture Lecture 3: ISA Tradeoffs. Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013

18-447 Computer Architecture Lecture 3: ISA Tradeoffs. Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013 18-447 Computer Architecture Lecture 3: ISA Tradeoffs Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013 Reminder: Homeworks for Next Two Weeks Homework 0 Due next Wednesday (Jan 23), right

More information

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine 7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change

More information

Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD

Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD BCD (ASCII) Arithmetic The Intel Instruction set can handle both packed (two digits per byte) and unpacked BCD (one decimal digit per byte) We will first look at unpacked BCD Unpacked BCD can be either

More information

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program

More information

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks 1 STACK A structure with a series of data elements with last sent element waiting for a delete operation.

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc Other architectures Example. Accumulator-based machines A single register, called the accumulator, stores the operand before the operation, and stores the result after the operation. Load x # into acc

More information

Lab Work 2. MIPS assembly and introduction to PCSpim

Lab Work 2. MIPS assembly and introduction to PCSpim Lab Work 2. MIPS assembly and introduction to PCSpim The goal of this work is for the student to become familiar with the data types and the programming in assembly (MIPS32). To realize this lab work you

More information

Q. Consider a dynamic instruction execution (an execution trace, in other words) that consists of repeats of code in this pattern:

Q. Consider a dynamic instruction execution (an execution trace, in other words) that consists of repeats of code in this pattern: Pipelining HW Q. Can a MIPS SW instruction executing in a simple 5-stage pipelined implementation have a data dependency hazard of any type resulting in a nop bubble? If so, show an example; if not, prove

More information

Chapter 7D The Java Virtual Machine

Chapter 7D The Java Virtual Machine This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly

More information

Lecture 22: C Programming 4 Embedded Systems

Lecture 22: C Programming 4 Embedded Systems Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human

More information

EE282 Computer Architecture and Organization Midterm Exam February 13, 2001. (Total Time = 120 minutes, Total Points = 100)

EE282 Computer Architecture and Organization Midterm Exam February 13, 2001. (Total Time = 120 minutes, Total Points = 100) EE282 Computer Architecture and Organization Midterm Exam February 13, 2001 (Total Time = 120 minutes, Total Points = 100) Name: (please print) Wolfe - Solution In recognition of and in the spirit of the

More information

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail All materials is licensed under a Creative Commons Share Alike license http://creativecommonsorg/licenses/by-sa/30/ # whoami Ali

More information

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP2e Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, pushl, ret, How instructions

More information

A Tiny Guide to Programming in 32-bit x86 Assembly Language

A Tiny Guide to Programming in 32-bit x86 Assembly Language CS308, Spring 1999 A Tiny Guide to Programming in 32-bit x86 Assembly Language by Adam Ferrari, ferrari@virginia.edu (with changes by Alan Batson, batson@virginia.edu and Mike Lack, mnl3j@virginia.edu)

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

COS 318: Operating Systems

COS 318: Operating Systems COS 318: Operating Systems OS Structures and System Calls Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall10/cos318/ Outline Protection mechanisms

More information

İSTANBUL AYDIN UNIVERSITY

İSTANBUL AYDIN UNIVERSITY İSTANBUL AYDIN UNIVERSITY FACULTY OF ENGİNEERİNG SOFTWARE ENGINEERING THE PROJECT OF THE INSTRUCTION SET COMPUTER ORGANIZATION GÖZDE ARAS B1205.090015 Instructor: Prof. Dr. HASAN HÜSEYİN BALIK DECEMBER

More information

CS2210: Compiler Construction. Runtime Environment

CS2210: Compiler Construction. Runtime Environment Compiler s Role in Program Execution When a program is invoked 0x8000000 The OS allocates memory for the program The code is loaded into the main memory Program initializes runtime environment Program

More information

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

More information

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture Last Class: OS and Computer Architecture System bus Network card CPU, memory, I/O devices, network card, system bus Lecture 3, page 1 Last Class: OS and Computer Architecture OS Service Protection Interrupts

More information

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University cwliu@twins.ee.nctu.edu.

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University cwliu@twins.ee.nctu.edu. Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University cwliu@twins.ee.nctu.edu.tw Review Computers in mid 50 s Hardware was expensive

More information

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing. CS143 Handout 18 Summer 2008 30 July, 2008 Processor Architectures Handout written by Maggie Johnson and revised by Julie Zelenski. Architecture Vocabulary Let s review a few relevant hardware definitions:

More information

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example BCD (ASCII) Arithmetic We will first look at unpacked BCD which means strings that look like '4567'. Bytes then look like 34h 35h 36h 37h OR: 04h 05h 06h 07h x86 processors also have instructions for packed

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Computer Organization and Components

Computer Organization and Components Computer Organization and Components IS1500, fall 2015 Lecture 5: I/O Systems, part I Associate Professor, KTH Royal Institute of Technology Assistant Research Engineer, University of California, Berkeley

More information

What Is Recursion? Recursion. Binary search example postponed to end of lecture

What Is Recursion? Recursion. Binary search example postponed to end of lecture Recursion Binary search example postponed to end of lecture What Is Recursion? Recursive call A method call in which the method being called is the same as the one making the call Direct recursion Recursion

More information

Extending the swsusp Hibernation Framework to ARM. Russell Dill

Extending the swsusp Hibernation Framework to ARM. Russell Dill Extending the swsusp Hibernation Framework to ARM Russell Dill 1 2 Introduction Russ Dill of Texas Instruments swsusp/hibernation on ARM Overview Challenges Implementation Remaining work Debugging swsusp

More information

C Compiler Targeting the Java Virtual Machine

C Compiler Targeting the Java Virtual Machine C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the

More information

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2 Lecture Handout Computer Architecture Lecture No. 2 Reading Material Vincent P. Heuring&Harry F. Jordan Chapter 2,Chapter3 Computer Systems Design and Architecture 2.1, 2.2, 3.2 Summary 1) A taxonomy of

More information

Computer Architectures

Computer Architectures Computer Architectures 2. Instruction Set Architectures 2015. február 12. Budapest Gábor Horváth associate professor BUTE Dept. of Networked Systems and Services ghorvath@hit.bme.hu 2 Instruction set architectures

More information

CPU Organization and Assembly Language

CPU Organization and Assembly Language COS 140 Foundations of Computer Science School of Computing and Information Science University of Maine October 2, 2015 Outline 1 2 3 4 5 6 7 8 Homework and announcements Reading: Chapter 12 Homework:

More information

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) ----------------------------------------- =============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

More information

C Programming Review & Productivity Tools

C Programming Review & Productivity Tools Review & Productivity Tools Giovanni Agosta Piattaforme Software per la Rete Modulo 2 Outline Preliminaries 1 Preliminaries 2 Function Pointers Variadic Functions 3 Build Automation Code Versioning 4 Preliminaries

More information

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016 CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping

More information

An Introduction to the ARM 7 Architecture

An Introduction to the ARM 7 Architecture An Introduction to the ARM 7 Architecture Trevor Martin CEng, MIEE Technical Director This article gives an overview of the ARM 7 architecture and a description of its major features for a developer new

More information

CS201: Architecture and Assembly Language

CS201: Architecture and Assembly Language CS201: Architecture and Assembly Language Lecture Three Brendan Burns CS201: Lecture Three p.1/27 Arithmetic for computers Previously we saw how we could represent unsigned numbers in binary and how binary

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Introduction to Electrical and Computer Engineering II Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat

More information

CSC 2405: Computer Systems II

CSC 2405: Computer Systems II CSC 2405: Computer Systems II Spring 2013 (TR 8:30-9:45 in G86) Mirela Damian http://www.csc.villanova.edu/~mdamian/csc2405/ Introductions Mirela Damian Room 167A in the Mendel Science Building mirela.damian@villanova.edu

More information

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1 Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be

More information

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997 Design of Pipelined MIPS Processor Sept. 24 & 26, 1997 Topics Instruction processing Principles of pipelining Inserting pipe registers Data Hazards Control Hazards Exceptions MIPS architecture subset R-type

More information

Chapter 2. Binary Values and Number Systems

Chapter 2. Binary Values and Number Systems Chapter 2 Binary Values and Number Systems Numbers Natural numbers, a.k.a. positive integers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative numbers A

More information

Lecture 17: Virtual Memory II. Goals of virtual memory

Lecture 17: Virtual Memory II. Goals of virtual memory Lecture 17: Virtual Memory II Last Lecture: Introduction to virtual memory Today Review and continue virtual memory discussion Lecture 17 1 Goals of virtual memory Make it appear as if each process has:

More information

HC12 Assembly Language Programming

HC12 Assembly Language Programming HC12 Assembly Language Programming Programming Model Addressing Modes Assembler Directives HC12 Instructions Flow Charts 1 Assembler Directives In order to write an assembly language program it is necessary

More information

Introduction to MIPS Programming with Mars

Introduction to MIPS Programming with Mars Introduction to MIPS Programming with Mars This week s lab will parallel last week s lab. During the lab period, we want you to follow the instructions in this handout that lead you through the process

More information

Analysis of a Search Algorithm

Analysis of a Search Algorithm CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

More information

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals CPU Architectures Motorola 68000 Several CPU architectures exist currently: Motorola Intel AMD (Advanced Micro Devices) PowerPC Pick one to study; others will be variations on this. Arbitrary pick: Motorola

More information

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders 1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

More information

recursion here it is in C++ power function cis15 advanced programming techniques, using c++ fall 2007 lecture # VI.1

recursion here it is in C++ power function cis15 advanced programming techniques, using c++ fall 2007 lecture # VI.1 topics: recursion searching cis15 advanced programming techniques, using c++ fall 2007 lecture # VI.1 recursion recursion is defining something in terms of itself there are many examples in nature and

More information

Common Data Structures

Common Data Structures Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE 1. Introduction 6.004 Computation Structures β Documentation This handout is

More information

x64 Cheat Sheet Fall 2015

x64 Cheat Sheet Fall 2015 CS 33 Intro Computer Systems Doeppner x64 Cheat Sheet Fall 2015 1 x64 Registers x64 assembly code uses sixteen 64-bit registers. Additionally, the lower bytes of some of these registers may be accessed

More information

CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++

CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++ Brad Rippe CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++ Recursion Recursion CHAPTER 14 Overview 14.1 Recursive Functions for Tasks 14.2 Recursive Functions for Values 14.3 Thinking Recursively

More information