COMPUTING SCIENCE 370
Programming Languages
Pseudo-code Interpreters
Machine Language
- Programming using a set of instructions directly implemented on a computer.
- Designed and organized to make a program easy to execute and fast, not easy to program or understand.
Complications
- limited primary storage (e.g., 2000 words)
- no built-in floating-point operations
- manual scaling -- numbers multiplied by scale factors (by the application program)
to keep them in the range of the integer arithmetic hardware.
- no index registers or indexed addressing modes
- address modification -- the program would use a memory location as an index variable,
adding the value there to the address part of a data-accessing instruction (i.e., the base address of an array)
prior to data access.
- early memory consisted of a rotating magnetic drum
- optimal coding -- use of a four-address opcode, with one field specifying the address of the
next instruction, so that the next instruction could be placed at or after the location the drum would have
rotated to while the current instruction was being executed.
| LOC |
OP |
DATA |
INST |
COMMENTS |
| 1107 |
46 |
1112 |
1061 |
Shall the loop box be used? |
| 1061 |
30 |
0003 |
1019 |
|
| 1019 |
20 |
1023 |
1026 |
Store C. |
| 1026 |
60 |
8003 |
1033 |
|
| 1033 |
30 |
0003 |
1041 |
|
| 1041 |
20 |
1045 |
1048 |
Store B. |
| 1048 |
60 |
8003 |
1105 |
|
| 1105 |
30 |
0003 |
1063 |
|
| 1063 |
44 |
1067 |
1076 |
Is an O2 operation called for? |
| 1076 |
10 |
1020 |
8003 |
|
| 8003 |
69 |
8002 |
1061 |
Go to an O1 subroutine. |
Early Program Design Notations
- flow diagrams (von Neumann and Goldstine) --> flowcharts
- mnemonics for opcodes --> assembler
- pseudo-code (Wilkes, Wheeler, and Gill) -- implements a virtual machine
- higher level, e.g., application-oriented data types (floating point) and operations (indexing)
- more regular -- fewer special cases
- easier to write and debug
- decreased chance of error
- increased security by allowing error checking
- compiling routines (Grace Hopper) vs. interpreter
- AUTOMATION PRINCIPLE
- Automate mechanical, tedious, or error-prone activities.
Pseudo-code example: IBM 650 (1955)
- machine: 2000 words of signed, 10-decimal-digit memory
- operations:
- FP arithmetic (+ - * / sqrt)
- FP comparisons (= != < <= > >=)
- indexing
- transfer of control
- I/O
- syntax:
- card reader for input, one instruction per card
- each instruction takes one word
- instruction format:
- divide address space into 1000-word data space and 1000-word code space
for interpreter and pseudo-code program --> impossible for program to overwrite itself or the
interpreter
- IMPOSSIBLE ERROR PRINCIPLE
- Making errors impossible to commit is preferable to detecting them after their commission.
Instruction Format and Security
Addresses must be limited to 3 digits, as only 1000-word data space.
How many addresses can be placed in an instruction?
- two-address instruction: x <- x + y
- leaves 4 digits plus sign for opcode, so 2 x 104 = 20,000 instructions available -- too many.
- three-address instruction: z <- x + y
- leaves 1 digit plus sign for opcode, so 2 x 101 = 20 instructions available
(of which we require about 15 different instructions).
Code format:
| |
CODE |
SOURCE 1 |
SOURCE 2 |
DEST |
| ± |
1 digit |
3 digits |
3 digits |
3 digits |
Instruction table:
| OP |
+ |
- |
|
| 0 |
z <- (x) |
|
move |
| 1 |
z <- (x) + (y) |
z <- (x) - (y) |
add / subtract |
| 2 |
z <- (x) * (y) |
z <- (x) / (y) |
multiply / divide |
| 3 |
z <- square(x) |
z <- sqrt(x) |
square / square root |
| 4 |
if (x) = (y) goto Z |
if (x) != (y) goto Z |
test equality |
| 5 |
if (x) >= (y) goto Z |
if (x) < (y) goto Z |
test inequality |
| 6 |
z <- (x + (y)) |
y + (z) <- (x) |
indexing |
| 7 |
x <- (x) + 1
if (x) < (y) goto Z |
|
increment and test (looping) |
| 8 |
read into z |
print (x) |
I/O |
| 9 |
stop |
|
halt |
lowercase = data space; uppercase = code space; ( ) = contents of address
Principles illustrated by the operation table:
- ORTHOGONALITY PRINCIPLE
- Independent functions should be controlled by independent mechanisms.
- orthogonal
- right-angled; varying independently (as along different axes)
- reduces the amount of memorization needed: learn m + n, not mn
| m |
| |
|
| ... |
| |
mn |
| 2 |
| |
|
| 1 |
| |
______________ |
| |
|
1 2 3 . . . n |
- REGULARITY PRINCIPLE
- Regular rules, without exceptions, are easier to learn, use, describe, and implement.
- may be in conflict with the Orthogonality Principle, as some of the m * n possibilities may
be useless, difficult to implement, or illegal --> must be remembered as exceptions (remember
m + n + e vs. mn - e)
- ABSTRACTION PRINCIPLE
- Avoid requiring something to be stated more than once: factor out the recurring pattern.
Questions
- What is the read-execute cycle?
- Debugging: What is a trace? What is the difference between a breakpoint and
a data trap?
- What principle would motivate us to add support for symbolic labels to our interpreter?
- What data structure is used to associate symbolic labels with data addresses (variables)?
- What principle would motivate us to perform bounds checking during array references
(operations +6 and -6)?
- What does it mean for a tool to be ampliative? reductive?
Copyright © 2000 Jonathan Mohr