CS 342 Lecture -*- Outline -*- * Design of a Pseudo-code (for scientific computation) ** What types of data? floating point numbers arrays (of floating point numbers) indexes into arrays ** What functions? floating point: arithmetic, comparison, I/O arrays: initialization, indexing control-flow (based on results of comparisons), looping Floating point functions: Arithmetic identity (move) addition, subtraction times, division exponentiation, logarithm (arguments literals or addresses?) Comparison and control flow branch if equal, branch if not equal (floating?) branch if greater or equal, branch if less than I/O read, print Array operations Initialization (not done at run-time) Indexing assignment of element, extraction of elements Control flow see comparisons (above) looping initialization (use move?) increment and test, perhaps decrement and test end (of program) Why looping? abstraction: avoids repeating body of loop, wouldn't know how many times to repeat it anyway. can be implemented efficiently arithmetic only applies to floating point Note: floats have to act as indexes, otherwise need new set of ops (e.g., move) -violates representation independence (principle): programs should be independent of how data is represented. ** Syntax (decide on syntax after deciding what is to be done) Assign codings to functions. IBM 650: 2000 words of 10 digit (signed decimal) memory. 1000 for data, 1000 for program (+ interpreter) Each instruction fits in one word (easier to implement interpreter), Instruction format: How many operations? (count them) How many addresses? (3) Address size? (3 digits) *** Program Structure have to think about composing things, initializing use +9 999 999 999 as separator between initial data, program and input data. *** Orthogonality principle Independent functions controlled by independent mechanisms (concrete:) 2 axis description of functions, sign for inverses 2 axis diagram: m*n > m+n *** Regularity Principle regular rules, without exceptions are easier to learn, use, describe, and implement (concrete:) each operation has same format. *** Security principle (abstract) no program that violates language defintion, or its own declared intentions, should escape detection (concrete) shouldn't be able to address ourside data area -helps make debugging easier. -trivial to enforce in this instance? what about array indexing? Quiz on principles, pseudo-code: 1. Define regularity. rules should apply without exception similar things should be expressed in similar ways 2. Give an example of regularity in pseudo-code. sequence of +, times, square use of same separator in two places 3. Define orthogonality independent features should be controled by independent mech. separation of mechanisms for each task 4. Give an example of orthogonality in pseudo-code use of sign vs. number in syntax of op-codes 5. Define security. programs should not be allowed to violate the language def. programs should not be allowed to violate their intentions (need 2 pieces of information) 6. Give an example of security in pseudo-code. checking for out of bounds addressing accomplished largely by not permitting programs to use illegal addresses. question: does this catch everything? 7. What should be the inverse of "move"? negation constant operation (e.g., zero) literal