0% found this document useful (0 votes)
10 views61 pages

ELEC1601 Week 6 2023

ELEC1601 Week 6 2023

Uploaded by

februarydtz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views61 pages

ELEC1601 Week 6 2023

ELEC1601 Week 6 2023

Uploaded by

februarydtz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

ELEC1601 Week 6

Introduction to Computer Systems

The University of Sydney


Lecture 6

Transistors RAMs/
Gates ROMs Actuators
ALUs
Flip-Flops/ Computer Sensors
Compilers
Registers Architecture Bus

Real-world
Ones and Zeros Words Instructions Programs
interactions

FSMs Pipelining Software Calibration


Floating
Combinational Point Memory/
Digital Logic Fixed Point Stack Subroutines
Addressing High-level
Propositional Binary Modes Constructs
Logic ISA/
Assembly
Machine
Code Simulation
Code
The University of Sydney
Outline:
– Lab 3
– Complete Floating-point from Week 5
– Memory

The University of Sydney Page 3


Floating-point
– What do you need to know?
– How to read understand a floating-point description
• What is Sign, Mantissa, Exponent
• What is an implicit 1
• What is Overflow/Underflow
– What are the characteristics of floating-point vs fixed-point
• What is the relationship between bits, range, precision and rounding error for
floating-point numbers vs fixed-point numbers
• How to perform floating-point arithmetic
– When to use floating-pont.

The University of Sydney Page 4


Floating-point
– What do you need to know?
– How to read understand a floating-point description
• What is Sign, Mantissa, Exponent
• What is an implicit 1
• What is Overflow/Underflow
– What are the characteristics of floating-point vs fixed-point
• What is the relationship between bits, range, precision and rounding error for
floating-point numbers vs fixed-point numbers
• How to perform floating-point arithmetic
– When to use floating-pont.

The University of Sydney Page 5


What is Floating-point?
– A number system with three key components:
– Sign
– Mantissa
– Exponent

– You need to read the definition of the number system to


understand what it means.
– Best understood by example

The University of Sydney Page 6


Floating-point example 3
– An 8-bit number format is:
– 1 sign bit, 4 mantissa bits, 3 exponent bits
– There is is an exponent bias of -2 with the exponent in unsigned binary
– There is an implicit one for the mantissa in the encoding (1.mantissa)

– Convert 11010100 to decimal, use as many decimal places as


necessary
– What is its absolute maximum, minimum. What is it’s worst-case
round-off error?

The University of Sydney Page 7


Why the implicit one
– A 16-bit number format is:
– 1 sign bit, 10 mantissa bits, 5 exponent bits
– Two’s complement exponent, no bias
– There is no implicit one for the mantissa in the encoding (0.mantissa)

– How do you represent 7.125 in floating point?

The University of Sydney Page 8


Why the implicit one
– A 16-bit number format is:
– 1 sign bit, 10 mantissa bits, 5 exponent bits
– Two’s complement exponent, no bias
– There is no implicit one for the mantissa in the encoding (0.mantissa)

– How do you represent 16.625 in floating point?

The University of Sydney Page 9


Why the implicit one
– How many bits did you need to accurately represent 7.125?
– How many bits did you need to accurately represent 16.625?

– Is there any other way you could have represented either


number?

The University of Sydney Page 10


Floating-point design example
– You must represent numbers in the range [0 127].
– Design an 8-bit number format for this range:

– How do you represent the integer 117 in this number system?


– What is the maximum and minimum value you can represent?
– What is the worst-case round-off error?

The University of Sydney Page 11


Why should I learn custom floating-point?
– IEEE 754 Standard Floating Point Single precision:

– IEEE 754 Standard Floating Point Double precision

The University of Sydney Page 12


Why should I learn custom floating-point?
– Single precision:

– Half precision

The University of Sydney Page 13


Why should I learn custom floating-point?
– IEEE standard single precision
– Implicit leading 1
• Except for subnormals…
– Exponent is unsigned with a bias of -127
– Special codes:
• Zero: exponent = 0, mantissa=0
• NaN (0/0, sqrt(-10))
• Infinity (100/0, -100/0)

The University of Sydney Page 14


Why should I learn custom floating-point?

The University of Sydney Page 15


Overflow/Underflow
– Overflow: When a number is too large to be represented.
– What causes this?
– Underflow: When a number is too small to be represented.
– What causes this?

The University of Sydney Page 16


Floating-point
– What do you need to know?
– How to read understand a floating-point description
• What is Sign, Mantissa, Exponent
• What is an implicit 1
• What is Overflow/Underflow
– What are the characteristics of floating-point vs fixed-point
• What is the relationship between bits, range, precision and rounding error for
floating-point numbers vs fixed-point numbers
• How to perform floating-point arithmetic
– When to use floating-pont.

The University of Sydney Page 17


Floating-point vs Fixed-point
– Let’s start with an example.

– You have an 5 bits.


– You can design a fixed or floating-point number system.
– What is the range/precision of each number system?
– What is the round-off error associated with each number system?

– You want to represent numbers from 0 to 7.


– Your floating point is of the form: x  2e  0.b1b2 ...bm
– The exponent is unsigned with no bias

The University of Sydney Page 18


Fixed vs Float a visualisation
5 bit fixed point, 3 bits integer, 2 bits fractional
Roundoff Overflow

Number system must not overflow (error unbounded)


Accumulation of round-off errors must lie below tolerable region

x  2e  0.b1b2 ...bm , bi  {0,1}


5 bit floating point, 2 bits exponent, 3 bits mantissa

The University of Sydney Page 19


Floating-point
– What do you need to know?
– How to read understand a floating-point description
• What is Sign, Mantissa, Exponent
• What is an implicit 1
• What is Overflow/Underflow
– What are the characteristics of floating-point vs fixed-point
• What is the relationship between bits, range, precision and rounding error for
floating-point numbers vs fixed-point numbers
• How to perform floating-point arithmetic
– When to use floating-pont.

The University of Sydney Page 20


Multiplication in floating-point
– Consider some examples:
– 1 sign-bit, 3 exponent bits (unsigned), 4 mantissa bits.
– We assume there is an implicit 1

The University of Sydney Page 21


Addition in floating-point
– Consider some examples:
– 1 sign-bit, 3 exponent bits (unsigned), 4 mantissa bits.
– We assume no implicit 1

– How do you add 0 100 1101 + 0 001 1001?

The University of Sydney Page 22


How do you add numbers in FP
Evaluate 3+0.625+0.875, with 3 bit mantissa
– Compute 3+0.625 – Compute 3.5+0.875.
x  2e  0.b1b2 ...bm
– 3 is 22x0.110 – 3.5is 22x0.111
– 0.625 is 20x0.101 – 0.875 is 20x0.111

– Align exponents – Align exponents


– 3 is 22x0.110 – 3.5 is 22x0.111
– 0.625 is 22x0.00101 – 0.875 is 22x0.00111
– Perform addition – Perform addition
– 22x0.11101 – 22x1.00011
– Re-normalise to 5 bits – Re-normalise to 5 bits
– 22x0.111 = 3.5 – 23x0.100 = 4
– Roundoff error of 0.125 – Roundoff error of 0.375

The University of Sydney Page 23


How do you add numbers in FP
Evaluate 0.625+0.875+3, with 3 bit mantissa
– Compute 0.625+0.875 – Compute 1.5+3
x  2e  0.b1b2 ...bm
– 0.625 is 20x0.101 – Result is 21x0.110
– 0.875 is 20x0.111 – 3 is 22x0.110

– Align exponents – Align exponents


– 0.625 is 20x0.101 – 3 is 22x0.110
– 0.875 is 20x0.111 – 0.875 is 22x0.0110
– Perform addition – Perform addition
– 20x1.100 – 22x1.001
– Re-normalise to 5 bits – Re-normalise to 5 bits
– 21x0.110 = 1.5 – 23x0.101 = 5
– No roundoff error – Roundoff error of 0.5

The University of Sydney Page 24


Floating-point
– What do you need to know?
– How to read understand a floating-point description
• What is Sign, Mantissa, Exponent
• What is an implicit 1
• What is Overflow/Underflow
– What are the characteristics of floating-point vs fixed-point
• What is the relationship between bits, range, precision and rounding error for
floating-point numbers vs fixed-point numbers
• How to perform floating-point arithmetic
– When to use floating-pont.

The University of Sydney Page 25


Encoding Real Numbers
– Do we need floating-point to encode real numbers ?

The University of Sydney Page 26


Why Floating-point?
– You want to represent a wide range with a fixed number of
bits?

– Reason for floating-point: You want to represent a variable


range with a fixed number of bits

The University of Sydney Page 27


Example:
– Your memory can store 16 bits.
– Your algorithm involves some calculations with many
variables
– Variables include numbers as large as 30000.
– Your algorithm has an exit condition var1-var2>1e-6
– You need more fixed-point bits than you can handle

The University of Sydney Page 28


Bisection algorithm

The University of Sydney Page 29


Why not use floating-point?

The University of Sydney Page 30


A bonus – floating-point games

The University of Sydney Page 31


Floating point is not associative
1e 7

i
i 1
Which answer is correct?

The University of Sydney Page 32


Floating point is not associative

The University of Sydney Page 33


Floating point games

2 25

 1
2  25

i 1

The University of Sydney Page 34


Memory

The University of Sydney Page 35


Memory
– What do you need to know?
– Why is memory necessary
– Main types of memory in a computer architecture
• Registers
• RAM (ROM)
– How to visualize a RAM/ROM
• What is the relationship between total data storage, number/size of
cells/number of address bits
– How to store data in memory
• Reading/writing
• Endianness
• Indirection
The University of Sydney Page 36
Memory
– What do you need to know?
– Why is memory necessary
– Main types of memory in a computer architecture
• Registers
• RAM (ROM)
– How to visualize a RAM/ROM
• What is the relationship between total data storage, number/size of
cells/number of address bits
– How to store data in memory
• Reading/writing
• Endianness
• Indirection
The University of Sydney Page 37
Why/What memory
– Every computer has memory

– Memory operations:
– Read
– Write

The University of Sydney Page 38


Memory
– What do you need to know?
– Why is memory necessary
– Main types of memory in a computer architecture
• Registers
• RAM (ROM)
– How to visualize a RAM/ROM
• What is the relationship between total data storage, number/size of
cells/number of address bits
– How to store data in memory
• Reading/writing
• Endianness
• Indirection
The University of Sydney Page 39
What is a register?
– Remember a D-flip flop?
D Q

– A register is just a collection of D-Flip-flops


– It allows you to represent “words” (your encodings e.g. 4-bit
unsigned binary)

The University of Sydney Page 40


What is a RAM (ROM)?
– A denser (but slower) way of storing data

N
Address Array

Data

The University of Sydney Page 41


Memory
– What do you need to know?
– Why is memory necessary
– Main types of memory in a computer architecture
• Registers
• RAM (ROM)
– How to visualize a RAM/ROM
• What is the relationship between total data storage, number/size of
cells/number of address bits
– How to store data in memory
• Reading/writing
• Endianness
• Indirection
The University of Sydney Page 42
What does a memory conceptually look like?
2:4
Decoder bitline2 bitline1 bitline0
wordline3
N 11
Address Array 2 stored stored stored
Address bit = 0 bit = 1 bit = 0
wordline2
10
stored stored stored
wordline1 bit = 1 bit = 0 bit = 0
01
M stored stored stored
bit = 1 bit = 1 bit = 0
wordline0
Data 00
stored stored stored
bit = 0 bit = 1 bit = 1

Data2 Data1 Data0

The University of Sydney Page 43


What does a memory conceptually look like?

DRAM bit cell:


bitline SRAM bit cell:

wordline
bitline bitline
stored wordline
bit

The University of Sydney Page 44


How does a memory (ROM) work
– (Flash is a variant of ROM) word lines (only one
is active – decoder is
just right for this)

1 1 1 1

n
2 -1

i word[i] = 0011
decoder
j word[j] = 1010

0 n-1
Address
bit lines (normally pulled to 1 through
resistor – selectively connected to 0
by word line controlled switches)

The University of Sydney Page 45


Memory
– What do you need to know?
– Why is memory necessary
– Main types of memory in a computer architecture
• Registers
• RAM (ROM)
– How to visualize a RAM/ROM
• What is the relationship between total data storage, number/size of
cells/number of address bits
– How to store data in memory
• Reading/writing
• Endianness
• Indirection
The University of Sydney Page 47
First – an aside. Some notation
– How many grams in a kilogram?

– How many metres in a kilometre?

– How many bytes in a kilobyte?


– KB: 2^10 Bytes,
– Also
– MB: 2^20 Bytes,
– GB: 2^30 Bytes,
The University of Sydney Page 48
Memory visualisation
– Output can be M bits (often described as A cells of B bytes
such that A*B/8=M)
N
Address Array

Data

The University of Sydney Page 49


Memory visualisation

N
Address Array

Data
– How many cells in a 2GB memory, where each cell is 1 Byte.
– 2^30 *2 = 2^31

The University of Sydney Page 50


Memory visualisation

N
Address Array

Data
– How many cells in a 2GB memory, where each cell is 2 Bytes.
– 2^30 *2 = 2^30

The University of Sydney Page 51


Memory visualisation

N
Address Array

Data
– How much data can a memory with 10 address bits, 1 byte
cells store?
– 2^10
The University of Sydney Page 52
Memory visualisation

N
Address Array

Data
– 10 bit address, 2-byte cells. How many cells are there in the
memory?

The University of Sydney Page 53


Memory Read/Write
– Write 4 bits into 8-bit cell. What happens?

The University of Sydney Page 54


How do we store things in memory

The University of Sydney Page 55


How do we store things in memory?
– What if I want to store a big thing in memory

The University of Sydney Page 56


How do we store things in memory?
– Can a big endian architecture share memory with a little
endian memory?

The University of Sydney Page 57


How to store arrays in memory
– Suppose
Imagine you just get
we have an given
array
the memory on the right.
of integers
– What
A[] = is stored
{10, 267,in39,
it?40}
– How many bits do we need
to store the array?
– What does it look like in
memory?

The University of Sydney Page 58


Design decisions with arrays
– How do you know size of array if stored in memory?
– Memory has no notion of size
– It does not know how many bits are the integers
– It does not know they are storing integers

– Options
– Create a symbol to say end of array
• Typically used for strings (null character)
• Not great for integers (already have a 0)
– Store the size
• First put a number
– Do nothing…

The University of Sydney Page 61


How to find elements in memory
– How do I look up A[5]?
– Address base
+ bytes to encoding array size
+ index * size of element

– E.g. What if look up A[7] in a


array declared of size 6.
– Error message
arrayindexoutofbounds

The University of Sydney Page 62


Working with memory addresses (Indirection)
– Common when you use pointers
(common for structures/arrays):

The University of Sydney Page 63


Working with memory addresses (Indirection)
– Common when you use pointers
(common for structures/arrays):

The University of Sydney Page 64

You might also like