Title: COCO
1COCO 18Programming Basics
- Programming Pragmatics
- Standard Constructs
- C-like Pseudo-Code
- Program Design
- Programming model
2Build a computer!
Basic Idea The Stored Program Computer Concept
RBUS
An instruction-controlled digital system with a
memory A sequence of instructions are stored in
memory This set of instructions constitute the
program that defines the machines behavior
MBUS
AC
A
B
Memory N bits wide 2M words
Memory
Address
ALU
FSM
MAR
S
ABUS
Opcode
IR
PC
MBUS
3Definitions
Program the sequence of instructions and
associated data values Programmer one who
creates, modifies, or maintains
programs Programming the act of creating
programsInitial design and planning,
documenting, coding into a language, testing, and
debugging Software often used as a synonym for
program
4Cold Hard Facts
- Software is expensive
- program development costs are more than an hour
of labor per machine instruction - Quality of much software and documentation is
poor - "All programs have at least one bug."
- "Testing proves the presence of bugs, not their
absence." - Testing and debugging usually takes more time
than the original planning and writing. - Thus, new software is usually completed later
than scheduled! - Programming is hard work
- There is no magic to remove the work, only a
method to work efficiently
5Kelley's 50 Rule
How do you write a program?
THINK
CODE
WRITE
TEST
50
75
87.5
Design the program
Write the program
Document the program
Debug, fix,and retest, redesign as needed
6Realistic Program Goals
What goals do you have when you write a program?
- Write the shortest program
- use the fewest number of bytes of memory
- Write the fastest program
- run as quickly as possible
- Write an easily understood program
- know what to change, fix, or modify
- Write an easily modified program
- cope with changes of environment or hardware
- Meet the schedule
- often at the cost of not meeting the other goals
Less important due to technology advances
7Pragmatic Programming
- Don't use a single item for multiple purposes
- makes debugging difficult
- Use no intimate knowledge of the hardware
configuration - 'reserved' bits/bytes might be used in later
hardware revisions - Avoid tricks
- avoid the 'clever' use of instructions
- Keep the instructions and data in separate
sections - avoids need to jump over data
- Use tables or structures for parameter and
related data - group data logically
- Put only constant data within the instructions
- changing data in instructions requires an
intimate understanding of its function in the
program - Don't write self-modifying programs
- can't run in ROM
- difficult to understand, debug, and modify
- Do use the instructions of the instruction set
well - use 'special/odd' instructions for certain
functions
8Flowcharting Symbols
9Standard Constructs
10Constructs ? Pseudo-code
Do Procedure 1 Do Procedure 2
11C ?Pseudo-Assembly Language
12More C ?Assembler
IF-THEN-ELSE IF( A 0) B ELSE B-- ENDIF
Fetch A, Test A, If (A 0) then Fetch
B, Increment B, Go to NEXT else Fetch
B' Decrement B, NEXT Store B
13More Constructs
14IN-CASE-OF Construct
ALL Standard Constructs have a single entry and
exit point
IF Case 1 True Do Procedure 1, Break IF
Case 2 True Do Procedure 2, Break
15Structured Loops
Unstructured premature loop termination
16More Loops
Unstructured premature loop termination
17Top-Down Design
An old and simple idea with a new name
- Divide and conquer
- Level 1
- Identify the major functional parts, or modules
- Level 2
- Next each module is broken into smaller parts. .
. - Level N1
- This process is continued until the parts are
known in enough detail to write and document the
original program
18Top-Down Implementation
An outside-in approach to integration
- Starts with the root of the top-down tree
- Implements the top level infrastructure first
- Integrates next level modules one at a time
- Requires stubs for unimplemented modules
- and so on for each module
- implement infrastructure then module-by-module
integration with stubs until the bottom level is
reached
19Bottom-Up Implementation
An assembly-line approach to integration
- Starts with the leaves of the top-down tree
- Implements the bottom level modules first
- Requires test programs for each modules
- Integrates fully tested modules to form higher
level module - Debugs the integration components
- and so on for each module
- integrate and debug with test programs until
finally the complete, integrated program is
working
20Programming Model (1)
Tri-Bus Computer
What does a programmer need to know to program
the computer?
Programming Model
1. Memory Model
2. Registers
3. Instruction Set
21Programming Model (2)
Memory Model
Number Notation denotes hexadecimal q 00 ..
11 h 0000 .. 1111
22Programming Model (3)
Registers
What registers do we need?
23Programming Model (4)
Instruction Set
Through the bus
How can we do this?
24Programming Model (5)
Instruction Format
16-bit Instruction
How many bits are needed for the OpCode? 2 How
many bits are needed to access any memory
location? 14
2-bit OpCode
14-bit Operand