Presentation is loading. Please wait.

Presentation is loading. Please wait.

Addendum to Chap 2 and Chap 3

Similar presentations


Presentation on theme: "Addendum to Chap 2 and Chap 3"— Presentation transcript:

1 Addendum to Chap 2 and Chap 3

2 Pointers What is a pointer? Example in C
A special data that records memory address Example in C variable address value a 0x0A p 0x0B int a = 3; int *p = NULL; p = &a; *p = 5; 3 5 0x0A

3 “Function call” in instruction level
Function call is noting but an unconditional jump to another instruction. Need to “jump back” when it returns. Save the “program counter” in some special place. Also the parameters. main() { int a = addone(5); printf(“a=%d\n”,a); } int addone(int a){ return a+1; 10 12 14 16 18 3FFF # Suppose PC # is R16FF 2105 # Set R1 = 5 31FE # Store R1 to FE B030 # jump to 0X30 14FD # Load data in # FD to R4 11FE # Load data in FE to R1 2201 # Set R2 = 1 5312 # R3 = R1 + R2 33FD # Store R3 to FD 11FF # Load data in FF to R1 313C # store return address B018 # jump to 0X18 30 32 34 36 38 3A 3C Nowadays, CPU has instructions: call and ret.

4 Global variables vs Local variables
A global variable exists when the program is loaded to memory Recall homework3 It’s address is fixed A local variable is created when the function is called Will disappear when the function returns. For C language, if a local variable has the same name as a global variable, it refers to the local variable (inside the function). int a; main() { a = 5; printf(“%d\n”,adda(a)); } int adda(int b){ int a = 3; return a+b; Global Local

5 Interrupt A signal from the hardware that tells the software to perform an operation. Operation is handled by the ISR (Interrupt Service Routine) for that interrupt request (IRQ). ISR is a special function, but When to call it is decided by the interrupt, not by users’ program All user program data need be saved, so that when the ISR finishes, user program can continue

6 Defragmentation File system fragmentation:
Will slow down system performance Defragmentation: a process to reduce the fragmentations Thus improves the performance A F B C D F G E H F H A C F H

7 Sleep vs Hibernation Sleep; standby; suspend
The computer cuts power to all unneeded parts of the machine, aside from the memory which is required to restore the machine's state. Hibernation The data in memory is copied to the hard drive, and the computer is powered off When power is on, the memory contents are restored from hard drive.


Download ppt "Addendum to Chap 2 and Chap 3"

Similar presentations


Ads by Google