Computer program - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Computer program

Description:

Computer program A sequence of step-by-step instructions for the computer to follow – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 21
Provided by: wkd5
Learn more at: https://cse.umn.edu
Category:

less

Transcript and Presenter's Notes

Title: Computer program


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 movx 4B0 movy 4B0 pen_dow
n movx 4 movy 4 movx -4 movy -4 pen_up
movx -4B0 movy -4B0 NEXT B0 end
8
(No Transcript)
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 movx 10 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 RE
TURN end
11
(No Transcript)
12
(No Transcript)
13
Body Computer
HIGH limb Raise body part LOW limb Lower body
part TOGGLE limb Body part to opposite
state SHOUT text Shout words SHOUT B0 Shout
value of variable PAUSE milliseconds Delay for
specified time SLEEP Sleep until next
power-up
14
Practice Programs (1)
HIGH right_hand
LOW right_hand
SHOUT Go
SHOUT Gophers
HIGH left_hand PAUSE 2000 LOW left_hand
15
Practice Programs (2)
HIGH right_foot PAUSE 5000 TOGGLE left_hand PAUSE
2000 TOGGLE right_foot PAUSE 5000 LOW left_hand SH
OUT Done
16
Practice Programs (3)
start HIGH right_hand PAUSE 6000 IF (light
on) THEN hammer SHOUT My hand is
up LOW right_hand GOTO end hammer LOW right_h
and SHOUT My hand is down end END
17
(No Transcript)
18
(No Transcript)
19
start HIGH right_hand PAUSE 2000 LOW right_han
d PAUSE 2000 SHOUT Go Gophers HIGH left_foot
PAUSE 2000 LOW left_foot PAUSE 2000 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 FOR N 1 TO 2
HIGH right_foot PAUSE 500
LOW right_foot PAUSE 500 SHOUT N NEXT
N HIGH left_foot GOTO oranges apples FOR N
1 TO 3 HIGH left_hand PAUSE 2000
LOW left_hand PAUSE 2000 SHOUT N NEXT
N HIGH right_hand GOTO plums oranges PAUSE 300
0 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 H
IGH right 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 PAUSE 2000 NEXT N GOTO
plums blueberries FOR N 1 TO 2 GOSUB
peaches PAUSE 2000 NEXT N GOTO
plums peaches SHOUT Go RETURN pineapples S
HOUT Gophers RETURN end LOW left_hand LOW l
eft_foot LOW right_hand LOW right_foot SHOUT I
m done END
20
Body Performance Run your program. One step per
clock tick
  • Computer A
  • HIGH right_hand
  • LOW right_hand
  • SHOUT Go Gophers
  • HIGH left_foot
  • LOW left_foot
  • IF person to my right has last name that starts
    with L thru Z THEN Line 9
  • CLAP
  • GOTO Line 11
  • WAIT
  • SHOUT Go
  • WAIT
  • END
  • Computer B
  • HIGH right_hand
  • LOW right_hand
  • SHOUT Go Gophers
  • HIGH right_foot
  • LOW right_foot
  • IF person to my right has last name that starts
    with L thru Z THEN Line 9
  • CLAP
  • GOTO Line 11
  • WAIT
  • WAIT
  • SHOUT Gophers
  • END
Write a Comment
User Comments (0)
About PowerShow.com