Download presentation
Presentation is loading. Please wait.
Published bySylvia Rose Modified over 9 years ago
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 to instruction tagged by a label 3. BRANCH:Evaluate a condition and jump if condition true 4. LOOP:Repeat section specified 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 d Move pen a distance d in x direction MOVY d Move 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: Loops FOR B0 = 1 TO n Repeat instructions n times instructions NEXT B0
7
Program 1 start: pen_down movx 20 movy 16 movx-20 movy-16 pen_up FOR B0 = 1 TO 3 movx4*B0 movy4*B0 pen_down movx 4 movy 4 movx-4 movy-4 pen_up movx-4*B0 movy-4*B0 NEXT B0 end:
9
More complexity N = N + 1 New val = old val + 1 IF expr THEN address Evaluate and branch if true GOTO address Jump immediately GOSUB address Jump to subroutine at address RETURN Go back to instruction after GOSUB
10
Program 2 start: pen_up movx10 movy 8 pen_down N = 0 part1: movy 1 N = N + 1 IF N = 5 THEN part2 GOTO part1 part2: GOSUB part3 pen_up movx -2 movy -2 pen_down FOR N = 1 TO 4 movx 1 NEXT N pen_up GOTO end part3: pen_up movx 4 pen_down movy 4 pen_up movx-4 movy-4 RETURN end:
13
Body Computer HIGHlimb Raise body part LOWlimb Lower body part TOGGLElimb Body part to opposite state SHOUT“text” Shout words SHOUTB0 Shout value of variable PAUSEmilliseconds Delay for specified time SLEEP Sleep until next power-up
14
Practice Programs (1) HIGHright_hand LOWright_hand SHOUT“Go” SHOUT“Gophers” HIGHleft_hand PAUSE2000 LOWleft_hand
15
Practice Programs (2) HIGHright_foot PAUSE5000 TOGGLEleft_hand PAUSE2000 TOGGLEright_foot PAUSE5000 LOWleft_hand SHOUT“Done”
16
Practice Programs (3) start: HIGHright_hand PAUSE6000 IF (light on) THEN hammer SHOUT“My hand is up” LOWright_hand GOTOend hammer: LOWright_hand SHOUT“My hand is down” end:END
19
start: HIGHright_hand PAUSE2000 LOWright_hand PAUSE2000 SHOUT“Go Gophers” HIGHleft_foot PAUSE2000 LOWleft_foot PAUSE2000 SHOUT“Why am I doing this?!” IF (last name of person closest to you starts with B, C, D, H, M, N or S) THEN apples FORN = 1 TO 2 HIGHright_foot PAUSE500 LOWright_foot PAUSE500 SHOUTN NEXT N HIGH left_foot GOTO oranges apples: FORN = 1 TO 3 HIGHleft_hand PAUSE2000 LOWleft_hand PAUSE2000 SHOUTN NEXT N HIGHright_hand GOTOplums oranges: PAUSE3000 IF (hand of person closest to you is up) THEN pears FOR N = 1 to 2 TOGGLE right_hand PAUSE 2000 SHOUT “Minnesota” TOGGLE right_hand NEXT N pears: LOW left_foot SHOUT “Finally” plums: HIGHright hand IF (light is on) THEN bananas TOGGLE left_hand TOGGLE left_foot PAUSE 3000 TOGGLE left_foot PAUSE 5000 IF (TA is standing) THEN blueberries GOTO end bananas: FOR N = 1 TO 2 GOSUB pineapples PAUSE2000 NEXT N GOTO plums blueberries: FOR N = 1 TO 2 GOSUB peaches PAUSE2000 NEXT N GOTO plums peaches: SHOUT “Go” RETURN pineapples: SHOUT “Gophers” RETURN end: LOWleft_hand LOWleft_foot LOWright_hand LOWright_foot SHOUT“I’m done” END
20
Body Performance: Run your program. One step per clock tick Computer A 1.HIGHright_hand 2.LOW right_hand 3.SHOUT “Go Gophers” 4.HIGHleft_foot 5.LOWleft_foot 6.IFperson to my right has last name that starts with L thru Z THEN Line 9 7.CLAP 8.GOTOLine 11 9.WAIT 10.SHOUT “Go” 11.WAIT 12.END Computer B 1.HIGHright_hand 2.LOW right_hand 3.SHOUT “Go Gophers” 4.HIGHright_foot 5.LOWright_foot 6.IFperson to my right has last name that starts with L thru Z THEN Line 9 7.CLAP 8.GOTOLine 11 9.WAIT 10.WAIT 11.SHOUT “Gophers” 12.END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.