algorithms, computer systems, and programming...

10
1/10/18 1 Algorithms, Computer Systems, and Programming Languages CSC121, Introduction to Computer Programming overview what is a computational process? what is an algorithm? what is a computer ? brief overview of computer organization computer processing as a discrete state machine assembly language programming high-level language programming the landscape of computational problems Computational Processes a computational process denotes a collection of rules, or a sequence of operations or transformations whereby some resulting information is derived from a set of initial or given information and conditions. Algorithm an algorithm is a plan for directing a computational process. algorithms should satisfy these conditions each of the steps must be clearly and precisely defined. each step must be effective (for the agent executing the process) the steps must be ordered properly the process must terminate at some point

Upload: others

Post on 27-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

1

Algorithms, Computer Systems,andProgramming Languages

CSC121,IntroductiontoComputerProgramming

overview

• whatisacomputational process?• whatisanalgorithm?• whatisacomputer?• briefoverviewofcomputer organization• computer processingasadiscrete statemachine• assemblylanguageprogramming• high-level languageprogramming• thelandscapeofcomputational problems

ComputationalProcesses

• acomputational process denotes acollectionofrules, orasequence ofoperations ortransformations whereby some resultinginformation isderived from asetofinitial orgiven information and conditions.

Algorithm

• analgorithm isaplanfordirecting acomputational process.

• algorithms shouldsatisfytheseconditions– eachofthestepsmustbeclearly andpreciselydefined.

– eachstepmustbeeffective (fortheagentexecuting theprocess)

– thestepsmustbeorderedproperly– theprocessmustterminate atsomepoint

Page 2: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

2

Devising anAlgorithm

• Creating analgorithm isaprocess that involvesthese considerations:a) what istheresult?(specifications forthetask,

process, answer,orproduct)b) what doIknow?(information thatisgivenor

input intothecomputational process)c) howdoIderive(a)from(b)?(modifications,

transformations, stepsrequired toproduce(a))

ComputerSystems (1)

• electronic• digital• programmable• automated

Today’s generationofcomputersystemsareautomated, programmable, electronicdigitalprocessingmachines.

ComputerSystems (2)

• data—symbolic representation ofinformation• process—asequence ofstatesduringwhichthedataaremodified inprescribed ways

• program—a setofinstructionsthatdirect theprocess

Acomputersystemisanelectronicdigital dataprocessingmachine.

ComputerSystems (3)

• software—programs– program—a setofinstructionsthatdirectaprocess

• hardware—devices thatmakeupthephysicalsystemofthecomputer

Acomputersystemiscomprisedbysoftware thatdirects theprocessingperformed byhardware.

Page 3: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

3

Hardware

• Hardware denotes the devices that comprisethe computer system

Hardware

• processor– CPU– mainmemory

• secondary memory and I/Osubsystem– auxiliary memory– input/outputdevices

ProcessorSystem

main memorystoresbothdataandinstructionsusedforprocessing

centralprocessingunit:manages theinstruction-executioncycle

bus providesinterconnections

Instruction-ExecutionCycle

• fetching thenextinstruction

• decoding (orinterpreting) thatinstruction

• executingwhat theinstructionprescribes

Page 4: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

4

13

Memory

• information (data) isstored inuniform-sizedunits

• each unit hasaunique address that identifies it• reading frommemory– copy data fromamemory location– non-destructive

• writing tomemory– moving and replacing data inamemory location– destructive

14

Secondary Memoryand I/O

• Secondary memory– nonvolatile storage– cheaper, mass storage

• Input/Output devices– input--translateshuman-readable formsofinformation tomachine-readable data

– output-- translates machine-readable data tohuman-readable forms

DiscreteStateMachine

Digitalcomputers...maybeclassifiedamongstthe'discretestatemachines.’Thesearethemachineswhichmovebysuddenjumpsorclicks fromonequitedefinitestatetoanother.Thesestatesaresufficientlydifferentforthepossibilityofconfusion betweenthemtobeignored.

Turing, “ComputingMachineryandIntelligence”(1951)

CapturingaDiscreteState

• thecurrentvaluesofanydata objectsspecified fortheprocess

• thestatus oftheprocessor– temporary valuesandflags storedthere

• thestatusofinputandoutputoperations• theaddressofthenextexecutableinstruction intheprogram

Page 5: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

5

Software

• computer programsarecommonlycalledsoftware

• eachmachine instruction inaprogramtypicallycorresponds toatypeofoperation thatthecomputer’s processor canperform

• thesetofpossibleprocessor ormachineinstructions iscalledtheprocessor ormachinelanguage

AssemblyLanguage Programming

• assemblylanguageprogramscontainsymbolicinstructionsrepresentingelementsofsomemachinelanguageinstruction

• eachinstructiontypicallyhas– amnemonicfortheoperationcode

– literalsorlabelsfortheoperands

AssemblyLanguage Programming

• Someoperandsare literals– e.g.,

ADD3[ACCß ACC+3]whereACCdenotestheAccumulator

• Someoperandsare labels signifying indirection(indirectcodes)– e.g.,

ADDLOC1024[ACCß ACC+value(LOC1024)]

AssemblyLanguage Programming

• constants. literalsorvalues thatmaychangefromtime totime, butare fixedorstaticforthecurrentexecutionoftheprogram

• variables. thesedenote values thatare dynamic,that is,maychange inthecourseofprocessing

• pointers (handles). thesedenotevalues thataretheaddressofother locationscontainingvalues

Labelsmayfunctionas…

Page 6: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

6

Assignments

• Putting adata valueinto memory iscalled(algorithmica lly) anassignment

• InPython (and most programming languages),it iswritten inthis form

ACCß 3

name =valuewhere name isasymboliclabel andvalue expressessomedatavalue

ConditionalProcessing

22

isthecapability oftheprocessortochoosebetweenalternative actionsbasedonevaluating currentdata

ConditionalProcessing

• unconditional branch (jump)—change theaddressofthenext instructiontotheoneindicated inthebranchinstruction

• conditional branch (jump)—if someconditionistrue, thenchange theaddressofthenextinstructiontotheone indicated inthebranchinstruction

…ismadepossible atthe processorlevelbybranchinstructions

ConditionalProcessing

…ismadepossibleattheprocessor levelbybranchinstructions

Page 7: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

7

Subroutines

library program unitsthatcanbelinkedwiththemain program

AssemblyLanguage Programming

AssemblyProcess Review: Assembly Language Programming

• instructions havealow-level ofabstractionbecausetheymodeltheactualoperationsofthenativeprocessor

• instructions represent(nearly)a1–1relationwiththoseofthecorresponding machinelanguage

• assemblylanguageprogramsarenot portable• assemblylanguagesareconsidered low-levelprogramminglanguages

Page 8: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

8

High-Level Programming Languages

• High-LevelLanguage(HLL)instructions aremoreabstract– HLL instructionsexpresshigher-orderoperations

• singleHLLinstructions substituteforasequenceoflow-levelmachinelanguageinstructions. Inshort, thereisa1–manyrelation betweenHLLinstructions andmachinelanguageinstructions

• HLLprogramsareportable tootherprocessors– providedasuitablemeans oftranslation

Advantages ofHigh-LevelProgramming Languages

• programmerisrelievedofmanyimplementation details inperformingtasks

• HLLsaredesignedtobemorecompatiblewith thewaywethink andsolveproblems

• HLLprogramscanbeadaptedmoreeasilyforavarietyofcomputersystemsandmodifiedmoreeasily fordifferentfunctions

• HLLprogramsaremoreconcise

Translating HLLPrograms

• interpreters—decodeandexecuteprogramsoneinstruction atatime– translationonthe fly– emulates theway theprocessorfunctions

• compilers—analyzeandtranslate theentire HLLsourceprogramtoproduce anexecutablemachinelanguageversion– likeaprepared text translation

ComputationalProblems: TheLandscape

• Somecomputational problemshavesolutions,butthesesolutionscannotbecomputedeffectivelybecausewe lackthepracticalmeans todoso– someproblemsmaybesolvablewhenwehavefasterprocessorsorgreatermemorycapacities

– forothers,wewillneverhavetheresourcestoeffectivelycompute themwithcurrentsolutionsoralgorithms

• Example: thetraveling salespersonproblem

Page 9: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

9

ComputationalProblems: TheLandscape

• Thebrute-forcesolutionforthe traveling salespersonproblem(TSP)hasafactorialgrowth rate

• Computer scientistsoftendescribe thebehaviorofalgorithmsusinganotationcalled“BigO”– thisdenotestheupperboundfor theworst-caseperformance ofanalgorithm

– TSP=O(N!),forN cities(ornodes)

ComputationalProblems: TheLandscape

• Supposethatwehadhardware thatwascapableofanalyzingonemillion individualpathsortripspersecond.– N =10 solution<4seconds– N =100 solution=approximately1049 centuries

• Problemswithalgorithms like forTSParesaidtobeintractable

ComputationalProblems: TheLandscape

• there isanotherclassofproblems thatare notsolvable

• example:The HaltingProblem– Supposethatwecreatedaprogram thatcouldanalyzeanyotherprogram.

– Specifically,analyzeaninputprogramwithaspecificsetofinputdata

– Ourprogrammustbeabletodeterminewhethertheinputprogramwillhalt—i.e.,completeitstask

– Aneffectivesolutionhastwopossibilities:“Yes”,theinputprogram terminates or“No”, theinputprogram neverterminatesorhalts

ComputationalProblems: TheLandscape

• AlanTuringdemonstratedthattheHaltingProblemwasunsolvablein1936

• headedthegroupatBletchleyParkthatcrackedtheEnigmaMachine inWWII

• developedtheACE computerin1946

• introducedwhatisnowcalledthe“TuringTest”todeterminewhetheramachinecouldbeconsidered intelligent

Page 10: Algorithms, Computer Systems, and Programming Languagescs.furman.edu/~tallen/csc121/materials/Alg.hardware18.pdf · 1/10/18 1 Algorithms, Computer Systems, and Programming Languages

1/10/18

10

Computational Problems: TheLandscape

• undecidable problems: problems forwhichthere canbenoeffectivealgorithm

• intractable problems: theseare decidablebuthavenopracticalalgorithmic solutions

• tractable problems: thesearebothdecidable andhavealgorithms thatare orwouldbepractical toimplement

review

• whatisacomputational process?• whatisanalgorithm?• whatisacomputer?• briefoverviewofcomputer organization• computer processingasadiscrete statemachine• assemblylanguageprogramming• high-level languageprogramming• thelandscapeofcomputational problems