Lecture34

# Lecture34 - 0306-250 Assembly Language Programming Lecture...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture Thirty-Four: Lab Exercise Ten—Game Lab Exercise Ten Create a game • • • • Serial I/O driver (interrupts)—SCI A/D conversion (polled)—ATD Timer driver (interrupts)—PTM Scoring system Work in team of two within lab section 2 Game Specification • Display instructions for game – Create your own instruction text • Prompt user to start by pressing a keyboard key – Key time may be used as random event • Run game rounds • Display score • Prompt user to start a new game 3 Game Round Try to match 1 number in each of 4 rounds i • Display pseudorandom number i to screen • User has ti = 25 - 5i seconds to match number from A/D conversion of potentiometer value within |e| < 50 • User presses a keyboard key to check number • Program prints A/D value or indication of how close • Round ends at first of these occurrences – Time expires – User matches pattern 4 Game Design (Part I) Serial I/O • • • • • • Display game instructions Prompt user to start game Get user input to start game Display each number to match Display score Prompt user to start next game 5 Game Design (Part II) A/D conversion • Read potentiometer value Timer driver • Measure time for game Scoring system • Correct response • Time of response 6 Random Number Generator (RNG) • A computer’s operation is deterministic.Hopefully! • How can it generate something truly random? Need external interaction • Outside event • Random process Time of user action is not repeatable ® random 7 Random Number Algorithm • Initialize and start ECT channel 7 output compare • When a random number is needed, prompt user action – Press a key – Enter data Any action requiring user effort • When the user acts, record the value of the timer Random Number 8 Random versus Pseudorandom Numbers • Random number time of random user action – Less repeatable – Consistently unpredictable • Pseudorandom number same seed value – Exactly repeatable – Consistently predictable easier debugging 9 Pseudorandom Number Generator Characteristics Mathematical expression • Sequence of numbers • Seed starts sequence – Initial value – Random number 10 Pseudorandom Number Generator (PRNG) Primitive polynomial • Generates repeating sequence of numbers • Example: 15-bit generator – G(x) = x16 + x12 + x5 + 1 – Sequence of 215-1 numbers 11 PRNG Pseudocode unsigned word MyRandomSeed = 0; unsigned word MyRandom (void) { unsigned word After, Before; if (MyRandomSeed <> 0) Before ß MyRandomSeed; else Before ß \$FFFF; if ((Before & \$0001) == 1) After ß ((Before >> 1) Å \$8408); else After ß (Before >> 1); } MyRandomSeed ß After; return MyRandomSeed; /* end MyRandom() */ 12 ...
View Full Document

• Fall '10
• RoyMelton
• Randomness, random number, Pseudorandom number generator, pseudorandom number, prompt user, PRNG Pseudocode

{[ snackBarMessage ]}

Ask a homework question - tutors are online