270 likes | 435 Views
CCR Programming Language. CCR Programming Language Nick Perz compsci.snc.edu/cs460/perzne April 29, 2003. Project Definition.
E N D
CCR Programming Language • CCR Programming Language • Nick Perz • compsci.snc.edu/cs460/perzne • April 29, 2003
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.
Solution • Created an ASM type language controlling • Train • Photocells • Turnouts • Language includes 25 commands • Addition, Subtraction, Conditionals • Random Number Generator, Delay, Variables • Supports comments
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
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 ‘~’
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
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
Sample Program • Start 16 7 2 -1 1 1 • Var X 8 • Speed X • End • Add X 4 • Speed X • Waitpc 7 • Stop • Quit
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
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
ASM Speed X ML Code[2][0] = 10 Code[2][1] = 1 Code[2][2] = 1 Line 2
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
Race Condition • Using If_Cov or If_Open • Sample Code Label a If_Cov 4 b Jump a Label b
Race Condition (cont.) • Executing If_Cov 4 b • Train has not yet covered Photocell 4, next line is executed
Race Condition (cont.) • Executing Jump a • As the next line is being executed the train covers Photocell 4
Race Condition (cont.) • Executing If_Cov 4 a • The train has passed photocell 4, which creates an infinite loop
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
Exceptions • One Train System • Operates in Console Mode • No API for C++ or VB programs to access CCR-asm commands
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
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
Q&A • Questions??
Track Data Structure • Track[pc][6] • Counterclockwise • Track[7][2] = -1 • Track[7][0] = 2 • Clockwise • Track[7][3] = 2 • Track[7][1] = 15
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
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
Extensions • Two trains • Higher Level Language • Simulator
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
Conclusion • Thanks for Coming