1 / 27

CCR Programming Language

CCR Programming Language. CCR Programming Language Nick Perz compsci.snc.edu/cs460/perzne April 29, 2003. Project Definition.

eyad
Télécharger la présentation

CCR Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CCR Programming Language • CCR Programming Language • Nick Perz • compsci.snc.edu/cs460/perzne • April 29, 2003

  2. Project Definition • Project Description: Construct a language for the Computer Controlled Railroad (CCR) that can completely control the system. General Requirements:Construct a low level assembly-like language that allows complete control of: a. trains using DCC standards b. turnout switches including feedback c. track detectors 2. Write an interpreter that decodes asm instructions and executes them. 3. The CCR must be able to execute stored asm programs (file) w/o user intervention. 4. Write an API that allows C++ or VB programs to access CCR-asm instructions.

  3. Solution • Created an ASM type language controlling • Train • Photocells • Turnouts • Language includes 25 commands • Addition, Subtraction, Conditionals • Random Number Generator, Delay, Variables • Supports comments

  4. Solution (cont.) • Train Commands • Speed, Stop, Toggle_Dir • Turnout Commands • Get_To_Dir, Set_To_Dir • Conditionals • If_Less, If_Great, If_Equal, If_Cov, If_Open, If_Str, If_Cur

  5. Solution (cont.) • Mathematical Commands • Add, Sub, Inc, Dec, Rand • Variable and Label Commands • Var, Label • Miscellaneous Commands • Delay, Waitpc, Jump, Quit, End • Comments supported by the use of opening and closing ‘~’

  6. Methodology • Compiler • Parses the string, input from a file, and creates machine language , alerts user to any errors within the program • Loads machine language into “memory”, a double scripted array • Machine Language consists of an opcode, mode “bits”, and parameters • Main • Function calls which use the global array to retrieve information and execute

  7. Machine Language • Code[program][y] • program is the line of code • y=0 contains the opcode • y=odd number contains the mode “bit” • 1 if variable, 0 if constant • y=even number contains the constant or location of the variable in memory

  8. Sample Program • Start 16 7 2 -1 1 1 • Var X 8 • Speed X • End • Add X 4 • Speed X • Waitpc 7 • Stop • Quit

  9. ASM Start 16 7 2 -1 1 1 ML Code[0][0] = 0 train.id = 16 train.lastpc = 7 train.nextpc = 2 train.to = -1 train.train_dir = 1 train.track_dir = 1 Line 0

  10. ASM Var X 8 ML Code[1][0] = 11 Code[1][1] = 1 Code[1][2] = 8 symbol_table[0] = “X” symbol_addr[0] = 1 Line 1

  11. ASM Speed X ML Code[2][0] = 10 Code[2][1] = 1 Code[2][2] = 1 Line 2

  12. ASM Add X 4 ML Code[4][0] Code[4][1] = 1 Code[4][2] = 1 Code[4][3] = 0 Code[4][4] = 4 Code[1][2] = 12 Line 4

  13. Race Condition • Using If_Cov or If_Open • Sample Code Label a If_Cov 4 b Jump a Label b

  14. Race Condition (cont.) • Executing If_Cov 4 b • Train has not yet covered Photocell 4, next line is executed

  15. Race Condition (cont.) • Executing Jump a • As the next line is being executed the train covers Photocell 4

  16. Race Condition (cont.) • Executing If_Cov 4 a • The train has passed photocell 4, which creates an infinite loop

  17. Race Condition (cont.) • Really?!? • The Command Would Execute about 50% of the time • Slowing the train increased success • Using one command instead of two increased success considerably

  18. Exceptions • One Train System • Operates in Console Mode • No API for C++ or VB programs to access CCR-asm commands

  19. Demonstration • Program 1 • Train circles the track changing to a random speed between 5 and 15 at every photocell • Program 2 • Train advances to 15, stops, switches turnout, starts again, slows at 11, stops at 14, switches turnout, increases speed until end

  20. Demonstration (cont.) • Program 3 • Train advances to 0, reverses, stops at 2, toggles direction, toggles turnout, starts, stops at 9, sets turnout, speeds to the finish

  21. Q&A • Questions??

  22. Track Data Structure • Track[pc][6] • Counterclockwise • Track[7][2] = -1 • Track[7][0] = 2 • Clockwise • Track[7][3] = 2 • Track[7][1] = 15

  23. Strategies • Trial and Error • After getting a few basic commands and running the train, I soon discovered things I needed/wanted to implement • Outside Input • Dr. Pankratz • Classmates • CS225 Book

  24. Knowledge • Programming Languages • Working with a compiler • Learning how languages work • CS225 • Looked to ASM to help with my ASM type language • CS370 • Racing condition problem

  25. Extensions • Two trains • Higher Level Language • Simulator

  26. Advice • Get started early, the more time you spend now, the less you will have to spend later • Meet early and meet often with Dr. Pankratz • Don’t be afraid to change your solution • Make sure you are solving the right problem

  27. Conclusion • Thanks for Coming

More Related