Anzeige
Anzeige

Más contenido relacionado

Anzeige
Anzeige

Chapter 4 computer language

  1. Computer Language Chapter 4
  2. Contents • Machine language programming • Programming process • Programming languages • Levels of programming languages • Program translator
  3. Learning Objectives • At the end of this chapter, students should be able to: – Identify and utilize the programming processes. – Identify the different levels of programming languages. – Identify and differentiate the program translators.
  4. Machine Language Programming
  5. Machine Language Programming • What is programming language? – A language for instructing computer • What is source code? – A complete program in such language • What is machine language? – The most primitive type of programming language that computer understands (instruction can be executed by the CPU)
  6. Machine Language Programming • Earliest form of programming • Most tedious and time consuming since it requires programmers to: – determine the exact set of primitive machine actions (instructions) necessary to perform complex task – write down each instruction in an understandable form to the computer
  7. Machine Language Programming • Computer’s instruction set are defined by the set of data manipulation and movement functions of which the CPU is capable to perform. • The processing functions of a typical CPU can be classified into 3 categories: – Computation – perform mathematical calculation using two numbers as input and store the result – Comparison – compare the values of two stored numbers and determine if they are equivalent – Data movement – move an individual item of data from one storage location to another storage location
  8. Machine Language Programming High Level Language Program Machine Language Code Micro Steps (Micro Code) Memory Bus System ALU etc. HW Decoder Control Signal Language Processing Translation from SW to HW
  9. Programming Process
  10. Programming Process • What is programming Language? – A set of rules that provide a way of telling a computer what operations to perform. • What is program? – Set of step-by-step instructions that direct the computer to do the task users want it to do and produce the results.
  11. Programming Process • Programming process includes: – define the problems – plan the solution • through developing an algorithm that includes the flowchart and pseudo-code – coding the program – test the program – document the program
  12. Programming Process • Defining a problem: – Programmer meets users of the client organization or system analyst will analyze the problems. – Written agreement is produced. – Items of input, process and output are being identified.
  13. Programming Process • Planning the solution – Most common way of planning is by having flow charts or write pseudo-code – Flowchart is a pictorial diagram of an ordered step by step solution to a problem
  14. Programming Process Process Decision Connector Start or Stop Program Input or Output Direction of Flow ANSI Standard Flow Chart Symbols
  15. Programming Process Example of simple flow chart – of what to do if a lamp doesn’t work
  16. Programming Process • Planning the solution – Pseudo-code is an English-like language that states the solution with more precision in English but less precision than is required when using a formal language. – Example: if credit card number is valid execute transaction based on number and order else show a generic failure message end if
  17. Programming Process • Coding the programs – The programmer translate the logic from the flow chart or pseudo-code to a programming language or source code – The programmer has to know the syntax and the format of writing the programming
  18. Programming Process • Testing the program – Involve the desk-checking, the translating, and the debugging phases. • Desk-checking involves a programmer sitting down to proof-read a program. • Translating involves a translator – using compiler or interpreter (a program that translates the instruction into a form the computer can understand). • Debugging involves detecting, locating, and correcting bug or mistakes or errors by running the program.
  19. Programming Process • Documenting the program – Is necessary and is an ongoing process. – Documentation is a written detail descriptions of the programming cycle and specific facts about the program. – Typical program documentation materials include: • The origin and the nature of the problem. • A brief narrative description of the program. • Logic tools such as flowcharts, pseudo-codes and/or flow charts. • Data record descriptions • Program listings and testing results.
  20. Programming Languages
  21. Programming Languages • Programming languages are said to be lower (closer to the computer) or higher (closer to people/users). • There are five generations of programming languages to be enlisted from the lowest to the highest levels, which are: – Machine language. – Assembly language. – High-level language (HLL). – Very high-level language (VHLL). – Natural language.
  22. Programming Languages Higher Lower Machine Users
  23. Programming Languages • Machine language – The lowest level of language – Represents data as 1s and 0s (binary digits corresponding to the “on” and “off” electrical states (switching actions) in a computer.
  24. Programming Languages • Assembly language – Uses mnemonic codes – Mnemonic codes are abbreviations that are easy to remember and to replace the machine language numbers – Even though not in English words, they are still convenient and are preferable than numbers alone. – Uses an assembler program to turn its program into a machine language. – Has disadvantages such as vary by machine, extremely detail, making programming becomes repetitive, tedious and prone to making errors.
  25. Programming Languages • High-level Language (HLL) – More English-like – thus making it more convenient – FORTRAN (FORmula TRANslator) is the 1st HLL – Other examples of HLL are COBOL, BASIC, ALGOL, APL, FORTH, LISP, LOGO, Modula- 2, PILOT, PLI, PROLOG and RPG.
  26. Programming Languages • Very high-level language (VHLL) – Known as a 4th generation language (4GL) – Usually nonprocedural (user need to write only “what” is to be done but not “how”. – A procedural language tells the computer how a task is done (a very specific step-by-step process) – Advantages - increase productivity, require minimal training and allow users to be unconcern about the HW or program structure.
  27. Programming Languages • Natural language – Is named because of its resemblance to spoken English. – Referred to as knowledge-based language due to its usage in interacting with a base of knowledge on some subject, resulting in a knowledge-based system (KBS), such as an expert system. – Natural language excel at easy data access – This has evolved into a language namely structured query language (SQL).
  28. Programming Languages • Object-oriented programming (OOP) – A group of languages : called object-oriented language (OOL) group. – OOL is based on a more active, visual programming environment. – Structured languages treat data and tasks (instructions) separately. – OOL views data and tasks together for each object (entity that may be grouped in classes and contains its own code). – Current examples OOP languages are Object Logo, JAVA, C++, Turbo Pascal, and SmallTalk.
  29. Programming Languages • Hybrid object-based programming languages – Are visual in a manner similar to OOP language but lack certain features. – The 1st hybrid language : HyperCard (Macintosh) – Some object-based hybrids are classified as visual programming languages because they are distinguished by the ability to build programs connecting links between various objects. – Current examples of visual programming languages are Object Vision and Visual Basic (VB).
  30. Program Translator
  31. Program Translator • What is program translator? – A program that transform/translate source code into machine readable code. • There are 3 types of program translator: – Assembler – Compiler – Interpreter
  32. Program Translator • Assembler – A program that translates the instruction (assembly language code) into a form that computer can understand (machine language code). MOV AX, 0005 ADD AX, 0010 ADD AX, 002 MOV [0120], AX INT 20 Assembler Output File 1011100000000101000000 0000000101000100000000 0000000001010010000000 0000001010001100100000 Symbolic program Binary program
  33. Program Translator ADD AX, 0010 05 10,00 Opcode in Assembly Language Operand1 Operand2 Opcode in Machine Language Operand1 Operand2 Notes that: ADD translated into 05 AX translated into 000010 translated into 1016 Assembly Language Machine Language (Binary) Machine Language (Hexadecimal) MOV AX,0005 10111000 00000101 00000000 B8 05 00 ADD AX,0010 00000101 00010000 00000000 05 10 00 ADD AX,0020 00000101 00100000 00000000 05 20 00 MOV [0120],AX 10100011 00100000 00000001 A3 20 01 INT 20 11001101 00100000 CD 20
  34. Program Translator • Compiler – A compiler translates a program in a programming language – The original program is called the source code – The result of translating source code is called the object code
  35. Program Translator • Compiler – How a compiler compile a program? • Source code is read from a file by the compiler and object code is written to a newly created file • The source code file is named to indicate the programming language, such as program.java where “.java” indicates a JAVA program • Object code filenames generally have an “.o” or “.obj” appended to original root filename, such as program.o or program.obj.
  36. Program Translator • Compiler – Source code statements are read into the compiler one at a time – 3 classes of source code statements are: • Data declaration • Data operation • Control structure
  37. Program Translator • Compiler: – Data declaration: • Set memory locations to store the declared data. • The amount of memory allocated depends on the type of the data, such as integer, real, character etc. • The compiler builds an internal table, known as symbol table to keep track of the data names, types and assigned memory addresses.
  38. Program Translator • Compiler – Data operation • As data operations are encountered in source code, they are translated into the sequence of machine instructions necessary to implement those operations. • These instruction sequences include primitive data manipulation instructions as well as any necessary data movement instructions.
  39. Program Translator • Compiler – Control structure • Example of control structure includes unconditional branches (such as GOTO statement or subroutine call), conditional branches (such as IF-THEN-ELSE statement), and loops (such as WHILE-DO, FOR and REPEAT-UNTIL statement).
  40. Program Translator • Compiler – Support Libraries • The object code consists entirely of executable machine instructions and data such as executable code. • Certain types of language statements, including data declarations, control structures are converted into executable codes (external subroutines). • These external subroutines can be found in either one of these places: – Compiler library – Library call
  41. Program Translator • Compiler – Linking • Note that, the preceding library call is not a CPU instruction. • Library call is a reference to a set of executable code that has been previously compiled and stored in a library for later use. • Therefore, it must be replaced by the corresponding library code before application can be executed. • A program called a linker or link editor performs this replacement. • The process of replacement is called linking, link editing or binding.
  42. Program Translator • Interpreter – While compilation process is in progress, link editing and program execution cannot occur until the entire source code file has been compiled – In contrast, interpretation interleaves source code translation and execution – An interpreter reads a single statement of the source code, translates into machine instruction, and immediately executed – One program (the interpreter) translates and executes another (the source code) one statement at a time
  43. End of Chapter 4
Anzeige