1Dimensional arrays

A 1 Dimensional array is a series of objects all of which are the same size and type. Each object in an array is called an array element. For example, you could have an array of integers or an array of characters or an array of anything that has a defined data type. The important characteristics of an array are:

  • Each element has the same data type (although they may have different values).
  • The entire array is stored contiguously in memory (that is, there are no gaps between elements).

Arrays can have more than one dimension. A one-dimensional array is called a vector ; a two-dimensional array is called a matrix.
Here is an example program that allows the user to enter up to 30 programs (allowing them to specify within that how many they want), then it allows them to pick a number to show the name that corrosponds to that number.

program arraysstudentno;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,crt
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };

{$R *.res}
var
students:array[1..30] of string;
nostudents:integer;
x:integer;
studentno:integer;
begin
writeln(‘How many students would you like to enter?’);
readln(nostudents);
for x:=1 to nostudents do
begin
writeln(‘Enter your students now, press enter between each name’);
readln(students[x]);
end;
writeln(‘Enter the name of the student you wish to see’);
readln(studentno);
writeln(students[studentno]);
readln;
end.

Microprocessors

1. What is meant by the term “instruction set”?

The instructions that can be recognized by a processor are referred to as an instruction set.

2. Do all processors have the same instruction set? What are the implications of this?

No. The reason for this is because not all processors can store the same amount of instructions. Therefore, there instruction sets will sometimes have to be different. However, this will result in some machines not being compatable with others.

3. Describe the structure of each machine code operation, including definitions of opcode and operand.

Machine code is structured in 0’s and 1’s.

Opcode is a short code which indicates what operation is expected to be performed. Each operation has a unique opcode.

Operands indicate where the data required for the operation can be found and how it can be accessed.

4. [see textbook p158] – What three opcodes are described? Give and explain an example of an instruction that uses each of these.

Add – Adds the contents of the memory address or integer to the accumulator.

Load – Loads the contents of the memory address or integer into the accumulator.

Store – Stores the contents of the accumulator into the addressed location.

5. [see textbook p160] – How can an opcode be sub-divided?

An op-code can be sub-divided into a part that denotes the basic operation.

6. [see textbook p160] – If a designer requires a processor to have 32 different operations, how many bits will be needed for the opcode part?

It will need 5 bits, since x^5 = 32.

7. Describe the three stages of the instruction execution cycle.  Illustrate your answer with a diagram.

Fetch Cycle: The fetch cycle takes the address required from memory, stores it in the instruction register, and moves the program counter on one so that it points to the next instruction.

Decode Cycle: Here, the control unit checks the instruction that is now stored within the instruction register. It determines which opcode and addressing mode have been used, and as such, what actions need to be carried out in order to execute the instruction in question.

Execute Cycle: The actual actions which occur during the execute cycle of an instruction depend on both the instruction itself, and the addressing mode specified to be used to access the data that may be required. However, four main groups of actions do exist, which are discussed in full alter on.

8. What is the role of the processor’s clock?

The clock determines how fast each action will take per second. The higher the clock speed, the quicker the actions will be performed.

This link also describes the cycle: http://www.eastaughs.fsnet.co.uk/cpu/execution-fetch.htm

While do loops

While do loops are used to specify the condition at the beginning of the code instead of after.
This is good in situations for implementing a counter.

For example, this program uses a counter to display ‘computing is the best’ 10 times which is made possible through the while do loop.

var
x:integer;
begin
x:=1;
while (x<10) do
begin
delay(1000);
writeln(‘Computing is the best’);
delay(1000);
x:=x+1;
end;

 

x is the integer.

x is equal to 1

while x is less than 10 do this

delay(a second)

writes – computing is the best

delay (a second)

x now equals x + 1 so that until x = 10 the computer while run this code.

end;

 

Classication of software questions

1a) software consists of sequences of instructions called programs that can be understood and executed by hardware.

1b)

Software Category

Example

Programming language translator Assembler, compiler
Utility Programs Disk defragmenter
Library Program A DLL file that is used by several applications programs
General purpose applications program Word processor

2)

Software

Description

Income Tax Calculation Software Special Purpose application software (G)
Translator software for C++ Interpreter or compiler Software (D)
Word Processing General Purpose application software (F)
Operating Software System Software (A)

3)

Fig. 1

a

Fig. 2

Move #45 R0 100 00101000 00101101
Move #4 R1 101 00101001 00000100
Move #96 R2 102 00101010 01100000
Add R2 R1 103 10100001 00000000
Add R1 R0 104 10100000 00000000

a) Second Generation Programming – Fig. 1

b) Fig.2 is First Generation

c) ?

d)  Each line of assembly language translates to one line of machine code

e)  The two codes are the same but Fig. 2 is in machine code whilst Fig.1 is in third generation.

4a)
i) Utility program
ii) Special-Purpose software is software that is designed to support one specific task.

b)
i) Bespoke Software is written for a customer’s specific need.
ii) An advantage of bespoke software is that sometimes it is the only way to acquire a specific software. Furthermore, they can be tailor-made and therefore specific for the customer. It usually costs A LOT more than software already made and for sale for the public. It won’t have been used and tested a lot and therefore unforseen bugs may appear.

Questions

Page 233.

1)
a)
1 – Clock
2 – Proccessor
3 – Read only memory
4 – RAM
5 – Data Bus
6 – Address Bus

b) The Address Bus

c) The Data Bus

2)
b) The data is transfered to the RAM before execution and then, each command is executed one at a time, from start to finish.

Questions on page 155.

10) The three internal componants of the proccessor, are the Program Control Unit, the Arithemtic-Control Unit, and the Clock.

11)
a) The register is the place where all the data for the Proccessor is stored in the Cache.
b) A general purpose register can be used for any purpose that a programmer defines.
c) Dedicated registers will be used internally, and the proccessor designer would decide what goes into this register.

12) Stack pointer, and Program counter are both Dedicated Registers, that would be managed independent of any external programming.

13)
a) The clock speed is the number of ticks per second, and essentially controls the speed of the whole system.
b) The Word length is the maximum number of bits that can be handled in a clock cycle. It normally corrisponds to the Bus width, which is the number of wires in the system’s data buses.
c) See above.

14) 16

15) 65, 535.

16) 504 365 056

I/O ports

The processor exchanges data with a peripheral device through a part of an I/O controller called an I/O port. An I/O port is simply a set of data, command and status registers. Registers are stored locations that can be written to and read from.

Buses

A computer bus is a let of parallel wires that connect independent components of a computer system in order to pass signals between them. Some signals represent data, some represent an adress and others control infomation. For this reason, the system bus is split into three buses…

  • Data bus: a bidirectional bus, typically consisting of 32 wires, used to transport data between the three components of the three box model.
  • Address bus: a unidirectional, typically consisting of 32 wires, used to adress memory and I/O locations
  • Control bus: a bidirectional bus, typically consisting of 8 wires, used to transport control signals between the three components of the three box model.

CPU

What is the purpose of the CPU and how does it achieve this?

1. Controls the computer

2. Fetches the instructions

3. Executes instructions
What three functions are used to perform a simple addition?

Load, add and store.
In the fetch-execute cycle, where are instructions and data fetched from? Where are they taken to?

From the RAM, they are taken to the CPU.
What is the clock speed? What effect does this have?

How many calculations the CPU can perform each second.
What is the cache? What is it used for?

It is memory exclusively used by the processor. Faster than RAM yet smaller.
What does it mean to have a dual or quad core processor? What is the effect of this?

More cores means that there are more virtual processors to serve requests. It is like having 4 workers instead of 2, more will be done by the quad core than the dual core.