程序代写代做代考 assembly Computer Systems Week 2

Computer Systems Week 2
Instructions, Assembly Language, and Machine Code
Slide #1 of 49

Lecture Objectives
To introduce the fundamental building blocks of a computer system and how programs are executed.
Slide #2 of 49

Lecture Outline
uHow Computers Execute Programs? uAnatomy of a Computer System uFetch / Execute cycle
uComputer’s View of Software
Slide #3 of 49

Some of the following slides are based on: Pearson Education Resources: Chapter 9 – Principles of Computer Operations
Before we start … What is a computer ?
Slide #4 of 49

A computer is a complex system (machine) that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming…
Slide #5 of 49

So…
How Computers Execute Programs?
Slide #6 of 49

Requirements of a Computing Device
uLoad the program from some external device/memory u– interface to the outside world
uProcess instructions in the correct order – mechanism to keep track of progress, local storage and decoding of instructions
uAccess pieces of data in accordance with the program’s instructions – local storage of data
uPerform computations – a calculation “engine” uTake decisions according to the results of the
computations – mechanism for control
uSend the results of the computations to some external device – interface to the outside world
Slide #7 of 49

Anatomy of a Computer System
All computers, regardless of their implementing technology, have five basic parts or subsystems:
1) Memory,
2) Control unit,
3) Arithmetic/logic unit (ALU), 4) Input unit, and
5) Output unit
Slide #8 of 49

1) Memory
Memory stores both the program while it is running and the data on which the program operates:
Properties of memory:
uDiscrete locations
u Memory is organized as a sequence of discrete locations
u In modern memory, each location is composed of 1 byte (8 bits)
u Addresses
u Every memory location has an address, whole numbers
starting at 0
u Values
u Memory locations record / store values
Slide #9 of 49

1) Memory
uFinite Capacity
u Memory locations have a finite capacity (limited size), u Data may not “fit” in the memory location
Address of location is displayed above the box and the contents of location is shown in the box
Blocks of four/eight bytes are used as a unit so often that they are called memory words
Slide #10 of 49

Random Access Memory (RAM)
u Computer memory is called Random Access Memory (RAM)
n“Random access” is out-of-date and simply means that the computer can refer to the memory locations in any order
u RAM is measured in megabytes (MB) or gigabytes (GB)
u Lots of memory is needed to handle the space required of programs and data
Slide #11 of 49

2) Control Unit
uThe control unit of a computer is where the Fetch/ Execute Cycle occurs
n Its circuitry fetches an instruction from memory and performs the other operations of the Fetch/Execute Cycle on it
n A typical machine instruction has the form ADD 4000, 2000, 2080
n Looks like those three numbers should be added together
u What it really means is that whatever numbers are stored in memory locations 2000 and 2080 be added together, and the result be stored in location 4000
Slide #12 of 49

Illustration of a Single Instruction
Slide #13 of 49

3) Arithmetic/Logic Unit (ALU)
u“Does the math”
uA circuit in the ALU can add/subtract two numbers
uThe circuit uses logic gates or simpler circuits that implement operations like AND and OR
uThere are also circuits for multiplying, for comparing two numbers, etc.
uThe ALU carries out each machine instruction with a separate circuit
Slide #14 of 49

4 & 5) Input / Output Units
uThese two components are the wires and circuits through which information moves into and out of a computer
uA computer without input or output is useless
Slide #15 of 49

The Peripherals
uPeripherals connect to the computer input/output (I/O) ports
uThey provide input or receiving its output uThey are not considered part of the computer:
nThey are only specialized gadgets that encode or decode information between the computer and the physical world.
nSome examples are Keyboard, Mouse, Monitor, USB, Hard Disks, Network Cards etc.
Slide #16 of 49

Anatomy of a Computer System
All computers, regardless of their implementing technology, have five basic parts or subsystems:
1) Memory,
2) Control unit,
3) Arithmetic/logic unit (ALU), 4) Input unit, and
5) Output unit
Slide #17 of 49

End of video one
Slide #18 of 49

How Computers Execute Programs?
Here is a simple computer program:
a = input(‘Enter a number’);
if a<1 exit(’Invalid input’); b=1; for(i=1;i<=a;i++) { b=b*i; } print (a,’! = ’,b); What is the program computing ? Slide #19 of 49 Executing Programmes A program is loaded into memory and address of first instruction is placed in PC (Program Counter) The following Fetch / Execute cycle is then followed: 1) Instruction Fetch (IF) 2) Instruction Decode (ID) 3) Data / Operand Fetch (DF/OF) 4) Instruction Execution (EX) 5) Result Return / Store (RR/ST) Slide #20 of 49 ADD 800, 428, 884 ADD the values found in memory locations 428 and 884 and store the result in location 800 Slide #21 of 49 Instruction Fetch (IF) uExecution begins by moving the instruction at the address given by the PC (PC 2200) from memory to the control unit uBits of instruction are placed into the decoder circuit of the Control Unit uOnce instruction is fetched, the PC can be readied for fetching the next instruction Slide #22 of 49 Instruction Decode (ID) uALU is set up for the operation uDecoder finds the memory address of the instruction's data (source operands) u Most instructions operate on two data values stored in memory (like ADD), so most instructions have addresses for two source operands u These addresses are passed to the circuit that fetches them from memory during the next step uDecoder finds the destination address for the Result Return step and places the address in the RR circuit Slide #23 of 49 Instruction Decode (ID) uDecoder determines what operation the ALU will perform (ADD), and sets up the ALU Slide #24 of 49 Data Fetch (DF) uThe data values to be operated on are retrieved from memory uBits at specified memory locations are copied into locations in the ALU circuitry uData values remain in memory (they are not destroyed) Slide #25 of 49 Instruction Execution (EX) uFor this ADD instruction, the addition circuit adds the two source operands together to produce their sum uSum is held in the ALU circuitry uThis is the actual computation Slide #26 of 49 Result Return (RR) uRR returns the result of EX to the memory location specified by the destination address. uOnce the result is stored, the cycle begins again Slide #27 of 49 Many Simple Operations uComputers “know” very few instructions uThe decoder hardware in the controller recognizes, and the ALU performs, only about 100 or so different instructions (with a lot of duplication) uEverything that computers do must be reduced to some combination of these primitive, hardwired instructions uADD is representative of the complexity of computer instructions...some are slightly simpler, some slightly more complex. uComputers achieve success at what they can do with speed i.e. millions of instructions per second (Clock Speed in MHz or even GHz) Slide #28 of 49 Computer’s View of Software uA computer “sees” software as a long sequence of 4- byte groups of bits (0's and 1's) This binary object file can be hundreds of thousands to millions of words long uOnce installed, the computer runs the software by: u copying the binary instructions into the RAM u interpreting them using the Fetch/Execute Cycle. uIt does whatever the instructions tell it to do! Slide #29 of 49 Summary uAll computers, regardless of their implementing technology, have five basic parts or subsystems uThe memory, a very long sequence of bytes, each with an address, stores the program and data while the program is running. uThe repeating process fetches each instruction (indicated by the PC), decodes the operation, retrieves the data, performs the operation, and stores the result back into the memory. uThe ALU does the actual computing. uThe input and output units are the interfaces for the peripheral devices connected to the computer. Slide #30 of 49