Chapter 3 - Two Conceptual Computer

3.1 Introduction

hardware, software, data
A program is a collection of commands or instructions for the computer to perform.

Machine language is the form that all instructions must be in before the computer can do them. This form consists of binary numbers or binary code.

A stored-program computer is a computing device with a memory which contains both a program (the instructions of what to do) and the data needed for computing by the program. (von-Neumann computer)

3.2 The Robot Computer and Machine Language

The ROBOT's Domain (Fig. 3.1)
Programming the ROBOT (Fig. 3.2.1)
ROBOT Characteristics: (Fig. 3.2.2)
The ROBOT has a memory where the instructions are stored
The ROBOT can fetch instructions from its memory, decode their meaning, and execute them.
ROBOT's MEMORY - 32 memory locations numbered 0-31 each capable of storing one ROBOT instruction

INSTRUCTION - 8 bits (3 bit opcode and 5 bit operand) [Fig. 3.3]

FETCH - ROBOT can retrieve one instruction at a time from the memory.

DECODE - splits instruction into opcode and operand and sends signals to appropriate part of ROBOT according to the opcode [Fig. 3.3.1]
EXECUTE - ROBOT executes the instructions based on the opcode

ROBOT's program stored in ROBOT's memory [Fig. 3.4]

low-level language: 1) non-symbolic; 2) pedestrian (micro-instructions)
Using the ROBOT
problem -> solution (algorithm) -> program

An algorithm is a step by step process used to solve a problem. It is essentially the solution to the problem and is usually implemented by a program
PROBLEM #1: Cause the ROBOT to take a step.

00000000 STEP
11100000 STOP

An algorithm should be general.
PROBLEM #2: Cause the ROBOT to walk to the nearest wall and stop with its arms lowered.

Solution 1: 	00000000	STEP				Difficulty: Infinite Loop
		10100000	GOTO Location 0			(never reaches STOP)
		11100000	STOP
Solution 2: [Fig. 3.4.4] Difficulty: Never lowers arms and stops one short of wall
Solution 3: [Fig. 3.4.6]

PROBLEM #3: Have the ROBOT locate any corner of the room and stop there with its arms lowered.

Solution:
		01000000	RAISE
		01100000	LOWER
		00000000	STEP
		10100000	Goto 0

		11000000	LIGHT
		00100000	TURN

		01000000	RAISE
		01100000	LOWER
		00000000	STEP
		10100110	Goto 6

		11000000	LIGHT
		11100000	STOP

PROBLEM #4: Have the ROBOT walk around the perimeter of the room [Fig. 3.4.7]

PROBLEM #5: Have the ROBOT find a doorway. [Fig. 3.4.8, 3.4.9]

PROBLEM #1: Have the ROBOT take a step.

Solution:
		01000000	RAISE
		01100000	LOWER
		00000000	STEP
		11100000	STOP

		11000000	LIGHT
		00100000	TURN
		00100000	TURN
		00000000	STEP
		11100000	STOP

3.3 The Pencil and Paper Computer: Just Like the Real Thing!
Fundamental components of a computer - [Fig. 3.5]
I/O Units
Memory
CPU: [Fig. 3.8]
ALU - arithmetic-logic unit
Control Unit
Instruction Decoding Unit [Fig. 3.8.1]

The Pencil & Paper Computer Instruction Set [Fig. 3.9]

PROBLEM #1: Print the sum of two numbers

Solution: Assembler - [Fig. 3.15.2]
Machine Code [Fig. 3.15.3]

Loading and Executing a Pencil & Paper Program
loader - places the program into memory and inserts the address of its first instruction into the PC; starts the Fetch-Execute cycle [Fig. 3.13]

PROBLEM #2: Write a program that will count backwards from 10 to 1 on the monitor.

1) Analyze the problem: [Fig. 3.15.1]

2) Define the memory space
use labels in assembler

3) Plan the Solution

4) Write the program [Fig. 3.16]
Labels
Instructions
Addresses
Comments



0 		1 		2 11001111		3 01101111
4 01001110	5 10001111	6 11100010		7 00000000
8
12
16
20
24
28		29		30 00000001		31 00001010
----------------------- 00000010 | ----------------------- Program Counter


HOMEWORK:
due March 14, 1997: (pp89-90). - # 2, 6, 9, 10, 13, 14
due March 26, 1997: (pp90-91) - #18, 22, 23,25
BACK TO Computer Science I Page