Introduction - UNB

18
Introduction Why and what for 2253 Levels of abstraction Instruction Set Architectures Major parts of any computer von Neumann architecture Flow of control

Transcript of Introduction - UNB

Page 1: Introduction - UNB

Introduction

● Why and what for 2253● Levels of abstraction● Instruction Set Architectures● Major parts of any computer● von Neumann architecture● Flow of control

Page 2: Introduction - UNB

CS2253● Goal: write a simple C program and understand how the computer actually executes it.

● Last year, we used the ARM7TDMI processor.● This year, we use the fictional LC-3.● The Church-Turing thesis essentially states that all systems with a certain minimal computational capability are able to compute the same things as each other. So LC3 vs ARM vs Intel x86 does not matter, at least theoretically.

● And in actuality, LC3 and ARM etc. are fundamentally similar.

● Easy to pick up a second machine....

Page 3: Introduction - UNB

Levels of Abstraction

● From atoms, we build transistors. [Lowest level]● From transistors, we built gates (ECE courses).● From gates, we build microarchitectures (CS3813) that

implement machine instructions.● From machine instructions, we can make simple programs

directly (first part of this course).● Or a compiler can string together machine instructions

corresponding to our C code (second part).● From simple pieces of C code, we can build OSes,

databases, other complex software systems. [Highest level]

Page 4: Introduction - UNB

Textbook Fig 1.6

Page 5: Introduction - UNB

Why Should I Care About the Lower Levels?

● If you want to work in the computer hardware field, it's obvious.

● If you want to work in software:– it's sad if you aren't intellectually a little bit curious about

how things really happen.

– when things fail, you tend to need to “see behind the veil” to understand what is going wrong. Debugging often requires a lower-level view.

– it helps you understand why some operations would be fast, while others would be slow. (Performance debugging.)

Page 6: Introduction - UNB

Microarchitecture example (block diagram, book Figure 4.3)

Page 7: Introduction - UNB

Instruction Set Architecture

● ISA is an important concept. In Java terms, it is like an Interface to the microarchitecture (hardware).

● It specifies all the things that you would need to know, to write a machine-instruction program:– what are the basic instructions?

– how does the machine find the data for instructions?

– what are the basic data types supported (bit lengths)?

– how is memory organized?

– how and where are the instructions stored?

Page 8: Introduction - UNB

Multiple implementation of an ISA

● In Java, several classes can implement the same Interface.● So, several microarchitectures can have the same ISA. They

can run the same machine instructions as each other.● IBM mainframes in the 1960s: fast implementation if you're

rich, slow ones if not.● Today: AMD and Intel processors can run the same code.● But computer designers like to extend ISAs over time.

Backward compatibility is the goal. No bad idea ever dropped. Ugly messes like Intel x64 architecture.

Page 9: Introduction - UNB

Textbook Fig 1.5

Page 10: Introduction - UNB

Major Parts of Any Computer

● An input and an output facility (from/to people or devices)● Memory/Memories to store data and programs● A “datapath” with the logic needed to add, multiply, store ...

binary values, etc.● A “controller” that goes through the program and makes the

datapath do the required operations, one at a time.

● Controller + Datapath = Processor (aka CPU)● Controller is the “puppeteer” and the datapath is the “puppet”.

Page 11: Introduction - UNB

Textbook Figure 4.3 again

Page 12: Introduction - UNB

John von Neumann's architecture

● John von Neumann was a brilliant mathematician (and statistician and nuclear weapons guy and father of game theory and inventor of MergeSort and ...) who wrote an influential report in 1946 with a computer design.

● A von Neumann architecture stores the program in (a different part of) the same memory that stores the data.

● A Harvard architecture uses separate memories.● Modern computers appear to be von Neumann, but behind

the scenes are a bit Harvard-ish.● Except for some special-purpose machines.

Page 13: Introduction - UNB

Last year's book, Figure 1.8

Page 14: Introduction - UNB

von Neumann and the IAS, 1952

Page 15: Introduction - UNB

How a von Neumann Architecture Works

● The program is a list of instructions located in memory. Part of the control unit is the Program Counter (PC), which points to the exact place for the current instruction.

● while (true) { Fetch current instruction from memory Increment PC Inspect current instruction and do what it says}

● This is the Fetch-Execute cycle.

Page 16: Introduction - UNB

Be a Human CPU

Memory Address

1000 right hand in

1001 right hand out

1002 right hand in

1003 shake it all about

1004 turn yourself around

1005 go back to address 1000

● “Hokey Pokey” program

● PC starts at 1000● Fetch and do “right

hand in”; PC ← 1001● Fetch and do “right

hand out”;PC ← 1002● ….

Page 17: Introduction - UNB

Control Flow● Normally, when you finish one instruction you advance to the (sequentially) next one.

● This is called straight line flow of control. PC just increments.

● But there are instructions like “go back to the instruction at address 1000” that disrupt this.

● Good thing, since that's how we can do IF and WHILE in a high-level language.

● Control flow is often disrupted conditionally, based on status flags that record what happened earlier (eg, did last addition give -ve result?)

Page 18: Introduction - UNB

More Realistic Instructions

● Instead of “right hand in”, a CPU instruction will be something simple like a request to take two integers stored locally in the CPU, add them, and store the result in the CPU

● Or “go to memory location 2000 and load the 8-bit integer there into the CPU”

● Or “go back to memory address 1000”, as in the Hokey Pokey program. A jump or branch instr.

● A compiler or a programmer needs a lot of simple instructions to do something more complicated.