Low-Level Programming Languages and Pseudocode
Low-Level Programming Languages and Pseudocode
Low-Level
Programming
Languages and
Pseudocode
Chapter Goals
2
Chapter Goals
• Describe the steps in creating and running an
assembly-language program
• Write a simple program in assembly language
• Distinguish between instructions to the
assembler and instructions to be translated
• Distinguish between following an algorithm and
developing one
• Describe the pseudocode constructs used in
expressing an algorithm
3
Chapter Goals
4
Computer Operations
Computer
A programmable electronic device that can
store, retrieve, and process data
Data and instructions to manipulate the
data are logically the same and can be
stored in the same place
5
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 computer
6
Machine Language
7
Pep/8 Virtual Computer
Virtual computer
A hypothetical machine designed to contain
the important features of a real computer
that we want to illustrate
Pep/8
A virtual computer designed by Stanley
Warford that has 39 machine-language
instructions
No; we are not going to cover all of them!
8
Features in Pep/8
10
Instruction Format
11
Instruction Format
Operation code
Specifies which instruction is to be carried out
Register specifier
Specifies which register is to be used (for our
purposes it always specifies the accumulator)
Addressing-mode specifier
Says how to interpret the operand part of the
instruction
12
Instruction Format
13
Addressing Modes
14
Some Sample Instructions
15
Sample Instructions
16
Sample Instructions
17
Sample Instructions
18
Sample Instructions
19
Sample Instructions
20
Assembly Language
Assembly language
A language that uses mnemonic codes to
represent machine-language instructions
Assembler
A program that reads each of the
instructions in mnemonic form and
translates it into the machine-language
equivalent
21
Assembly Process
22
Pseudocode
Pseudocode
A mixture of English and formatting to make the
steps in an algorithm explicit
23
Following an Algorithm
24
Following an Algorithm
25
Developing an Algorithm
Pseudocode
A way of expressing algorithms that uses a
mixture of English phrases and indentation
to make the steps in the solution explicit
There are no grammar rules in pseudocode,
but it’s important to be consistent and
unambigous
27
Following Pseudocode
While (the quotient is not zero)
Divide the decimal number by the new base
Make the remainder the next digit to the left in the answer
Replace the original decimal number with quotient
What is 93 in base 8?
93/8 gives 11 remainder 5
11/6 gives 1 remainder 3
1/ 8 gives 0 remainder 1
answer 135
28
Following Pseudocode
30
Pseudocode Functionality
Variables
Names of places to store values
quotient, decimalNumber, newBase
Assignment
Storing the value of an expression into a
variable
Set quotient to 64
quotient <-- 64
quotient <-- 6 * 10 + 4
31
Pseudocode Functionality
Output
Printing a value on an output device
Write, Print
Input
Getting values from the outside word and
storing them into variables
Get, Read
32
Pseudocode Functionality
Selection
Making a choice to execute or skip a statement (or group of
statements)
Read number
IF (number < 0)
Write number + " is less than zero."
or
Write "Enter a positive number."
Read number
IF(number < 0)
Write number + " is less than zero."
Write "You didn't follow instructions."
33
Pseudocode Functionality
Selection
Choose 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"
ELSE
Write "Pay senior citizens rate"
34
Pseudocode Functionality
Repetition
Repeating a series of statements
Set count to 1
WHILE ( count < 10)
Write "Enter an integer number"
Read aNumber
Write "You entered " + aNumber
Set count to count + 1
To What?
Assembly language
Very detailed and time consuming
High-level language
Easy, as you'll see in Chapter 9
36
Testing
Test plan
A document that specifies how many times and with what
data the program must be run in order to thoroughly test it
Code coverage
An approach that designs test cases by looking at
the code
Data coverage
An approach that designs test cases by looking at the
allowable data values
37
Testing
38
Important Threads
Operations of a Computer
Computer can store, retrieve, and process data
Machine-language Programs
Written by entering a series of these instructions in binary
form
39
Important Threads
Pseudocode
Shorthand-type language people use to express algorithms
40
Important Threads
Testing Programs
All programs must be tested; code coverage testing and
data coverage (black-box testing) are two common
approaches
41