Molecules to Machine Code

Preview:

Citation preview

Molecules to Machine CodeJames Lawson

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

Part 1Semiconductors

Conductors vs SemiconductorsWhat is the difference?[discuss]

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

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.

Pure Silicon forms a tight lattice…

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.

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.

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.

A Silicon lattice doped with Arsenic: -

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.

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.

Part 2Electrical Primitives

• 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?

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.

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.

+

-

Negative current to N-Type Silicon

Electricity will flow!

+

-

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.

-

+

Negative current to P-Type Silicon

+

-

Electricity will NOT flow!

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

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

+

-

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

More uses for our doped semiconductor?

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…

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.

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…

• 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!

Part 3Integrated Circuits

Boolean Logic• The advent of the transistor and digital

electronics was revolutionary.

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

AND

A B Q0 0 00 1 01 0 01 1 1

Boolean Logic

OR

A B Q0 0 00 1 11 0 11 1 1

Boolean logic…

NOR

A B Q0 0 10 1 01 0 01 1 0

Boolean logic…

XOR

A B Q0 0 00 1 11 0 11 1 0

Boolean logic…

NOT

A Q0 11 0

Boolean logic…

NAND

A B Q0 0 10 1 11 0 11 1 0

Boolean logic…

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

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

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

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

couple of transistors!

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

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.

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

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

What else can we build with a NAND gate?

• Actually – lots of things!

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?

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?

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…

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…

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…

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…

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.

What else can we build with a NAND gate?

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

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.

Putting it all together…

Part 4Programming

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.

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

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

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.

A modern CPU• The stack pointer (SP)

02 LDA 303 PUSH PC04 JMP 1A

.

.

.1A LDB 41B POP PC

Questions?

Recommended