An Introduction to Microprocessors 1312022 Costas Foudas Imperial

  • Slides: 24
Download presentation
An Introduction to Microprocessors 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 1

An Introduction to Microprocessors 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 1

Outline: l l l l 1/31/2022 Numerical representations Registers and Adders ATmega 103 architecture

Outline: l l l l 1/31/2022 Numerical representations Registers and Adders ATmega 103 architecture AVR assembly language Elementary example program STUDIO 3. 52 AVR Assembler Downloading with Pony. Prog Costas Foudas, Imperial College, Rm: 508, x 47590 2

Numbers in a computer: l Computers store arithmetic units called bits. Each bit is

Numbers in a computer: l Computers store arithmetic units called bits. Each bit is represented by an electrical signal which is either high or low (voltage levels). Normal high 1 and low 0 Logic Often high 0 and low 1 l l 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 Inverse Logic 3

High and Low In this course we use TTL or TTL-like (CMOS) technology where:

High and Low In this course we use TTL or TTL-like (CMOS) technology where: Transistor Logic (TTL) CMOS ‘High’ 1 3. 5 – 4. 9 Volts 2. 0 – 2. 4 Volts NO MAN’S LAND 74 HCxx NO MAN’S LAND 74 LSxx 0. 8 – 0. 4 Volts 1/31/2022 1. 0 – 0. 1 Volts ‘Low’ 0 Costas Foudas, Imperial College, Rm: 508, x 47590 4

Making a Zero or and One l How do you actually make a 0

Making a Zero or and One l How do you actually make a 0 or 1 ? Logic Signal 1/31/2022 It is clear that depending upon the switch position the line will be either ‘ 0’ or ‘ 1’ Costas Foudas, Imperial College, Rm: 508, x 47590 5

Storing Zeros and Ones: Registers are electronic devices capable of storing 0 or 1

Storing Zeros and Ones: Registers are electronic devices capable of storing 0 or 1 l D-FLIP-FLOPs are the most elementary registers which can store one bit l 8 DFFs clocked together make an one byte register l 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 6

The D-Flip-Flop (DFF) DAT O S Q D CLK 74 F 74 Q R

The D-Flip-Flop (DFF) DAT O S Q D CLK 74 F 74 Q R STORED S, R, Q-bar are Signals with Complement Logic O One can Set or Reset (Clear) the DFF using S or R On the rising edge of the clock the data are transferred and stored in Q. 1/31/2022 CLK D S R Q !Q X X L H H L X X H L L H H L H X X L L H H Costas Foudas, Imperial College, Rm: 508, x 47590 7

Byte Register Byte register that stores a byte Byte coming in 1/31/2022 DAT-7 S

Byte Register Byte register that stores a byte Byte coming in 1/31/2022 DAT-7 S Q D Q R Q-0 O O DAT-0 CLK O College, Rm: Costas Foudas, Imperial 508, x 47590 Byte Stored 8

Byte Register I l It exists in one package : Byte coming in 1/31/2022

Byte Register I l It exists in one package : Byte coming in 1/31/2022 DAT-7 E Q-7 74 F 374 DAT-0 CLK Q-0 Costas Foudas, Imperial College, Rm: 508, x 47590 Byte Stored 9

Bits & Bytes : l Bit 1, 0 l Nibble 4 bits l Byte

Bits & Bytes : l Bit 1, 0 l Nibble 4 bits l Byte 8 bits l Word 16 bits or 2 bytes l 1 Kbyte = 1024 Bytes = 8 Kbits l 1 Mbyte = 1024 Kbytes = 8*1024 Kbits l 1 Gbyte = 1024 Mbytes =…… 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 10

Binary Representation l This representation is based on powers of 2. Any number can

Binary Representation l This representation is based on powers of 2. Any number can be expressed in terms of 0 and 1 Example: 5 = 1012 = 1* 22 + 0*21 + 1*20 Example: 9 = 10012 = 1* 23 + 0* 22 + 0*21 + 1*20 Exercise: Convert any way you can the numbers 19, 38, 58 from decimal to binary. (use calculator or C program) 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 11

Hexadecimal Representation l This representation is based on powers of 16. Any number can

Hexadecimal Representation l This representation is based on powers of 16. Any number can be expressed in terms of: 0, 1, 2, …, 9, A, B, C, D, E, F (0, 1, 2, …, 9, 10, 11, 12, 13, 14, 15) Example: 256 = 10016 = 1* 162 + 0*161 + 0*160 Example: 1002 = 3 EA 16 = 3* 162 + 14*161 + 10*160 Exercise: Convert any way you can the numbers 1492, 3481, 558 from decimal to hex. (use calculator or C program) 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 12

Boolean Operations l NOT: NOT(101) = 010 l AND: AND(10101 ; 01010) = 0

Boolean Operations l NOT: NOT(101) = 010 l AND: AND(10101 ; 01010) = 0 l OR : OR(10101; 01010) = 11111 l SHIFT L: SHIFT L(111) = 1110 l SHIFT R: SHIFT R(111) = 011 Why shift is Exercise: (1) Find NOT(AAA) Important ? (2) Find OR(AAA; 555) Try SHIFT R(011) (3) Find AND (AEB 123; FFF 000) 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 13

Negative Numbers l How do you represent negative numbers ? Using 2’s Complement Arithmetic

Negative Numbers l How do you represent negative numbers ? Using 2’s Complement Arithmetic Recipe : Take the complement of the number and add 1. Example: Consider the number 3 = 0112 Then – 3 is NOT(011) + 1 = 100 + 1 = 101 Exercise: Consider a 4 bit machine. Derive all possible positive and negative numbers 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 14

4 -bit Negative Numbers l Consider a 4 bit machine. Find all positive and

4 -bit Negative Numbers l Consider a 4 bit machine. Find all positive and negative numbers you can have: 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 Integer Sign Magnitude 2’s compl ement +7 0111 +6 0110 +5 0101 +4 0100 +3 0011 +2 0010 +1 0001 0 0000 -1 1001 1111 -2 1010 1110 -3 1011 1101 -4 1100 -5 1101 1011 -6 1110 1010 -7 1111 1001 -8 1000 (-0) 1000 15

How do the computers do all these ? l l 1/31/2022 You may remember

How do the computers do all these ? l l 1/31/2022 You may remember how do we make an AND, OR, NOT: Any Digital device can be made out of these three gates. Costas Foudas, Imperial College, Rm: 508, x 47590 16

De. Morgan’s Theorem l You can swap shapes if at the same time you

De. Morgan’s Theorem l You can swap shapes if at the same time you invert all inputs and outputs : = Exercise: Write to truth table for both and prove that this is correct 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 17

Exercise: Exclusive OR l Construct an exclusive OR gate using OR, AND NOT: 1/31/2022

Exercise: Exclusive OR l Construct an exclusive OR gate using OR, AND NOT: 1/31/2022 A B XOR 0 0 1 1 0 Costas Foudas, Imperial College, Rm: 508, x 47590 18

The Exclusive OR l Solution: XOR A B 1/31/2022 = Costas Foudas, Imperial College,

The Exclusive OR l Solution: XOR A B 1/31/2022 = Costas Foudas, Imperial College, Rm: 508, x 47590 19

The D-Flip Flop l Making a DFF using gates A X B Y A

The D-Flip Flop l Making a DFF using gates A X B Y A B X Y H H H L L H H L L L H H Undefined A B X Y 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 20

How do Computers Add ? l Make a 2 bit adder with a carry_in

How do Computers Add ? l Make a 2 bit adder with a carry_in and a carry out : Cin A B SUM Cout 0 1 0 0 0 1 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 1 1 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 21

Two Bit Adder with Carry l Answer: 1/31/2022 Costas Foudas, Imperial College, Rm: 508,

Two Bit Adder with Carry l Answer: 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 22

Arithmetic Logic Unit (ALU) Center of every computer: l 1/31/2022 Costas Foudas, Imperial College,

Arithmetic Logic Unit (ALU) Center of every computer: l 1/31/2022 Costas Foudas, Imperial College, Rm: 508, x 47590 23

You can actually design one yourself with what you already know The Arithmetic Overflow

You can actually design one yourself with what you already know The Arithmetic Overflow Flag is stored here The result is stored in this register Eight Bits Wide Bus. 1/31/2022 2 Bit adders with carry-in and carry-out Costas Foudas, Imperial College, Rm: 508, x 47590 24