1 / 12

Computer Program

Computer Program. A sequence of step-by-step instructions for the computer to follow. Computer Instructions. 1. OPERATION: Evaluate expression, set output, read input, ... 2. JUMP: Jump immediately, and out of sequence to another instruction

dasan
Télécharger la présentation

Computer Program

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. Computer Program A sequence of step-by-step instructions for the computer to follow

  2. Computer Instructions 1. OPERATION: Evaluate expression, set output, read input, ... 2. JUMP: Jump immediately, and out of sequence to another instruction 3. BRANCH: Evaluate a condition and jump if condition true 4. LOOP: Repeat specified section a number of times

  3. A Program 1. Do this 2. Do that 3. Jump to instruction 6 4. Do the other thing 5. All done, sleep 6. If switch closed, do that thing you do 7. Jump to instruction 4

  4. Pen Computer PEN_UP Lift pen off paper PEN_DOWN Lower pen onto paper MOVX dMove pen a distance d in x direction MOVY dMove pen a distance d in y direction PEN_UP MOVX 8 MOVY 8 PEN_DOWN MOVX 4 MOVY 4 MOVX -4 MOVY -4 PENUP

  5. PEN_UP MOVX 8 MOVY 8 PEN_DOWN MOVX 4 MOVY 4 MOVX -4 MOVY -4 PENUP

  6. Some Complexity: For Loops Initialize counter (once)Check condition. If true, do instructions then increment counter Effect: Repeats instructions for desired number of times for (i=0;i<n;i++) {instructions} Example What is j at the end? Ans: j = 3 Ans: j = 6 j=0 for (i=1;i<4;i++) { j=j+1 } j=0 for (i=1;i<4;i++) { j=j+i }

  7. Program 1 pen_down movx 20 movy 16 movx -20 movy -16 pen_up for (i=1;i<4;i++) { movx 4*i movy 4*i pen_down movx 4 movy 4 movx -4 movy -4 pen_up movx -4*i movy -4*i } (go to top of next column)

  8. More Complexity: If and Functions if (expr) { Evaluate. If true, do instructionsinstructions} myfunction() Jump to myfunction(). When done, return to next instruction.

  9. Program 2 main() { pen_up movx 10 movy 8 pen_down for (i=0;i<5;i++) { movy 1 } movepen() pen_up movx -2 movy -2 pen_down for (i=0;i<4;i++) { movx 1 } pen_up } //end of main, stop here //movepen function movepen() { pen_up movx 4 pen_down movy 4 pen_up movx -4 movy -4 }

More Related