ccr programming language

27
CCR Programming Language CCR Programming Language Nick Perz compsci.snc.edu/cs460/perzn April 29, 2003

Upload: eyad

Post on 06-Jan-2016

33 views

Category:

Documents


0 download

DESCRIPTION

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

TRANSCRIPT

Page 1: CCR Programming Language

CCR Programming Language

CCR Programming LanguageNick Perz

compsci.snc.edu/cs460/perzneApril 29, 2003

Page 2: CCR Programming Language

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.

Page 3: CCR Programming Language

Solution

• Created an ASM type language controlling– Train– Photocells– Turnouts

• Language includes 25 commands• Addition, Subtraction, Conditionals• Random Number Generator, Delay,

Variables• Supports comments

Page 4: CCR Programming Language

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

Page 5: CCR Programming Language

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 ‘~’

Page 6: CCR Programming Language

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

Page 7: CCR Programming Language

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

Page 8: CCR Programming Language

Sample Program

Start 16 7 2 -1 1 1 Var X 8Speed XEndAdd X 4Speed XWaitpc 7Stop Quit

Page 9: CCR Programming Language

Line 0

ASMStart 16 7 2 -1 1 1

MLCode[0][0] = 0

train.id = 16train.lastpc = 7train.nextpc = 2train.to = -1train.train_dir = 1train.track_dir = 1

Page 10: CCR Programming Language

Line 1

ASMVar X 8

MLCode[1][0] = 11

Code[1][1] = 1

Code[1][2] = 8

symbol_table[0] = “X”

symbol_addr[0] = 1

Page 11: CCR Programming Language

Line 2

ASMSpeed X

MLCode[2][0] = 10

Code[2][1] = 1

Code[2][2] = 1

Page 12: CCR Programming Language

Line 4

ASMAdd X 4

MLCode[4][0] Code[4][1] = 1Code[4][2] = 1Code[4][3] = 0Code[4][4] = 4

Code[1][2] = 12

Page 13: CCR Programming Language

Race Condition

•Using If_Cov or If_Open

•Sample CodeLabel aIf_Cov 4 bJump aLabel b

Page 14: CCR Programming Language

Race Condition (cont.)

• Executing If_Cov 4 b

• Train has not yet covered Photocell 4, next line is executed

Page 15: CCR Programming Language

Race Condition (cont.)

• Executing Jump a

• As the next line is being executed the train covers Photocell 4

Page 16: CCR Programming Language

Race Condition (cont.)

• Executing If_Cov 4 a

• The train has passed photocell 4, which creates an infinite loop

Page 17: CCR Programming Language

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

Page 18: CCR Programming Language

Exceptions

• One Train System

• Operates in Console Mode

• No API for C++ or VB programs to access CCR-asm commands

Page 19: CCR Programming Language

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

Page 20: CCR Programming Language

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

Page 21: CCR Programming Language

Q&A

Questions??

Page 22: CCR Programming Language

Track Data Structure

• Track[pc][6]• Counterclockwise

– Track[7][2] = -1– Track[7][0] = 2

• Clockwise– Track[7][3] = 2– Track[7][1] = 15

Page 23: CCR Programming Language

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

Page 24: CCR Programming Language

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

Page 25: CCR Programming Language

Extensions

• Two trains

• Higher Level Language

• Simulator

Page 26: CCR Programming Language

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

Page 27: CCR Programming Language

Conclusion

Thanks for Coming