3 Recall: A Computer System is … HardwareCentral processing unit (CPU)Main memory (RAM, ROM)Secondary memory (Hard disk, CD, DVD, flash drive, etc)Input devicesOutput devicesNetwork interfacePower supplySoftwareFirmwareOperating systemApplication programs
4 What is a Software “Program”? A set of instructionsPerforms a specific taskRequired to make the hardware “do something”The hardware “runs” or “executes” itMust be in main memory (RAM or ROM)Is written in machine language (specific to a CPU)Consists of binary ‘1’s and ‘0’s
5 How a Program gets into Memory It is always stored in memory (ROM)Firmware such as a PC BIOSEmbedded systems contain ROM or FlashFrom secondary storage when neededRead from the Hard Disk into main memoryRead directly from a CD or DVD into main memoryVia the networkAutomatic updates from the program vendorWeb pages and web applications with active contentMobile applicationsCloud computing
6 Programs are Very Diverse … Mobile applications – Info services and transactionsWeb applications – Web pages, shopping, Virtual LibraryBusiness applications – Word processing, , accountingLeisure applications – Games, e-book readersEducational applications – Language learning, encyclopediaBatch data processing – Payrolls, bank statementsServer software – Provide information services via webOperating systems – Control hardware, software, securityControl systems – Automation, energy managementEmbedded software – Routers, printers, appliances, automobiles, cameras, watches, cell phones, lighting control
7 …But Programs Have Much in Common Programs process informationInformation is stored in the form of binary dataDifferent types of information use different data typesPrograms acquire input dataPrograms produce output dataPrograms are implementations of algorithmsAlgorithms are precise solutions to problemsPrograms are written in programming languagesMay be compiled (translated) to machine languageMay be compiled to intermediate form and then interpreted
8 This Class Introduces Programming Programming is the discipline and art of creating softwareFocus is on fundamental concepts and building skillsExamples, labs, and projects will use the C languagePrerequisite class – NT1110 Computer Structure & LogicFuture classes:ELCT: ET2640 Microprocessors and MicrocontrollersELCT: ET2750 Programmable Logic ControllersEECT: ET4560 C++ ProgrammingEECT: ET4640 Embedded Systems
9 Programs Relevant to Electronics Unit 1: Programs
10 Program-based Solutions Programs used to solve electrical engineering problemsSolutions of equations needed for design and analysisExample: Iterative calculations of roots of complex polynomialsExample: – Knowledge computation engineTry: “0.45 ohms per foot for 100 meters”Simulation software to try circuit design before buildingMultisimChip design softwareCost is hundreds of thousands of dollars per workstationOne design engineer can access immense libraries of knowledgeSimulations can save millions in time and manufacturing costs
11 What is a Control System? An electronic control system is a device that:Regulates a process (such as a manufacturing system)Components:Sensors – Convert physical variables to electronic signalsControllers – Based on sensor data, send signals to actuatorsActuators – Use electronic signals to affect physical worldExample: A commercial baking ovenExample: An automobile engineThe controller can be …Analog electronicsHard-wired digital electronicsA programmable computer-based controller
12 Benefits of Programmable Control Flexibility – can be reprogrammedUpgradableCan have optional featuresDefects can be easily repairedLower engineering costsStandard hardware designs availableSoftware designs can be reusedSelf-testing and error reportingProgrammable logic controllers – PLCsOff-the-shelf hardwareSimplified programming
13 Embedded Systems Found everywhere as part of electronic devices Examples: Watches, calculators, appliances, irrigation and lighting systems, copiers, traffic lights, MP3 playersPre-programmed computerDedicated to a few functions inside a deviceOften must be real-time (respond “immediately” to events)Non-stop computing (continuously functioning)Traditionally viewed as non-reprogrammableReprogrammability is becoming commonplaceTherefore, programming is essential to electronics students!
14 How are Programs Created? Unit 1: Software Development Process
15 Creating a Program Use problem solving skills Create an algorithm Implement the algorithm in a programming languageUnderstand the programming modelUse specialized toolsUse software engineering methodology
16 Use Problem-Solving Process Heuristics (strategies) for successful problem solvingFive-step process (from Strategies for Creative Problem Solving, Fogler et al)Define the problemGenerate possible solutionsEvaluate and decide on a solutionImplement the solutionEvaluate the solution
17 Develop Problem-Solving Skills A good programmer is an effective problem solverHas a belief that problems can be solved through analysisDevelops a high level of problem-solving skills:Active – Makes sketches, draws figures, asks questionsMethodical – Keeps track of progress in solving the problemDetail-orientedTakes great care to understand facts and relationshipsChecks and re-checks for accuracy
18 Create an Algorithm Develop an algorithm before writing a program Use precise statementsBased in mathematics and logicClear and concrete languageDefine a step-by-step processGoal is solution to a problem
19 Use a Programming Language A computer’s CPU uses machine languageConsists of binary values representing instructionsNot practical for human programmersAssembly languageLow-level language closely tied to machine languageOnce widely used, now only specialized useHigh-level languagesHundreds to thousands of languages in useMuch easier to use than assembly and machine languageCompiler provides automatic translation to machine language
20 Based on a Programming Model The operating system (OS) presents the programming modelAn OS is used on all but the smallest computersControls the hardwareStandardizes access to files, shared resourcesMay be console user interface or graphical (GUI) user interfaceConsole-based user interfaceCalled “command-line” accessBased on text serial input and outputGraphical user interface (GUI)Based on point-and-click or touch screen and windowed interfaceEvent-driven, object-oriented modelEmbedded systems may not have a user interface at all
21 The Compiler Approach A compiler is a translation program Input is written using a programming languageOutput is assembly language for one specific CPU instruction setAssembler may be included or separateCompletes the translation into machine languageLinkerCombines translated program pieces with library piecesCreates a complete, executable moduleOperating system and loaderLoads module into main memory and starts executionProcess must be done again for each type of “host” system
22 The Interpreter Approach Compiler creates an intermediate representationProgram is neither in high-level language, nor machine languageInstead, it is “virtual instructions” in an intermediate languageThe virtual instructions are the same for all CPUsInterpreter follows the virtual instructionsA different interpreter is needed for each CPU typeBenefitsA single compilation can theoretically be used on all computersPresents a common programming model on multiple CPUsDrawbackInterpreters are slower than compiled (“native”) programs
23 The “Just-In-Time” (JIT) Approach CompilerCreates an Intermediate Language (IL) representationRuntime systemDoes not interpretContains a “compiler” which completes compilationResult is machine language produced just before executionBest of both worldsCode can be “Compiled once, Run anywhere” (e.g. Java, .NET)Single programming model regardless of computer hostProgram execution speed is comparable to native code
24 Specialized Programming Tools EditorCompilerAssemblerDebuggerSupport filesLibrariesIntegrated development environmentComplete package of toolsUses a “project-based” approach
25 Software EngineeringWaterfall model, iterative model, agile developmentProcesses to move from idea to productLifecycle managementBeginning-to-end product managementIncludes program maintenance over timeSupport and structure for working in teamsCoding standardsChange controlProject managementHuman factors“User friendly” design, ease of use
27 Software Development Method Specify the problem requirementsAnalyze the problemDesign the algorithm to solve the problemImplement the algorithm as a programTest and verify the completed programMaintain and update the program
28 Analyzing the Problem Requires identifying the … Inputs – the data available to work withOutputs – the desired resultsIncluding the format of the outputAdditional requirementsConstraints
29 Producing the Algorithm List of steps from beginning to endBegin at step 1, have a specific step to EndDon’t try to get every detail at firstUse top-down design:Break the problem into subproblemsSolve each subproblem individuallySimilar to outlining a written paperUse pseudo-code combined with flowchartingDesk-check the algorithm
30 Convert the Algorithm to a Program Implement the flowchart and pseudo-code as a programVerify that the program compilesTest the programCreate several test cases and verify the resultsTest boundary conditionsEnter erroneous data intentionallyIf the program behaves unexpectedly, back upDouble-check the algorithm, modify if neededDouble-check the program, modify if neededUse debugging tools and techniques
31 Identify Variables Information in an algorithm is put into variables A variable is the programming term describing the storage of a single datum or a collection of data.In a program, the compiler will put the variables into memoryEach data item used in the algorithm should be given a nameEach name should be distinct and used for only one variableData types for variables include:Integers: 0, 12, -53Decimal numbers: 22.76, 193.1Decimals in scientific notation 3.0x108Character strings (in double-quotes) “Programming is fun!”
32 Simple Example: miles to kilometers Problem statement “Convert a distance in miles to kilometers”Identify the inputs dist_in_miles A decimal number representing a distance in milesIdentify the outputs dist_in_kms A decimal number representing the distance in kilometers
33 List the Steps to Solve the Problem Break the problem into steps:Input the dist_in_milesConvert dist_in_miles to kilometersOutput the dist_in_kmsAs you can see, step 2 is not precise, because it does not specify how to do the conversion. This is not yet a complete algorithm.
34 What is the Formula for Step 2? One mile is equal to approximately equal to kmA number of miles can be converted to kilometers by multiplying by 1.609The formula is:dist_in_km = dist_in_mi × 1.609
35 Algorithm to Convert mi to km Input the dist_in_milesConvert dist_in_miles to kilometersMultiply dist_in_miles by 1.609Put the result in dist_in_kmsOutput the dist_in_kmsEndThis algorithm accomplishes the task, but it is not user-friendly. We need to add some human factors to the algorithm.
36 An Improved Algorithm Output “Convert miles to kilometers” Output “Please enter the distance in miles”Input dist_in_milesConvert dist_in_miles to kilometersMultiply dist_in_miles by 1.609Put the result in dist_in_kmsOutput “The distance in kilometers is ”Output dist_in_kmsEndAs you can see, creating a good algorithm requires substantial effort and attention to details
37 An Algorithm to List #s < 10 Output “List of Numbers less than 10”Put 1 in numberOutput numberAdd 1 to numberIf number is less than 10, go back to step 3EndNotice this algorithm has no inputs, only one variable, “number”
38 An Algorithm to List Odd #s < 10 Output “List of Odd Numbers less than 10”Put 1 in numberIf number is even, skip to step 5Output numberAdd 1 to numberIf number is less than 10, go back to step 3EndIs this an algorithm? Is step 3 sufficiently precise?
39 An Algorithm to List Odd #s < 10 Output “List of Odd Numbers less than 10”Put 1 in numberIf number divided by 2 has remainder 0, go to step 5Output numberAdd 1 to numberIf number is less than 10, go back to step 3EndNow we have precise instructions which can be followed!