21
D75P 34 – HNC Computer Architecture Lecture 14 Clock Cycles and Program Analysis. © C Nyssen/Aberdeen College 2003 All images © C Nyssen/Aberdeen College except where stated Time, radio tower, computer all © Keyclip, with non-distribution licence Prepared 14/01/04

D75P 34 – HNC Computer Architecture Lecture 14 Clock Cycles and Program Analysis. © C Nyssen/Aberdeen College 2003 All images © C Nyssen/Aberdeen College

Embed Size (px)

Citation preview

D75P 34 – HNC Computer Architecture

Lecture 14

Clock Cycles and Program Analysis.

© C Nyssen/Aberdeen College 2003All images © C Nyssen/Aberdeen College except where statedTime, radio tower, computer all © Keyclip, with non-distribution licencePrepared 14/01/04

Let’s begin by reviewing the CPU from Outcome 2. We saw that the CU contained a system clock, made from a silicon crystal vibrating at very high speeds.

The Control Unit uses the “ticks” of this clock to time the signals sent along the Control Bus.

The faster the clock ticks, the more signals are sent, enabling the processing to be completed more quickly.

Frequency is measured in Hertz, named after the German physicist Heinrich Hertz, who made the sensational discovery of radio waves in 1888.

1 Hz = 1 wavelength, pulse or vibration per second.

In the UK, mains electric power runs at 50 Hz AC – the polarity of the current reverses 50 times per second.

An early 486 computer had a processor running at 4 MHz – the system clock “ticked” 4,000,000 times per second.

Now is a good time to revise BIG numbers …..

1 KiloHertz (kHz) = 1,000 Hz1 MegaHertz (mHz) = 1,000,000 Hz1 GigaHertz (gHz) = 1,000,000,000 Hz 1 TeraHertz (tHz) = 1,000,000,000,000 Hz1 PetaHertz (pHz) = 1,000,000,000,000,000 Hz

Note that when measuring Hertz, the definitions rise in value by 1000x each time. This is NOT the same as measuring bytes, where the definitions rise in value by 1024x each time!

For assessment purposes you should concentrate on the values of the Mega- (million) and Giga- (billion) hertz.

We have already seen that the CU sends control signals based on the frequency of the internal clock. We can use the quoted speed, or frequency, of the processor, to work out how long the space is between each clock “tick”.

For a 1 mHz processor, each clock “tick”, or cycle, will take

1

1,000,000 second

An alternative (better) method of writing this is

1

106 second, or

1 x 10-6 seconds.

A 1 gHz processor takesfor each clock cycle

This can also be expressed as

1

1,000,000,000 second

1

109 second , or 1 x 10 –9 second.

This period of time is referred to a t-cycle. This in turn gives us a unit of measurement, when determining how long a program will take to run.

Some processor instructions are more difficult to execute than others, so it may take several t-cycles to fetch and execute the command.

For assessment purposes, you will be given a chart showing how many t-cycles each assembly instruction will take to execute.

Every time a t-cycle is generated, the Control Unit sends signals along the Control Bus to change the bit patterns in the registers and RAM.

To do a mov takes 10 t-cycles, the int takes 52 but the cmp, being a very simple task, only uses 4.

                                                      

The first thing to establish is how many t-cycles each instruction uses. You can write it next to the source code like this -

Every computer program consists of three distinct parts :-

We now have to split our program into the three sections, so that we know which lines may be repeated.

The first clue as to where the loop may lie is given in the two highlighted lines -

The je is a conditional jump, so the program flow will either branch or keep going.Although jne is normally conditional, in this case it acts as though it were an unconditional jump.

Everything in the red box will happen in the context of one complete loop.

This also shows us what happens once only before and after the loop.

We can now begin to calculate the total number of t-cycles required using the following formula –

Total t-cycles =

t-cycles at start +

t-cycles at end +

t-cycles in each complete loop x number of loops

t-cycles in last loop (which may be only a partial loop)

Note that je and jne have two values, because they are condition statements.

It is a lot harder for the processor to work out what to do, if the program has to jump, so the higher number would be used.

If, however, the condition is not met and the program flow is not going to branch off, the lower value is used.

So the number of t-cycles required for each complete loop will be

4 + 52 + 4 + 4 (not jumping) + 4 + 16 (jump back to start) = 84.

On the last iteration of the loop, where the stopping condition is met, the number of t-cycles will be

4 + 52 + 4 + 16 (jump to exit) = 76.

We can now begin to fill in the formula -

Total t-cycles =

t-cycles at start + 72

t-cycles at end + 62

t-cycles in each complete loop x number of loops

84 x ?

t-cycles in last loop (which may be only a partial loop)

76

The only figure now missing is for how many complete loops are run. To establish this, we have to look at the data provided.

We are told that the user inputs the following values each time the prompt is displayed –

6, o, %, f and s

One of the stopping conditions was defined in the lines

So the condition is met on the fifth pass of the loop.

Remember that on the fifth pass, the loop is only the partial one, as the stopping condition is triggered halfway down.

We therefore have four complete loops to count -

Total t-cycles = 546

t-cycles at start + 72

t-cycles at end + 62

t-cycles in each complete loop x number of loops

84 x 4

t-cycles in last loop (which may be only a partial loop)

76

We are now asked to apply this value to a given speed of processor. For this, we need to work out the length of the t-cycle as shown at the start of the lecture –

1.2 GHz t-cycle = 1

1.2 X 10 –9 seconds

So 546 of them will take 546

1.2 X 10 –9 seconds

or 455 x 10 –9 seconds.

Now use what you have learned to work out the time taken to process the second set of inputs –

A, b, h. 9, x, S

Watch this one, because the last loop, where the stopping condition is met, will be different from what happened with the first set of data!

Summary [1]

The time taken to execute an assembly code program is measured in t-cycles. Each t-cycle represents the space between clock “ticks”.

The actual length of the t-cycle depends on the speed of the processor.

To analyse the source code -

•establish how many t-cycles each instruction takes.•establish what happens at the beginning, in the middle and at the end of the program.•work out how many whole loops will be completed, and whether the last loop is a partial one.

Summary [2]

Apply the total number of t-cycles to the processor speed, to work out in real time, how long the source code will take to run.

Always display your results in scientific notation, e.g.455 x 10 –9 seconds.

You will be required to depict this on a graph later!

For your assessment, you will be required to analyse two separate programs using different instruction sets. Although the languages are different, the principles remain the same!