1 / 38

COMP 1321 Digital Infrastructure

COMP 1321 Digital Infrastructure. Richard Henson University of Worcester October 2018. Week 3: Programming a CPU. Explain how logic gates can create a CPU Understand how registers and memory addresses are used to process input and store the results. How can logic gates make a CPU?.

lowman
Download Presentation

COMP 1321 Digital Infrastructure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 1321 Digital Infrastructure Richard Henson University of Worcester October2018

  2. Week 3: Programming a CPU • Explain how logic gates can create a CPU • Understand how registers and memory addresses are used to process input and store the results

  3. How can logic gates make a CPU? • Overview: • https://www.youtube.com/watch?v=1I5ZMmrOfnA • Early “chips” called integrated circuits • e.g. Intel 7481 ALU (Arithmetic & Logic Unit) • do arithmetic e.g. “adding” • provide logic…

  4. Minimalist CPU What is needed to build a successful CPU? ALU (Arithmetic Logic Unit) Memory (to store intermediate data)) “Execution Unit” Input & Output A Good Name! Intel’s first (1972) was called… “4004”… because it had a 4-bit bus!

  5. Input A Input B 3 3 2 2 add sub 5 1 Output Arithmetic Logic Unit (ALU) (or… more sophisticated… Integer Execution Unit) How could these numbers be represented as data that passes into the ALU?

  6. Programming Commands and Machine Code • A set of instructions for the CPU can be put into a program that can be executed one after the other • these instructions are known as machine code • Each type of CPU has its own type of “machine language”.

  7. Storing Results of Calculations • Memory is needed (let’s start with 8-bit data): • to feed ALU input • to record ALU output • Overview: • https://www.youtube.com/watch?v=fpnE6UAfbtU

  8. 0 1 2 3 3 2 3 2 4 add 5 5 Processing Idea Nr. 1 Move data in and out of data memory store 1. Move data from memory Memory DRAM, Hard Disk .. 2. 3. Move data into memory

  9. Sequence of CPU commands • If the CPU is going to do something useful, it needs a sequence of commands • e.g. • move number into ALU from memory • move another number in from memory • add them together • move the result into memory…

  10. IP 0 1 2 3 3 2 3 2 4 add 5 5 Processing Idea Nr.2 Move instructions into CPU from code memory Instruction Memory (Code Memory) Program

  11. 0 6 6 8 1 8 4 4 Registers Registers are high-speed memory stores on the CPU chip Parking places for data on the move AX BX AX and BX are used for ALU operations MAR MAR is memory address register, here 4. So result, 6+8=14 will go into memory cell address 4

  12. 0 1 Instruction Memory Data Memory mar ip 4 The computer so far …

  13. 0 1 Data Memory 4 A couple of extra bits.. Memory Data Register Instruction Register 1. 2 add ax,bx 2. 8 34 Instruction Memory Data • Energize ax • Energize bx • Select ALU “add" 2 Address 34 • Lineof code goes in… • Electrical bit signals come out

  14. 0 1 2 mar 3 Instruction Memory 4 Moving data into Registers For example … mov ax , [1] AX BX mov bx , [2] mov ax , [1] 5 mov bx , [2] 7 8 8 7 6 1

  15. 0 1 2 mar 3 Instruction Memory 4 Moving data into Memory For example … mov [3] , ax mov [0], bx AX BX mov [3] , ax 5 7 mov [0] , bx 7 8 8 7 6 8 1

  16. 0 1 2 mar 3 Instruction Memory 4 Adding Numbers For example … add ax , bx … this means ‘ add ax to bx, put the answer in ax’ AX BX Add ax,bx 5 7 8 8 7 8 7 15 6 1

  17. Now let’s slow things down… • Today’s CPUs process billions of instructions every second • in the early days (Intel 4004) it was merely millions! • Many great simulators have been produced that can work through a machine code program one cycle, or one instruction, at a time…

  18. What is “Processing”? • Mostly… calculations by the ALU: • need data input • from register • from external memory • need to store output • from register • from external memory • Could also be just a command, no data needed…

  19. CPU types • Most frequently used: • Intel 8086 family • Motorola (esp. 68000 family) • ARM (many mobile phones) • We’ll focus on Intel 8086 family • dates back to original IBM PC…

  20. Role of “Registers” • Memory stores inside the CPU • just the right size “word” of data for ALU • typically 1, 2, 4 bytes i.e. very small! • Advantage: CPU reads/writes the data very very quickly to/from the registers

  21. Architecture and Buses • Design of CPU • internal connections • external connections to motherboard • data bus (same word as registers) • address bus (depends on no of memory locations) • control bus (messages to/from components) • layout of components on motherboard

  22. Registers (summary…) 0 6 6 8 1 8 4 4 high-speed memory on the CPU chip Parking places for data on the move AX BX AX and BX registers are used for ALU operations MARR MAR is memory address register, 4 in eg. Result of processing, 6+8=14, will go into memory address 4

  23. 0 1 Instruction Memory Data Memory mar ip 4 The computer so far… (identify & name components)

  24. 0 1 Data Memory 4 A couple of extra registers.. Memory Data Register Instruction Register 1. 2 add ax,bx 2. 8 34 Instruction Memory Data • Energize ax • Energize bx • Select ALU “add" 2 Address 34 • Lineof code goes in… • Electrical bit signals come out

  25. 0 1 2 mar 3 Instruction Memory 4 Moving data into Registers (ie from specified location) mov ax , [1] for example … AX BX mov bx , [2] mov ax , [1] 5 mov bx , [2] 7 8 8 7 6 1

  26. 0 1 2 mar 3 Instruction Memory 4 Moving data into Memory For example … mov [3] , ax mov [0], bx AX BX mov [3] , ax 5 7 mov [0] , bx 7 8 8 7 6 8 1

  27. 8086 CPU family registers • 8086 chip always used a 16-bit word • SAM simulates an 8-bit word • popular on most early microcomputers… • Typical 8086 registers (stores): • general purpose data: AX, BX, CX, DX • specific use e.g. • program counter (PC): instruction address in memory • stack pointer SP): address of the top of the “stack”

  28. Data and Addressing • General purpose register contents… • data • memory address that points to data • Convention: • data written as hexadecimal equivalent • e.g. 4A • memory location also has square brackets • e.g. [4A]

  29. CPU Instructions • Used to tell the CPU what to do… • MOV is for moving data around… • MOV AX, 4A – move “4A” into AX register • MOV AX, [4A] – move data contained in address 4A into AX register • Many other instructions; range of operations… • collectively known as an instruction set • each CPU family has its own unique codes

  30. 8086 in practice • Four 16-bit General Purpose registers • each gen register (e.g. AX) can be read/written to upper (AH) & lower (AL) byte lower byte upper byte AX AL AH BX BL BH CX CH CL DH DL DX

  31. Another 8086 Instruction: ADD • Takes values from two registers • Adds them together • Deposits results back in one of the registers • Which one? • the register that appeared first • e.g. “MOV, AX, BX” puts result in AX

  32. 8088: Brains of the IBM PC

  33. Inside the 8088 address bus address adder External buses gen registers ALU

  34. Pentium(8086family) 1 2 • Fetch • Decode • ALU • Mem Ops • Reg Write 3 4 5

  35. IntelMulti-core

  36. Programming a CPU CPU programming code written as assembly language each family has its own instruction set Programming syntax depends on the CPU/instructions how they should be used Intel 8086 assembly language used for CPUs that support PC platforms

  37. Example 8086 Assembly Language MOV AH,08 INT 21 MOV DL,AL MOV AH,02 INT 21 MOV AH,4C INT 21

  38. So THAT’S how it all works!Now try it on a simulator…Next week: a focus on the fetch-execute cycle

More Related