140 likes | 208 Views
Introduction to Programming. Programming. Process of implementing a solution to a problem in a computer language Writing Testing Debugging Maintaining. Central Processing Unit. MEMORY. 76. Register A. Instr Addr. 1: SET A,10 2: READ B 3: ADD A,B 4: WRITE A …. 1. 30. Register B.
E N D
Programming Process of implementing a solution to a problem in a computer language • Writing • Testing • Debugging • Maintaining
Central Processing Unit MEMORY 76 Register A InstrAddr 1: SET A,10 2: READ B 3: ADD A,B 4: WRITE A …. 1 30 Register B CPU The CPU fetches an instruction using the instruction address register, and then executes the that instructions, and then prepares for the next instruction
Instructions • Instructions to a CPU are simple • Must be “executed” by hardware • Encoded as numbers • Math: Add, subtract, compare values • I/O: read, write • Memory: load/store • Execution in hardware = designing a circuit using “logic gates” : AND,OR,NOT and combining them together in a circuit • This is done by Electrical and Computer Engineers
Sequential Execution • Processors execute instructions one-by-one • The instruction address is updated to point to the next instruction • When we write code, we expect one instruction to be followed sequentially by the next • We can choose a different instruction to be next, but to do so, we have to update the instruction register in a special way
State of the Machine • The state of the machine • The contents of the memory and machine registers at a specific point in time • Instructions change the state of the machine • Instructions have a predictable change on the state of the machine • Programming is about finding a sequence of instructions that will change from one state of the machine to a desired state of the machine.
Early Programs • Early programmers wrote in Machine Language • Instructions were manually encoded as numbers Each instruction was dialed in by flipping switches, and connecting input and output of different units. ENIAC (from Wikipedia)
Assembly Language • Assembly Language • A human readable version of machine language • Still writing code directly for the machine Assembly still used for certain critical sections of code where performance matters. Requires years of training andexpertise to be a goodassembly language programmer.
Early Languages • FORTRAN • FORTRAN was an early language (1950’s) A Compiler converts the FORTRAN code into Assembly Language, and theAssembler converts to Machine Language.
Mid-Level Languages • C Language • C is a mid-level language (1970’s) Compiler still translates to machine language – but the compiler does more work than in the older languages – so the source code is a little more readable.
High-Level Languages • SQL is a high-level language • Instructions are interpreted as commands to a database engine – and one instruction in SQL can generate millions of machine language instructions. The problem with high level languages is that they limit what we can do with the machine – if the language doesn’t support it we cannot do it.E.g. cannot display graphics with SQL commands
Object Oriented • Object Oriented Programming (OOP) • A style of programming that organizes code and data together • In languages like C, there is code, and there is data; and they can be treated separately. • Very difficult to maintain as the project grows large • OOP organizes things into classes • classes define the data that are stored there • classes define the operations on the data • objects are instances of a class • This concept helps to quickly organize code and create high quality systems
OOP Languages • C++ is an OOP language
Other Languages LISP Smalltalk C#