Some more exercise for weeks 1 & 2
Hopefully the lectures helped you to understand how numbers are represented in a computer.
Here are a few questions you might want to work through. They are not, meant to be a practice quiz
– they are to help you check your understanding.
1. The 32 bit (4 byte) value 1011021031048 is used to represent the 4 ASCII characters ‘ABCD’
a. What would be the result if you added that value to 0010020030048?
The key point here is that the data is just a pattern of bits. If we interpret it as numbers
we can do arithmetic – or we can treat it as characters.
In ASCII each byte is interpreted:
Decimal Octal Character
65 101 A
66 102 B
67 103 C
……
101102103104
+
001002003004
102104106110
b. What would be the interpretation of that result as ASCII characters?
BDFH
2. If a floating point number is represented in 8 bits. The leftmost bit represents the sign of the
exponent, the next bit the sign of the mantissa, the next 2 bits represent the magnitude of
the exponent and the final four bits the magnitude of the mantissa. Convert the following
into that representation:
Our representation is:
Sign
Exponent
Sign
Mantissa
2 bits for exponent 4 bits for mantissa
So the range of exponent is from -11 to +11 (Notice we can have +/- 0). We cannot represent
values with an exponent outside that range.
The mantissa will be normalised to the form 1.dddd – We don’t need to represent the ‘1.’
a. 1.741
Convert to binary:
1.101111011…..
We round up to 4 digits, so we end up with:
1100 as the mantissa
The exponent is 0 (we’ll choose +0)
We’ll use 0 to indicate +
So we end up with:
00001100
That is:
Sign exponent: 0
Sign mantissa: 0
Exponent: 00
Mantissa: 1100
b. -1.741
This is the same as a) but with a negative sign for the mantissa:
01001100
c. 17412245
This is too large to represent – we cannot represent an exponent that large.
d. 5.741
Convert to binary:
101.10111…….
Normalise:
1.0110111……. x 2^(2)
Round:
1.0111
So:
Sign Exponent: 0
Sign Mantissa: 0
Mantissa: 0111
Exponent: 10
e. 1.741 x 2-3
This will be the same as a) but with an exponent of -3
Sign exponent: 1
Sign mantissa: 0
Exponent: 11
Mantissa: 1100
3. In base 5, what is the result of the following operations:
a. 213215+32415
301125
b. 320215-0225
314445
4. What would be the maximum address space if you used:
The maximum address is defined as 2n-1 (we have 2n addresses in the range 02n-1)
a. 36 bits
236-1
b. 12 bits
212-1
5. If a processor runs at 1GHz, and (at best) takes 5 ticks to execute instructions
a. Without pipelining how many instructions could be executed in a second?
At best you might execute 1 instruction every 5 ticks (so 200,000,000 instructions per
second). In practice it would be less (possibly much less).
b. With pipelining, how many instructions would you hope to execute per second?
If you had a 5 stage pipeline you might hope for a 5 times improvement in performance –
one instruction would come out of the pipeline every tick. In practice, there are many
factors that will mean that this speedup is never achieved: you need to fill the pipeline,
branch instructions, memory access etc.
6. If you need to store 5 million records each containing 150 bytes
a. How many bytes of data would you need to store?
5,000,000 x 150 = 750,000,000
b. How many bits would you need in an address to be able to address this many bytes?
You need 30 bits. You can take the log2 of the size (and round it up) or use trial and error
7. In MIPS:
a. What does a shift left instruction have as its operands and what does it do?
The instruction takes the value in the source register, shifts it left the specified number
of bits and places the results in the destination register
b. What is the difference between a register operand and an immediate operand?
A register operand specifies a register where a value is held. An immediate operand
specifes a value.
8. What is the relationship between binary machine code and assembly code?
In its purest form assembly code is a human readable equivalent of binary machine code – we
use names and symbols instead of bit patterns. So there is a 1:1 mapping between them. In
practice, assembly code may also have a few extra convenience features but it is still easily
mapped to machine code.
9. What does the instruction register hold?
It will hold the instruction currently being executed
10. What is a register?
A register is part of the definition of the architecture of a machine. It is a unit of memory which
is usually addressed directly in an instruction. It can be accessed very quickly.
11. What is a bus?
A bus is a channel used to interconnect components of a system. A bus allows multiple
components to share the same channel, rather than each having their own interconnection to
each other. Buses are used within a processor, to connect external devices, for networking and
so on.
Let me stress – these are NOT examples of questions you should expect to find in the quiz. They are
to help you check whether you understand and help focus your study.