Transcript Document
Chapter 7
Low-Level Programming
Languages
Nell Dale • John Lewis
Chapter Goals
• List the operations that a computer can perform
• Discuss the relationship between levels of abstraction
and the determination of concrete algorithm steps
• Describe the important features of the Pep/7 virtual
machine
• Distinguish between immediate mode addressing and
direct addressing
• Convert a simple algorithm into a machine-language
program
7-2
Chapter Goals (cont.)
• Distinguish between machine language and assembly
language
• Describe the steps in creating and running an assemblylanguage program
• Convert a simple algorithm into an assembly-language
program
• Distinguish between instructions to the assembler and
instructions to be translated
• Describe two approaches to testing
• Design and implement a test plan for a simple assemblylanguage program
7-3
Computer Operations
• A computer is 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
• Store, retrieve, and process are actions
that the computer can perform on data
7-4
Machine Language
• Machine language: the instructions built
into the hardware of a particular computer
• Initially, humans had no choice but to write
programs in machine language because
other programming languages had not yet
been invented
7-5
Machine Language
• Every processor type has its own set
of specific machine instructions
• The relationship between the processor
and the instructions it can carry out is
completely integrated
• Each machine-language instruction does
only one very low-level task
7-6
Pep/7: A Virtual Computer
• A virtual computer is a hypothetical
machine designed to contain the important
features of real computers that we want
to illustrated
• Pep/7
– designed by Stanley Warford
– has 32 machine-language instructions
• We are only going to examine a few
of these instructions
7-7
Features in Pep/7
• The memory unit is made up of 4,096 bytes
of storage (4096x8bits)
• Word length is 2 bytes (or 16 bits)
• Seven registers, four of which we focus on at
this point
– 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 index register (X register)
– The accumulator (A register)
7-8
Features in Pep/7
Figure 7.1 Pep/7’s architecture
7-9
Memory of Pep/7
7-10
Assembly Language
• Assembly languages: assign mnemonic
letter codes to each machine-language
instruction
– The programmer uses these letter codes in
place of binary digits
– A program called an assembler reads each
of the instructions in mnemonic form and
translates it into the machine-language
equivalent
7-11
Figure 7.5 Assembly Process
7-12
Pep/7 Assembly Language
Page 208
7-13
Pseudo Operations
Useful assembler directives
ie. Instructions to assembler
Page 209
7-14
Program
• Write “Hello”
7-15
Program (immediate addressing)
7-16
Program (direct addressing)
7-17
Program (direct addressing)
7-18
Program (direct addressing +
write the initial)
7-19
Features in Pep/7
Figure 7.1 Pep/7’s architecture
7-20
Instruction Format
• There are two parts to an instruction
– The 8-bit instruction specifier
– And optionally, the 16-bit operand specifier
Figure 7.2 The Pep/7 instruction format
7-21
Instruction Format
• The instruction specifier is made up of
several sections
– The operation code
– The register specifier
– The addressing-mode specifier
7-22
Instruction Format
• The operation code specifies which
instruction is to be carried out
7-23
Instruction Format
• The 1-bit register specifier is 0 if register A
(the accumulator) is involved in the
operation and 1 if register X (the index
register) is involved
7-24
Instruction Format
• The 2-bit addressing-mode specifier says
how to interpret the operand part of the
instruction
7-25
Instruction Format
Figure 7.3 Difference between immediate-mode and direct-mode addressing
7-26
Machine Code (1/6)
LOADA 0007, i
LOADX 001F, i
7-27
Machine Code (2/6)
LOADA (001F), d
LOADX (001F),d
7-28
Machine Code (3/6)
STOREA (000A), d
ADDA 20A, i
7-29
Machine Code (4/6)
ADDX 20A, i
ADDA (20A), d
7-30
Machine Code (5/6)
ADDX (20A), d
CharI (000A)
7-31
Machine Code (6/6)
CharO 41,i
‘A’
CharO (000A), d
7-32
A Program Example
• Let’s write "Hello" on the screen
Page 200
7-33
Hello (1/3)
• PC=0 CharO, 48, i
Page 201
7-34
Hello (2/3)
• PC=3 CharO, 65, i
1 1
Page 201
7-35
Hello (3/3)
• PC=0F STOP
Page 201
7-36
Code
7-37
Pep/7 Simulator
• A program that behaves just like the Pep/7
virtual machine behaves
• To run a program, we enter the hexadecimal
code, byte by byte with blanks between each
Page 202
7-38
Another Program
• Using direct addressing method
– 11100000 => 11100001
• Insert data after the program code
• Correction (p. 204)
– Line #6 :
• 10 (16 decimal)
– Line #7 :
• 11 (17 decimal)
7-39
Enhanced Version
• Refer the table on the textbook (page 205)
7-40
A New Program
Page 213
7-41
Pseudocode
Page 213
7-42
Completed Program
Page 214
Our Completed Program
Page 215
Testing
• Test plan: a document that specifies how many
times and with what data the program must be
run in order to thoroughly test the program
• A code-coverage approach designs test cases
to ensure that each statement in the program
is executed
• Data-coverage testing is another approach;
it designs test cases to ensure that the limits
of the allowable data are covered
7-45
Ethical Issues:
Software Piracy, Copyrighting
• Research indicated that, globally, 11.5
billion dollars were lost in the year 2000 to
pirated software
• Advocates of open-source code believe
that a program’s original source code
should be in the public domain
• Respecting the copyrights of software, if it
is not open code, is important from a
number of perspectives
7-46