1 / 38

Introducing hardware and computer languages

Introducing hardware and computer languages. March 17. Computer components. Monitor Motherboard CPU (Microprocessor) Sockets Main memory (RAM) Expansion cards Power supply unit Optical disc drive Hard disk drive (HDD) Keyboard Mouse. Motherboard. Input/output.

lore
Download Presentation

Introducing hardware and computer languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introducing hardware and computer languages March 17

  2. Computer components • Monitor • Motherboard • CPU (Microprocessor) • Sockets • Main memory (RAM) • Expansion cards • Power supply unit • Optical disc drive • Hard disk drive (HDD) • Keyboard • Mouse

  3. Motherboard Input/output Graphic card slot Processor Processor Slots for Storage devices Memory slots Power slot

  4. Motherboard A bus is a set of wires that connect the computer’s components. address data, or instructions Random Access Memory Buses are responsible for movement of data from input devices, to output devices and from/to CPU and memory.

  5. Memory • Memory is a large collection of circuits, each capable of storing bit. • Bit is a binary(base 2) digit: either 0 or 1 • Cells (words): manageable units; • Typical size is 8 bits (1 byte): Example: 01101011b • Some machines are 16 bits (2 bytes) and some are 32 bits or 64 bits • Byte (8 bits), • KB (kilobyte, 103≈210 bytes), • MB (Megabyte, 106≈220 bytes), • GB (Gigabyte, 109≈230 bytes). Note: k ≠ K because 1000 ≠ 1024.

  6. Most Significant Bit (MSB) Least Significant Bit (LSB) High-order end 0 0 0 0 0 1 0 1 Low-order end Memory To identify individual cells (bytes) in a machine’s main memory, each cell is assigned a unique name, called its address. H e l l o , ASCII ... ... Data 01001000 01100101 01101100 01101100 01101111 00101110 Address 0000 0101 0000 0110 0000 0111 0000 1000 0001 0001 0001 0010 Address Bus Data Bus • The organization of byte-size memory cell ASCII is symbolic coding table, where each symbol associated with a numerical code.

  7. Stored Program Concept • Instructions are represented as 32-bit numbers • Programs can be stored in memory • Can be read/written just like numbers/data Memory Payroll program Payroll data Word processor Processor Term paper C compiler Source C program

  8. Processor ControlUnit Registers are memory cells that work as scratch locations for storing intermediate results and values # Add 25 to A Registers ALUThis provides the basic operational units of the CPU A control unit: This unit is responsible for controlling flow of data and instructions. PC PC – program counter IR – instruction register IR

  9. Program execution (you can skip) Control Unit Memory 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 ... program & data Data path(bus) Fetch Decode Execute Cycle Input / Output

  10. Example of Processor Instructions • Arithmetic • add, sub, mult, div • Logical • and, or, ssl (shift left logical), srl (shift right logical) • Data transfer • lw (load word), sw (store word) • lui (load unsigned immediate constant) • Branches • Conditional: beq, bne, slt • Unconditional: j (jump), jr (jump register), jal

  11. Computer Languages temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; TEMP = V(K) V(K) = V(K+1) V(K+1) = TEMP High-level Language C/Java Compiler Fortran Compiler lw $t0, 0($2) lw $t1, 4($2) sw $t1, 0($2) sw $t0, 4($2) Assembly Language Assembler 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Machine Language

  12. Generations of Programming Languages 1GL: machine codes (0110 1101 1100 1010, …) 2GL: symbolic assemblers (add A, B) 3GL: (machine-independent) imperative languages (C = A + B). Examples are FORTRAN, Pascal, C languages 4GL: domain specific application generators (Python, LabVIEW, R, Matlab) Each generation is at a higher level of abstraction

  13. Machine Languages • Comprised of 1s and 0s • The “native” language of a computer • Difficult to program – one misplaced 1 or 0 will cause the program to fail. • Example of code:11101000101010 01110101011100 10111010110100 10100011110111

  14. Assembly Languages • Assembly languages are a step towards easier programming. • Assembly languages are comprised of a set of elemental commands which are tied to a specific processor. • Assembly language code needs to be translated to machine language before the computer processes it. • Example:ADD AX, 10 Register (temporary memory) inside processor

  15. High-Level Languages • High-level languages represent a giant leap towards easier programming. • The syntax of HL languages is similar to English. • Historically, we divide HL languages into two groups: • Procedural languages • Object-Oriented languages (OOP)

  16. Assembler vsHigh Level Languages • A “semantic gap” exists between the amount of information conveyed in assembly language vshigh level languages. Consider the following single statement: x = x + 3; • This single statement may require many assembly language statements (operations): Load memory location 24 into accumulator Add a constant 3 to the accumulator Store accumulator in memory location 24 • The number of executable statement expands greatly during the translation process from a high level language into assembly language.

  17. Procedural Languages • Early high-level languages are typically called procedural languages. • Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. • Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript

  18. Object-Oriented Languages • Most object-oriented languages are high-level languages. • The focus of OOP languages is not on structure, but on modeling data. • Programmers code using “blueprints” of data models called classes. • Examples of OOP languages include C++, Visual Basic.NET and Java.

  19. Languages’ similarities and differences Common Constructs: • basic data types (numbers, etc.); • variables; • expressions; • statements; • keywords; • control constructs; • procedures; • comments; • errors ... Uncommon Constructs: • type declarations; • special types (strings, arrays, matrices, ...); • sequential execution; • concurrency constructs; • packages/modules; • objects; general functions; • generics; • modifiable state; ...

  20. Machine code generation process • All programs need to be translated to machine code so that a computer can process the program. The machine code building process consist of compilation and linking compilation Source codes Object codes linking

  21. Compiler • Compiler is program that analyze source code and generates intermediate code. A compiler consists of: • The front end: Verifies syntax and semantics, and generates an intermediate representationof the source code for processing by the middle-end. • The middle end: Performs optimizations, including removal of useless or unreachable code, discovery and propagation of constant values, etc. • Generates another intermediate representation for the backend. • The back end: Generates the assembly code, performing register allocation in process.

  22. Linker • Alinkeris a computer program that takes one or more object files generated by a compiler and combines them into a single executable program.

  23. Interpreting • Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). • Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed. Examples are Javaand Python.

  24. Origin of Name Language Application Area Primitive assemblers (early 1950s) FORTRAN (1957) Scientific programming Formula Translation COBOL (1960) Business data Processing Common Business-Oriented Language Lisp (1960) Artificial Intelligence (AI) List Processing C (1972) System Programming Predecessor B Prolog(1970) Artificial Intelligence Logic Programming Ada (1980) Real-time distributed syst. Ada Augusta Byron & Charles Smalltalk(1983) GUI, OOP Objects “talk” via message C++ (1986) Supports object & OOP C (++ is the increment operator) JAVA (1995) Uses virtual machine Originally named “Oak” A Brief Chronology

  25. Developing a Program Programming as Problem Solving Problem solving principles Analyze the problem • Understand the problem Design the problem Devise a plan to solve Code the program Carry out the plan Test the program Review the results

  26. (1) Analyze the Problem Specify the problem requirements Important questions • What are the inputs? (given data) • What are the outputs? (required data) • How will we calculate the required outputs from the given inputs?

  27. (2) Design the Program • Create an outline of the program that solves the problem • An algorithm – a step by step procedure that will provide the required results from the given inputs. • Algorithm Examples: • Instructions on how to make a cake, • How to use the bank’s ATM, etc. • Flowchart is a good way to represent an algorithm start Get Data Processes Output Result stop

  28. (3) Code the Program • Once the design is completed, implement the program code. • Code is written in some programming language such as BASIC, Pascal, C++, Java, etc.

  29. (4) Testing the program • Locate any errors (bugs) • Testing is done throughout the development cycle • Desk-checking, or code walkthrough is performed to locate errors in the code. • Pretend you are the computer and execute your own code. • Ultimate test is to run the program to see if the outputs are correct for the given inputs.

  30. Modular programming • Determine the major tasks that the program must accomplish. Each of these tasks will be a module. • Some modules will be complex themselves, and they will be broken into sub-modules, and those sub-modules may also be broken into even smaller modules. • This is called top-down design

  31. Example: Calculate Electricity Bill • The rates that a company charges for electricity, based on kilowatt-hours (kWh) • The task is to develop a program that calculates energy costs. • The following information is provided First 360 kWh: $0.12589 per kWh Next 320 kWh: $0.17901 per kWh Over 680 kWh: $0.20971 per kWh Important questions • What are the inputs? • Energy rates per kWh • What are the outputs? • Total cost for a given kWh • How will we calculate the required outputs from the given inputs?

  32. Mapping Modules

  33. Code Modules • A module is an independent, self-contained section of code that performs a single task. • The main module is the module that drives the application. It “controls” all other modules. • When the main module calls another module, program control transfers to the called module. Program control cedes back to the main module when the called module finishes. Main Module Input Data Perform Calculations Output Results

  34. Problem classification • A programming language is a notational system for describing computation in a machine-readable and human-readable form. • Types of problems • Functional problems • Decision problems • Search problems • Optimization problems

  35. Programming problem examples • Polynomial root finding • Category: Functional problem • Input: A polynomial with real coefficients • Output: One (or all) real roots of the input polynomial • Matrix inversion • Category: Functional problem • Input: A square matrix with rational entries • Output: The inverse of the input matrix if it is invertible, or "failure” • Primalitytesting • Category: Decision problem • Input: A positive integer • Output: The decision whether the input integer is prime or not

  36. Programming problem examples • Weather prediction • Category: Functional problem • Input: Records of weather for previous days and years. Possibly also data from satellites. • Output: Expected weather of Seoul for tomorrow • Web browsing • Category: Functional problem • Input: A URL (abbreviation for "Uniform Resource Locator" which is colloquially termed as "Internet site”) • Output: Display (audio and visual) of the file at the given URL

  37. Programming problem examples • Traveling salesman problem (TSP) • Category: Optimization problem • Input: A set of cities, the cost of traveling between each pair of cities, and the criterion of cost minimization • Output: A route through all the cities with each city visited only once and with the total cost of travel as small as possible • Chess : Can I win? • Category: Search problem • Input: A configuration of the standard 8x8 chess board and the player ("white" or "black") who is going to move next • Output: A winning move for the next player, if existent, or "failure”

  38. Documentation Documentation plays an important role for programmers as well as for users. • Internal Documentation • Comments explain to the reader the logic and decision processes of the programmer. Comments are ignored by an interpreter or compiler. • Types of comments include code comments, documentation comments & module comments. • External Documentation • External documentation includes a user’s guide and, typically, a more technical system administrator’s guide.

More Related