Chapter 7

Low-Level Programming Languages

(slides modified by Erin Chambers)

Computer Operations

Computer

A programmable electronic device that can store, retrieve, and process data

Data and instructions to manipulate the data are all binary numbers and can be stored in the same place

Recall: this is called the von Neumann architecture

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

Why would anyone choose to use machine language?

(Hint: they had no choice. Why?)

Machine Language

Characteristics of 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

Pep/7: A Virtual Computer

Virtual computer

A hypothetical machine designed to contain the important features of a real computer that we want to illustrate

Pep/7

A virtual computer designed by Stanley Warford that has 32 machine-language instructions

No; we are not going to cover all of them!

Features in Pep/7

Figure 7.1 Pep/7’s architecture

Features in Pep/7

Pep/7 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)

More Features

Pep/7 Registers/Status Bits Covered

The accumulator (A register)

Status bit N (1 if A register is negative; 0 otherwise)

Status bit Z (1 if the A register is 0; and 0 otherwise)

The memory unit is made up of 4,096 bytes

Instruction Format

Figure 7.2 The Pep/7 instruction format

Instruction Format

Operation code

Specifies which instruction is to be carried out

Register specifier

Specifies which register is to be used (only use A in this chapter)

Addressing-mode specifier

Says how to interpret the operand part of the instruction

The Addressing Mode Specifier

Figure 7.3 Difference between immediate-mode and direct-mode addressing

Instruction Format

Is there something we are not telling you

about the addressing mode specifier?

How can you tell?

Some Sample Instructions

Figure 7.3 Subset of Pep/7 instructions

Sample Instructions

What do these instructions mean?

Sample Instructions

What do these instructions mean?

Sample Instructions

What do these instructions mean?

Sample Instructions

What do these instructions mean?

Algorithms

Write "Hello"

Write "Hell"

Write "H"

Write "e"

Write "l"

Write "l"

Write "o"

Are we concrete yet?

Are we concrete yet?

Algorithms

Is this concrete enough?

How can we explicitly tell the computer to print, and what to print?

Write "Hell"

Write "H"

Write "e"

Write "l"

Write "l"

Write "o"

How to print:

We use opcodes to tell the computer that it needs to print

Now how do we tell it what to print?

What to print: remember ASCII?

To print 'H', we need to look up ACSII code for H (and other letters)

Then, write that code in binary as our operand

A Program Example

Hand Simulation

What is the fetch/execute cycle?

How much is the PC incremented?

Fetch/Execute Cycle

Fetch the next instruction

How long is instruction here?

Decode the instruction

Look up in table

Get data if needed

If code is '01', then need to get value from memory location

Execute the instruction

Hand Simulation

What is the fetch/execute cycle here?

Hand Simulation

What is the fetch/execute cycle here?

Pep/7 Simulator

Pep7/Simulator

A program that behaves just like the Pep/7 virtual machine behaves

To run a program

Enter the hexadecimal code, byte by byte with blanks between each

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

Pep/7 Assembly Language

Remember

the

difference

between

immediate

and

direct

addressing?

i : immediate

d: direct

Pep/7 Assembly Language

What is the difference between

operations and pseudo operations?

Assembly Process

A New Program

Reading and adding three numbers

Set sum to 0

Read num1

Add num1 to sum

Read num2

Add num2 to sum

Read num3

Addnum3 to sum

Write sum

Are we

concrete

yet?

Our Completed Program

Decision Making

Remember the status bits A and Z?

Decision Making

…

Add num3 to sum

If sum is negative

Write "Error"

Else

Write sum

Write "Error" if sum is negative.

Are we

concrete yet?

Decision Making

Add num3 to sum

If status bit N is 1

Go to NegMsg

Write sum

Quit: STOP

NegMsg: Write the message and go to Quit

Are we concrete yet?

Decision Making

Read limit

Set sum to 0

While (limit is not zero)

Read number

Set sum to sum + number

Set limit to limit - 1

Are we concrete yet?

Decision Making

Set the accumulator to limit

Subtract one from the accumulator

Compare accumulator to zero

If status bit Z is 1

go to Quit

Else

go to Read

Are we concrete yet?

Decision Making

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

PowerPoint Presentation

Jones & Bartlett Publishers

2002-06-09T11:27:05