Chapter 12 - Types, Operators, and Expressions

Chapter 12 - Types, Operators, and Expressions - "C is...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 12 – Types, Operators, Expressions First chimp in space "C is quirky, flawed, and an enormous success." - Dennis M. Ritchie.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
BYU CS/ECEn Variables and Operators 2 Systematic Decomposition n Finiteness n Must terminate. n Definiteness n Each step is precisely stated. n Effective Computability n Each step can be carried out. IDEA Step by Step Procedure Systematic Decomposition
Background image of page 2
BYU CS/ECEn Variables and Operators 3 Incremental Development n Start with problem statement: “Write an assembler program for a traffic stop light.” n Decompose task into a few simpler subtasks . n Turn on the green LED for 5 seconds. n Blink the green LED on and off at 1 second intervals for 6 seconds (3 offs and 3 ons). n Blink the green LED on and off at 0.25 second intervals for 4 seconds (8 offs and 8 ons). n And finally, turn the green LED off for 10 seconds. n Test, test, test n Repeat the process of dividing into subtasks until you get to the machine instruction level. Systematic Decomposition
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
BYU CS/ECEn Variables and Operators 4 Systematic Decomposition “Write an assembler program for a traffic stop light.” Turn on the green LED for 5 seconds. Blink the green LED on and off at 1 second intervals for 6 seconds (3 offs and 3 ons). Blink the green LED on and off at 0.25 second intervals for 4 seconds (8 offs and 8 ons). Turn the green LED off for 10 seconds. .cdecls C,LIST,"msp430x20x3.h" .text RESET: mov.w #0x0280,SP mov.w bis.b mainloop: ; turn on led for 5 seconds ; blink led for 6s at 1s intervals ; blink led for 4s at 0.25s intervals ; turn led off for 10 seconds jmp mainloop .sect ".reset" .word RESET .end Init program. Systematic Decomposition Problem Algorithm Incremental Development
Background image of page 4
BYU CS/ECEn Variables and Operators 5 Simon Example play_Game; Systematic Decomposition init_board; while (TRUE) { new_game; while (success) { doTest; doPlayer; doResults; } } init_board; while (TRUE) { new_game; saveRandSeed; success = TRUE; trys = TRYS-1; while (success) { trys++; for (i=0; i<trys; i++) { getRand; doLEDsTone; } restoreRandSeed; for (i=0; i<trys; i++) { getSwitch; doLEDsTone; if (getRand  switch) { success = FALSE; outRaspberry; break; } } if (!success) break; outSuccessDitty; restoreRandSeed; } } S y s te m a tic D e c o p itio n start: call #init_board newGame: call #new_game call #saveRandSeed mov.b mov.w tryLoop: tst.b jeq newGame inc.w test: mov.w #0,r15 testLoop: cmp.w jge player call #getRand and.w #0x0003,r12 call #doLEDsTone inc.w r15 jmp testLoop: player: call #restoreRandSeed ...
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
BYU CS/ECEn Variables and Operators 6 Simon Example play_Game; Systematic Decomposition init_board; while (TRUE) { new_game; while (success) { doTest; doPlayer; doResults; } } new_game : { saveRandSeed; success = TRUE; trys = TRYS-1; } doTest : { trys++; for (i=0; i<trys; i++) { getRand; doLEDsTone; } } doPlayer : { restoreRandSeed; for (i=0; i<trys; i++) { getSwitch;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 03/20/2012.

Page1 / 33

Chapter 12 - Types, Operators, and Expressions - "C is...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online