67
Molecules to Machine Code James Lawson

Molecules to Machine Code

Embed Size (px)

Citation preview

Page 1: Molecules to Machine Code

Molecules to Machine CodeJames Lawson

Page 2: Molecules to Machine Code

Agenda• Part 1 - Semiconductors

– Electromagnetic theory• Part 2 – Electrical Primitives

– Diodes, Transistors• Part 3 – Integrated Circuits

– Logic Gates, Memory and Arithmetic units, CPUs• Part 4 – Programming

– Machine Code and Assembly Language

Page 3: Molecules to Machine Code

Part 1Semiconductors

Page 4: Molecules to Machine Code

Conductors vs SemiconductorsWhat is the difference?[discuss]

Page 5: Molecules to Machine Code

A non exhaustive list of semiconductors…

• Diamond• Silicon• Germanium• Selenium• Tellurium

For a more extensive list please refer to: -http://en.wikipedia.org/wiki/List_of_semiconductor_materials

Page 6: Molecules to Machine Code

Atomic composition• Lets look at the atomic composition of a

couple of these semiconductors in their pure form.

• An even number of valence electrons (outer shell electrons)

• 4 valence electrons in both elements.

Page 7: Molecules to Machine Code

Pure Silicon forms a tight lattice…

Page 8: Molecules to Machine Code

Getting your semi on…• A lack of spare electrons in the Silicon lattice

makes it difficult for electrical current to flow.

• Electrical current flows when electrons can skip along the material.

• This is why semiconductors are not called conductors – they need a little helping hand.

Page 9: Molecules to Machine Code

Lets get doped up…• Semiconductor ‘Doping’ is a technique

where a trace amount of a second material is added to the semiconductor to make it less pure.

• By doing so, we can alter the electro-magnetic properties of the semiconductor.

Page 10: Molecules to Machine Code

Lets get doped up…

• Arsenic has 5 valence electrons.

• Adding a trace amount of arsenic to Silicon can have a nice side effect.

• Lets look at the atomic composition Arsenic.

Page 11: Molecules to Machine Code

A Silicon lattice doped with Arsenic: -

Page 12: Molecules to Machine Code

Types of doping…• An excess of electrons in the lattice has now

made the Silicon take on a negative charge (because electrons are negatively charged).

• This is called N-Type Arsenic doped Silicon.

Page 13: Molecules to Machine Code

Types of doping…• Doping can also be used to provide a

shortage of electrons. Any ideas on what you would use to do this?

• Doping with Boron (which has only 3 valence electrons) will result in positively charged Silicon. This is called P-Type Boron doped Silicon.

Page 14: Molecules to Machine Code

Part 2Electrical Primitives

Page 15: Molecules to Machine Code

• So we can create a nice semiconductor with Silicon by increasing the number of free electrons – this is great for our mundane circuitry, but what else can we use it for?

• Lets layer the stuff…

Uses for our doped semiconductor?

Page 16: Molecules to Machine Code

Uses for our doped semiconductor?• In the presented arrangement we have P-

Type Silicon (with electron holes) layered above N-Type Silicon (with an excess of electrons).

• Lets investigate what happens if we add an electrical current to this arrangement.

Page 17: Molecules to Machine Code

Negative current to N-Type Silicon• If we connect a negative current to the side

with the N-Type Silicon…

• The incoming electrons will dislodge the electrons in the Lattice and push them towards the P-Type silicon to fill the holes.

• Likewise, the lack of electrons on the P side will cause electrons to be pulled up and out the top of the Silicon.

+

-

Page 18: Molecules to Machine Code

Negative current to N-Type Silicon

Electricity will flow!

+

-

Page 19: Molecules to Machine Code

Negative current to P-Type Silicon

• What happens if we reverse the connections?

• The lack of electrons at the will pull the N-Type spare electrons down.

• The excess electrons at the P-Type silicon will cause the holes in the lattice to be ‘pulled’ upwards.

-

+

Page 20: Molecules to Machine Code

Negative current to P-Type Silicon

+

-

Electricity will NOT flow!

Page 21: Molecules to Machine Code

The Diode!• We’ve just invented a Diode…

• A component that allows current to flow in one direction only.

+

-

Page 22: Molecules to Machine Code

• Lets take a look if at what happens if we layer this stuff some more!

More uses for our doped semiconductor?

Page 23: Molecules to Machine Code

More uses for our doped semiconductor?

• Here we have essentially created a barrier - you can think of this as two back-to-back diodes.

• It’s difficult to see how we could get current to flow either way.

• However, all is not lost…

Page 24: Molecules to Machine Code

More uses for our doped semiconductor?

• If we apply a small amount of current to the N-Type Silicon in the middle then we will end up with a base flow.

• The base flow will take the charge collecting at one end and drag through the layers.

• The overall current will be emitted at the other end.

Page 25: Molecules to Machine Code

More uses for our doped semiconductor?

This stuff is pretty mental to visualise so its probably a good time to show a simplified model using some water…

Page 26: Molecules to Machine Code

• We’ve just invented a P-N-P Transistor…

• An electrical component that allows current to flow in one direction that can be switched on or off.

The Transistor!

Page 27: Molecules to Machine Code

Part 3Integrated Circuits

Page 28: Molecules to Machine Code

Boolean Logic• The advent of the transistor and digital

electronics was revolutionary.

• Before we investigate why – lets have a quick refresher on Boolean logic…

Page 29: Molecules to Machine Code

AND

A B Q0 0 00 1 01 0 01 1 1

Boolean Logic

Page 30: Molecules to Machine Code

OR

A B Q0 0 00 1 11 0 11 1 1

Boolean logic…

Page 31: Molecules to Machine Code

NOR

A B Q0 0 10 1 01 0 01 1 0

Boolean logic…

Page 32: Molecules to Machine Code

XOR

A B Q0 0 00 1 11 0 11 1 0

Boolean logic…

Page 33: Molecules to Machine Code

NOT

A Q0 11 0

Boolean logic…

Page 34: Molecules to Machine Code

NAND

A B Q0 0 10 1 11 0 11 1 0

Boolean logic…

Page 35: Molecules to Machine Code

NAND Logic• NAND gates can be used to create all of the

other Boolean operators…

A B Q0 0 10 1 11 0 11 1 0

A Q0 1

1 0

Page 36: Molecules to Machine Code

NAND Logic• Now that we have used a NAND to make a

NOT, can make this…

A B Q0 0 00 1 01 0 01 1 1

Page 37: Molecules to Machine Code

NAND Logic• …and so on. Feel free to carry this on in

your own time and have a go at making the other logic gates.

A B Q0 0 00 1 01 0 01 1 1

Page 38: Molecules to Machine Code

NAND Logic• Why focus on the NAND operator?• Because it’s relatively easy to make from a

couple of transistors!

A B Q- - +- + ++ - ++ + -

Page 39: Molecules to Machine Code

NAND Logic• So… by using Silicon doped with Arsenic and

Boron we can now do exactly what Texas Instruments do and create one of these bad boys… • A 14 pin integrated circuit with 4 NAND

gates.

• 2 pins reserved for power (pins 7 and 14)

• Implemented internally using 8 NPN transistors.

Page 40: Molecules to Machine Code

What can we build with a NAND gate?• This pairing of NAND gates is

called an RS-Flipflop.

• Sending a brief pulse along S will SET the value of Q to 1. Sending a brief pulse along R will RESET the value of Q to 0.

S R Q0 0 Q0 1 01 0 1

Page 41: Molecules to Machine Code

What can we build with a NAND gate?• That’s correct - we’ve now just

built ourselves a 1 bit memory.

• If you stick 64 of these together on a single CPU dye and you have a single 64 bit register – that’s 128 transistors.

S R Q0 0 Q0 1 01 0 1

Page 42: Molecules to Machine Code

What else can we build with a NAND gate?

• Actually – lots of things!

Page 43: Molecules to Machine Code

What else can we build with a NAND gate?

• Lets imagine we’re going to take on Intel and building a 1 bit CPU – we certainly need to have logic inside the CPU to ADD a couple of 1 bit numbers…

• What would the truth table look like for that?

Page 44: Molecules to Machine Code

What else can we build with a NAND gate?

A B R C0 0 0 00 1 1 01 0 1 01 1 0 1

• Okay - It’s not rocket science. We have a result and a carry bit (the overflow flag).

• How could we achieve this using NAND logic?

Page 45: Molecules to Machine Code

What else can we build with a NAND gate?

A B R C0 0 0 00 1 1 01 0 1 01 1 0 1

• R looks like a simple XOR of A and B…

Page 46: Molecules to Machine Code

What else can we build with a NAND gate?

A B R C0 0 0 00 1 1 01 0 1 01 1 0 1

• R looks like a simple XOR of A and B…

• C looks like a simple AND of A and B…

Page 47: Molecules to Machine Code

What else can we build with a NAND gate?

A B R C0 0 0 00 1 1 01 0 1 01 1 0 1

• Combined…

Page 48: Molecules to Machine Code

What else can we build with a NAND gate?

A B R C0 0 0 00 1 1 01 0 1 01 1 0 1

• And converted to NAND logic…

Page 49: Molecules to Machine Code

What else can we build with a NAND gate?

• With a minor tweak we can change this to include a carry in too!

• Not bad – a 1 bit adder with carryover (overflow) using only 18 transistors.

Page 50: Molecules to Machine Code

What else can we build with a NAND gate?

• Yikes - We could chain this stuff together to make a larger adder!

Page 51: Molecules to Machine Code

Putting it all together…• So we have created a 4 bit adder.

• And lets pretend we followed the same process to create some 4 bit subtraction logic.

• And we have created three 4 bit registers using 12 RS-Flipflops.

• And we have used a single RS-Flipflop for a carryover register.

Page 52: Molecules to Machine Code

Putting it all together…

Page 53: Molecules to Machine Code
Page 54: Molecules to Machine Code
Page 55: Molecules to Machine Code
Page 56: Molecules to Machine Code
Page 57: Molecules to Machine Code
Page 58: Molecules to Machine Code
Page 59: Molecules to Machine Code
Page 60: Molecules to Machine Code
Page 61: Molecules to Machine Code

Part 4Programming

Page 62: Molecules to Machine Code

The instruction set…Op4

Op3

Op2

Op1

D0 D1 D2 D3

0 0 0 1 Set the value of Register A to D0-D30 0 1 0 Set the value of Register B to D0-D30 0 1 1 Add Register A to Register B and store the result in

Register R.

Will set Register C if an overflow occurs.0 0 0 0 Subtract Register B from Register A and store the

result in Register R.

Will set Register C if an underflow occurs.

Page 63: Molecules to Machine Code

Programming the machineThe following 3 bytes of machine code show how a CPU would add two numbers together: -1A 26 30

0001 1010 1A Sets Register A to 100010 0110 26 Sets Register B to 60011 0000 30 Add Register A to Register B

Page 64: Molecules to Machine Code

Assembly language is nothing specialIs simply a set of mnemonics to make the hexadecimal more memorable: -

LDA A 0001 1010 1A Sets Register A to 10LDB 6 0010 0110 26 Sets Register B to 6ADD 0011 0000 30 Add Register A to Register B

Page 65: Molecules to Machine Code

A modern CPU• The program counter (PC)

– A register that contains the memory address for the next machine code instruction to be executed.

– A number of instructions exist to alter the PC register: JMP, JNE, JEQ, etc.

Page 66: Molecules to Machine Code

A modern CPU• The stack pointer (SP)

02 LDA 303 PUSH PC04 JMP 1A

.

.

.1A LDB 41B POP PC

Page 67: Molecules to Machine Code

Questions?