Presentation on theme: "Low-Level Programming Languages and Pseudocode"— Presentation transcript:
1 Low-Level Programming Languages and Pseudocode Chapter 6Low-Level Programming Languages and Pseudocode
2 Computer Operations Computer A programmable electronic device that can store, retrieve, and process dataData and instructions to manipulate the data are logically the same and can be stored in the same placeWhat operations can a computer execute?
3 Machine Language Machine language The language made up of binary coded instructions built into the hardware of a particular computer and used directly by the computerWhy would anyone choose to use machine language?(Hint: they had no choice. Why?)Why would anyone choose to use machine language?(Hint: they had no choice. Why?)
4 Machine Language Characteristics of machine language: Every processor type has its own set of specific machine instructionsThe relationship between the processor and the instructions it can carry out is completely integratedEach machine-language instruction does only one very low-level task
5 Pep/8 Virtual Computer Virtual computer A hypothetical machine designed to contain the important features of a real computer that we want to illustratePep/8A virtual computer designed by Stanley Warford that has 39 machine-language instructionsNo; we are not going to cover all of them!
6 Features in Pep/8 Pep/8 Registers/Status Bits Covered The program counter (PC) (contains the address of the next instruction to be executed)The instruction register (IR) (contains a copy of the instruction being executed)The accumulator (A register)The memory unit is made up of 65,636 bytes of storage! 64kb!
7 Architecture of Pep/8Figure 6.1 Pep/8’s Architecture
8 Instruction FormatFigure 6.2 Pep/8 Instruction Format
9 Instruction Format Operation code Specifies which instruction is to be carried outRegister specifierSpecifies which register is to be used (only use A in this chapter)Addressing-mode specifierSays how to interpret the operand part of the instruction
10 Instruction FormatFigure 6.3 Difference between immediate addressing mode and direct addressing mode
11 Instruction Format Is there something we are not telling you about the addressing mode specifier?How can you tell?
12 Some Sample Instructions Figure 6.4 Subset of Pep/8 instructions
13 What do these instructions mean? Sample InstructionsWhat do these instructions mean?
14 What do these instructions mean? Sample InstructionsWhat do these instructions mean?
15 What do these instructions mean? Sample InstructionsWhat do these instructions mean?
16 Sample Instructions What do these instructions mean? Why is there only one on this page?1616
17 What do these instructions mean? Sample InstructionsWhat do these instructions mean?1717
27 Assembly Language Assembler Assembly language A language that uses mnemonic codes to represent machine-language instructionsAssemblerA program that reads each of the instructions in mnemonic form and translates it into the machine-language equivalent
28 Pep/8 Assembly Language Rememberthedifferencebetweenimmediateanddirectaddressing?i : immediated: direct
29 Pep/8 Assembly Language What is the difference betweenoperations and pseudo operations?
30 Pep/8 Assembly Language Program "Hello"CHARO 0x0048,i; Output an 'H'CHARO 0x0065,i;Output an 'e'CHARO 0x006C,i; Output an 'l'CHARO 0x006F,i;Output an 'o'STOP.END3030
35 Decision Making BRLT i Set PC to operand if A < 0 BREQ I Set PC to operand if A = 0negMsg: CHARO 0x0045,iBR finishmain: LDA sum,d…BRLT negMsgSTA sum,dDECO sum,dfinish: STOPHow many ways to finish?
36 Decision Making Problem: Read and sum limit values. How many values? Where does this value come from?Will require repeating the reading andsummingHow do we know when we are done?3636
37 Pseudocode Pseudocode A mixture of English and formatting to make the steps in an algorithm explicitAlgorithm to Convert base-10 number to other basesWhile (the quotient is not zero)Divide the decimal number by the new baseMake the remainder the next digit to the left in the answerReplace the original decimal number with the quotient
39 Following an Algorithm Algorithm for preparing a Hollandaise sauceIF concerned about cholesterolPut butter substitute in a potELSEPut butter in a potTurn on burnerPut pot on the burnerWHILE (NOT bubbling)Leave pot on the burnerPut other ingredients in the blenderTurn on blenderWHILE (more in pot)Pour contents into lender in slow steamTurn off blender
40 Developing an Algorithm Two methodologies used to develop computer solutions to a problemTop-down design focuses on the tasks to be doneObject-oriented design focuses on the data involved in the solutionBut first, let's look at a way to express algorithms: pseudocode
41 Pseudocode Pseudocode A way of expressing algorithms that uses a mixture of English phrases and indention to make the steps in the solution explicitThere are no grammar rules in pseudocodePseudocode is not case sensitive
42 Following Pseudocode What is 93 in base 8? 93/8 gives 11 remainder 5 While (the quotient is not zero)Divide the decimal number by the new baseMake the remainder the next digit to the left in the answerReplace the original decimal number withWhat is 93 in base 8?93/8 gives 11 remainder 511/6 gives 1 remainder 31/ 8 gives 0 remainder 1answer
43 Easier way to organize solution Following PseudocodeEasier way to organize solution
44 Pseudocode for Complete Computer Solution Write "Enter the new base"Read newBaseWrite "Enter the number to be converted"Read decimalNumberSet quotient to 1WHILE (quotient is not zero)Set quotient to decimalNumber DIV newBaseSet remainder to decimalNumber REM newBaseMake the remainder the next digit to the left in the answerSet decimalNumber to quotientWrite "The answer is "Write answer
45 Pseudocode Functionality VariablesNames of places to store valuesquotient, decimalNumber, newBaseAssignmentStoring the value of an expression into avariableSet quotient to 64quotient <-- 64quotient <-- 6 *
46 Pseudocode Functionality OutputPrinting a value on an output deviceWrite, PrintInputGetting values from the outside word and storing them into variablesGet, Read
47 Pseudocode Functionality RepetitionRepeating a series of statementsSet count to 1WHILE ( count < 10)Write "Enter an integer number"Read aNumberWrite "You entered " + aNumberSet count to count + 1How many values were read?
48 Pseudocode Functionality SelectionMaking a choice to execute or skip a statement (or group of statements)Read numberIF (number < 0)Write number + " is less than zero."orWrite "Enter a positive number."IF(number < 0)Write "You didn't follow instructions."
49 Pseudocode Functionality SelectionChoose to execute one statement (or group of statements) or another statement (or group of statements)IF ( age < 12 )Write "Pay children's rate"Write "You get a free box of popcorn"ELSE IF ( age < 65 )Write "Pay regular rate"ELSEWrite "Pay senior citizens rate"
50 Pseudocode ExampleProblem: Read in pairs of positive numbers and print each pair in order.WHILE (not done)Write "Enter two values separated by blanks"Read number1Read number2Print them in order
51 Pseudocode Example How do we know when to stop? Let the user tell us how manyPrint them in order?If first number is smallerprint first, then secondIf first number if largerprint second, then first5151
52 Pseudocode Example Write "How many pairs of values are to be entered?" Read numberOfPairsSet numberRead to 0WHILE (numberRead < numberOfPairs)Write "Enter two values separated by a blank; press return"Read number1Read number2IF(number1 < number2)Print number1 + " " + number2ELSEPrint number2 + " " number1Increment numberRead5252
53 Walk Through Data Fill in values during each iteration 3 numberRead number1 number255 702 133 33numberOfPairsWhat is the output?
54 Translating Pseudocode To What?Assembly languageVery detailed and time consumingHigh-level languageEasy as you'll see in Chapter 95454
55 TestingTest planA document that specifies how many times and with what data the program must be run in order to thoroughly test itCode coverageAn approach that designs test cases by looking atthe codeData coverageAn approach that designs test cases by looking at the allowable data values
56 Testing Test plan implementation Using the test cases outlined in the test plan to verify that the program outputs the predicted results
57 Important Threads Operations of a Computer Computer’s Machine Language Computer can store, retrieve, and process dataComputer’s Machine LanguageA set of instructions the machine’s hardware is built to recognize and executeMachine-language ProgramsWritten by entering a series of these instructions in binary form
58 Important ThreadsPep/8: A Virtual Computer with One Register (A) and two-part instructions:One part tells which action the instruction performs; the other part details where the data to be used can be foundPep/8 Assembly LanguageA language that permits the user to enter mnemonic codes for each instruction rather than binary numbersPseudocodeShorthand-type language people use to express algorithms
59 Important Threads Testing Programs All programs must be tested; code coverage testing and data coverage (black-box testing) are two common approaches
60 Ethical Issues Software Piracy and Copyrighting Have you every "borrowed" software from a friend?Have you ever "lent" software to a friend?Did you know that 107,000 jobs were lost in the US one year due to such "borrowing” and "lending?"