BU CS 101 - The Programming Language Continuum
Pages 45

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 459-1Programming•Remember:–intro programming concepts–intro generations of programming languages–what instructions look like in memory–how to program (conceptually)•In this lecture:–generations of programming languages–what instructions look like in memory–how to program (conceptually)–programming the “ROBOT” computer9-2The Programming Language Continuum•In the beginning… To use a computer, you needed to know how to program it.•Today… People no longer need to know how to program in order to use the computer.–In fact, programming has become easier as well–programming languages “evolve” from low-level to high-level.–Fifth Generation - Natural Languages–Fourth Generation - Non-Procedural Languages–Third Generation - People-Oriented Programming Languages–Second Generation - Assembly Language–First Generation - Machine Language (code)HighlevelLowlevel9-3Representing (Instructions) Programs•Arithmetic Instructions–Addition, subtraction, multiplication, division, and other numeric operations•Data Movement Instructions–Move numbers from place to place in the computer•Logical or Comparison Instructions–Decision making instructions e.g. x < 10•Control Instructions–Controls the sequences in which instructions are executed e.g. for x = 1 to 10•Input/Output Instructions–Allow the program to communicate with something outside the program (user, monitor, network, other programs)9-4Representation of Programs•Program: A collection of instructions for the computer.–Instructions are broken down into an opcode and an operand•Opcode – what to do•Operand – additional info needed to do the opcode•Instruction – opcode + operand–For some specific given CPU, imagine there are only eight valid opcodes (shown below)READ PRINTADD SUBSTORE LOADPJUMP STOP9-5Representation of Programs–Although we could simply use the ASCII codes and store each command as a collection of characters ...•at some point the CPU will need to be able to “make decisions” based on opcodes – i.e., these opcodes will be binary input to the Instruction Decoding Unit•To have the CPU directly understand ASCII would require many more wires/bits input into the CPU•Map each opcode into a binary numberREAD = 000LOAD = 001ADD = 010etc..•And each operand will also be in binary such that the entire instruction is binary–Ex: 001 11001–What does the operand 11001 mean? –It could be a number, a symbol, a sound, a pixel of an image... –It’s the context (program/instruction) that gives meaning9-6Generation I: Machine Language•Machine language programs made up of instructions written in binary code. •Computers operate in their “native” language•Humans translate their instructions into binary•Each instruction has two parts: Operation code, Operand–Operation code (Opcode): The command part of a computer instruction.–Operand: The address of a specific location in the computer’s memory.–You write programs in the “lowest-level” language directly for the CPU. •Opcodes do very simple things (the computer is “dumb”) and you have it perform more complicated tasks by combining these instructions.9-7Generation I: Machine Language•example . . .Store the accumulator value into memory location “15” 011111013Add the contents of memory slot “13” into the accumulator011010112Load contents of memory slot “14” into accumulator011101001MeaningOperandOpcodeInstruction # (slot #)9-8Generation I: Machine Language•Machine language –Hardware dependent: Could be performed by only one type of computer with a particular CPU.–That is, each computer (although all speak binary) might have different arrangements of 1s and 0s for different instructions.»“Different words could have different meanings”»Maybe some computers can’t do the same things–111 might be add to me, but 010 might be add to you..9-9Generation II:Assembly•Second Generation - Assembly Language–Assembly language programs are made up of instructions written in mnemonics. –Mnemonics: Uses convenient alphabetic abbreviations to represent operation codes, and abstract symbols to represent operands.–Each instruction (still) had two parts: Operation code, Operand»One-to-one mapping from written instruction to machine instruction–Still a “low-level” language–“higher level languages”»Easier on the programmerREAD num1READ num2LOAD num1ADD num2STORE sumPRINT sumSTOP9-10The Programming Language Continuum•Second Generation - Assembly Language–Assembly language programs are made up of instructions written in mnemonics. »Because programs are not written in 1s and 0s, the computer must first translate the program before it can be executed.»The translation is a direct translation»We translate into machine codeREAD == OPCODE 001num1 == Memory 0000 1110…READ num1READ num2LOAD num1ADD num2STORE sumPRINT sumSTOP9-11Assembled, Compiled, or Interpreted Languages•Assembled languages: –Assembler: a program used to translate Assembly language programs.–Produces one line of binary code per original program statement.•The entire program is assembled before the program is sent to the computer for execution.9-12Generation: III•Third Generation – High-level languages–Instructions in these languages are called statements. •High-level languages: Use statements that resemble English phrases combined with mathematic and logical terms needed to express the problem or task being programmed.•As before, programs are not written in 1s and 0s, the computer must first translate the program before it can be executed.–Instructions are more complicated – one may actually represent several simple opcodes–NOT-Hardware dependent. “portable”–So, as long as you can translate the statements from this language to another machine code, you can run it on that platform. (more on this later)9-13High Level Language Example•Pascal Example: Read in two numbers, add them, and print them out.Program sum2(input,output);var num1,num2,sum : integer;begin writeln(”please enter num1”);


View Full Document

BU CS 101 - The Programming Language Continuum

Download The Programming Language Continuum
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Programming Language Continuum and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Programming Language Continuum 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?