🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Chapter 4_Computer Language (1).pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Computer Language Chapter 4 Contents Machine Programming Programming Levels of Program language process languages programming translator programming languages Learning Objectives At the end of this c...

Computer Language Chapter 4 Contents Machine Programming Programming Levels of Program language process languages programming translator programming languages 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. Machine Language Programming Machine Language Programming What is programming language? – A language for instructing a computer What is source code? – A complete program in such language What is machine language? – The most primitive type of programming language that a computer understands (instruction can be executed by the CPU) Machine Earliest form ofLanguage programming MostProgramming 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 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 Machine Language Programming High Level Language Program Language Processing Machine Language Code Decoder Micro Steps (Micro Code) Control Signal Memory Bus System ALU etc. Translation from SW to HW HW Programming Process Programming Process What is programming What is program? Language? A set of rules that provide a way of telling Set of step-by-step instructions that direct a computer what operations to perform. the computer to do the task users want it to do and produce the results. Programming process includes: – define the problems – plan the solution through developing an Programming algorithm that includes the Process flowchart and pseudo-code – coding the program – test the program – document the program 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. Programming Process Planning the solution – The most common way of planning is by having flow charts or writing pseudo-code – Flowchart is a pictorial diagram of an ordered step-by- step solution to a problem Process Start or Stop Program Decision Input or Output Connector Direction of Flow ANSI Standard Flow Chart Symbols Programming Process Example of simple flow chart – of what to do if a lamp doesn’t work Programming Process Planning the solution – Pseudo-code is an English-like language that states the solution with more precision in English but Programming Process 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 Programming Process Coding the programs – The programmer translates 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 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. Documenting the program – Is necessary and is an ongoing process. – Documentation is a written detailed description of the programming cycle and specific facts about the program. – Typical program documentation materials include: Programming The origin and the nature of the Process 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. Programming Languages 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. Programming Languages Users Higher Lower Machine 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. 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. High-level Language (HLL) – More English-like – thus making it more convenient – FORTRAN (FORmula TRANslator) is the 1st Programming HLL – Other examples of HLL Languages are COBOL, BASIC, ALGOL, APL, FORTH, LISP, LOGO, Modula-2, PILOT, PLI, PROLOG and RPG. 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. 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). 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. 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 Programming objects. Languages – Current examples of visual programming languages are Object Vision and Visual Basic (VB). Program Translator 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 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 Output File ADD AX, 0010 10111000000001010000000 ADD AX, 002 Assembler 00000010100010000000000 MOV , AX 00000001010010000000000 INT 20 0001010001100100000 Symbolic Binary program program Program Translator Operand1 Notes that: ADD AX, 0010 05 10,00 ADD translated into 05 AX translated into Opcode in Operand1 Opcode in Operand2 000010 translated into Machine 1016 Assembly Language Operand2 Language Machine Language (Binary) Machine Language Assembly 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 ,AX 10100011 00100000 00000001 A3 20 01 INT 20 11001101 00100000 CD 20 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 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. 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 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. 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. Compiler – Control structure Example of control structure includes unconditional branches (such as GOTO statement Program or subroutine call), Translator conditional branches (such as IF-THEN-ELSE statement), and loops (such as WHILE-DO, FOR and REPEAT-UNTIL statement). 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 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. 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 End of Chapter 4

Use Quizgecko on...
Browser
Browser