1 / 7

Addendum to Chap 2 and Chap 3

Addendum to Chap 2 and Chap 3. Pointers. What is a pointer? A special data that records memory address Example in C. int a = 3; int * p = NULL; p = & a; * p = 5;. 3. 5. 0. 0x0A. “Function call” in instruction level.

basil
Télécharger la présentation

Addendum to Chap 2 and Chap 3

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. Addendum to Chap 2 and Chap 3

  2. Pointers • What is a pointer? • A special data that records memory address • Example in C int a = 3; int*p = NULL; p = &a; *p = 5; 3 5 0 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 30 32 34 36 38 3A 3C 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 Nowadays, CPU has instructions: call and ret.

  4. Global variables vs Local variables Global • 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). Local int a; main() { a = 5; printf(“%d\n”,adda(a)); } int adda(int b){ int a = 3; return a+b; }

  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 B F C F D E G 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.

More Related