{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter 12 - Types, Operators, and Expressions

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

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

Chapter 12 – Types, Operators, Expressions First chimp in space "C is quirky, flawed, and an enormous success." - Dennis M. Ritchie.

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

View Full Document
BYU CS/ECEn 124 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
BYU CS/ECEn 124 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

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

View Full Document
BYU CS/ECEn 124 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 #WDTPW+WDTHOLD,&WDTCTL bis.b #0x01,&P1DIR 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
BYU CS/ECEn 124 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; } } Systematic Decomposition start: call #init_board newGame: call #new_game call #saveRandSeed mov.b #0xff,&success mov.w #TRYS-1,&trys tryLoop: tst.b &success jeq newGame inc.w &trys test: mov.w #0,r15 testLoop: cmp.w r15,&trys jge player call #getRand and.w #0x0003,r12 call #doLEDsTone inc.w r15 jmp testLoop: player: call #restoreRandSeed ...

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

View Full Document
BYU CS/ECEn 124 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; doLEDsTone; if (getRand  switch) { success = FALSE; break; } } } doResults : { if (success) { outSuccessDitty; restoreRandSeed; } else outRaspberry; } Systematic Decomposition start: call #init_board newGame: call #new_game call #saveRandSeed mov.b #0xff,&success mov.w #TRYS-1,&trys tryLoop: tst.b
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}