You are on page 1of 29

CST1500

Computer Systems Architecture and


Operating Systems

Lecture 3 – Computer Architecture 1 and Assembly


language

1
CPU and Memory
• Every instruction executed by the CPU requires
memory access

• Primary memory holds program instructions and data

• Secondary storage is used for long term storage


- Data is moved from secondary storage to primary memory for CPU execution

6-2
CPU: Major Components
• ALU (arithmetic logic unit)
- Performs calculations and comparisons
- Uses the accumulator which is a register in which intermediate
arithmetic and logic results are stored.

• CU (control unit)
- Performs fetch/execute cycle
• Accesses program instructions and issues commands to the ALU
• Moves data to and from CPU registers and other hardware
components
- Subcomponents:
• Memory management unit: supervises fetching instructions and
data from memory
• I/O Interface: sometimes combined with memory management unit
as Bus Interface Unit, manages input-output transfers

System Block Diagram

6-3
Memory (Write)
Data
A demultiplexer of 2n D1 D0
outputs has n select lines, Address
which are used to select
which output line to send A1 A0
the input. A demultiplexer
is also called a data D Q D Q
distributor. >C >C
Y3

Demux D Q D Q
>C >C
Y2

Write D Q D Q
Enable >C >C
Y1

D Q D Q
>C >C
Y0
4
What is a Flip flop?
A flip flop is an electronic circuit with two stable states that
can be used to store binary data. The stored data can be
changed by applying varying inputs. Flip-flops and latches are
fundamental building blocks of digital electronics systems
used in computers, communications, and many other types of
systems. Both are used as data storage elements.
Tristate Buffer Memory (Read)
Data
Q1Q0
Address
A1 A0

D Q D Q
>C >C
Y3

Demux D Q D Q
>C >C
Y2

Output Enable D Q D Q
>C >C
Y1

D Q D Q
>C >C
Y0

6
Tri- state buffer
A tri-state buffer has two inputs: a data input x and a
control input c. The control input acts like a valve. When
the control input is active, the output is the input. That is,
it behaves just like a normal buffer. The "valve" is open.

When the control input is not active, the output is "Z".


The "valve" is open, and no electrical current flows
through. Thus, even if x is 0 or 1, that value does not flow
through.
Memory (Read / Write)
• The wide arrows represent several wires
– We’re going to call these arrows buses

• The computer has:


– A data bus
– An address bus
• Which memory cells to use
– A control bus
• Output enable and write enable + others

• Buses Used to communicate between parts of the computer


• 2 levels of busses: Internal to chip and External between chips

8
Memory
• Flip flops are grouped into bytes (or larger)
– Each byte has a unique address
– To write
• Present the address and the data
• Tell chip to write
– To read
• Present the address
• Tell the chip to read
• Look at the data

• Memory size is dependant on address bus “width”


– 2n bytes for n-lines on the address bus
• 28=256B, 216=64KB, 232=4GB, 264=16EB
• An exabyte (EB) is a large unit of computer data storage 9
Address bus
A collection of wires connecting the CPU with main
memory that is used to identify particular locations
(addresses) in main memory.

The width of the address bus determines the amount of


memory a system can address.

For example, a system with a 32-bit address bus can


address 232 (4,294,967,296) memory locations. If each
memory location holds one byte, the addressable
memory space is 4 GB.
Arithmetic Logic Unit (ALU)
• Performs arithmetic operations
– addition, subtraction, etc.
• Performs logical operations
– AND, OR, SHIFT, etc.
• Subunits
– Adder (and subtraction)
– Logical tests (if, >0, <0, =0, <=0, etc.)
– Logical operations (AND, OR, XOR, etc.)
– Shifting
– Comparison (done by subtraction)
– Multiplication and division

11
Control Unit
• Coordinates the operation of the computer
• Generates control signals
– Connect registers to the bus
– Control the function of the ALU
– Provides timing signals to the system

12
Registers
• Registers are memory cells with names
– Hold data, instructions, or other items
– Various sizes (typically: 8, 16, 32, or 64 bits)
– Program counter (PC) and memory address registers must be
same width as address bus
– Registers which hold data must be same width as memory
words
• The accumulator is a special register
– Source of one of the operands
– Destination of the result

• The Status Flags is a special register


– Individual bits store information about results of operations
• Result is zero, Carry, Overflow, Result is negative.

13
Computer!

• Instructions are bit patterns


• Can be split into a number of fields
– One field specifies the operation to be executed
(opcode)
– Other fields specify the address in memory (or registers) of
operands and where to place the result
( operand)

INSTRUCTION = OPCODE + OPERAND

14
Stored Program Computer
Address (A)

Output Enable Data In (D)


Write Enable Memory

Data Out (Q) Data Out (Q)


PC
CPU
Data In (D) IR

Control Bus Command (X)


Instruction
X1 X0 A1 A0

15
Von Neumann Architecture
• Three key concepts:
– Data and instructions are stored in a single read-write
memory
– Contents of memory are addressable by location, without
regard to the type of data contained
– Execution occurs in a sequential fashion, unless explicitly
altered, from one instruction to the next

16
High vs. Low Level Language

18
Machine Code
• These numbers tell the computer what to do
• They tell the CPU to
– Assign values to registers
– Load registers from memory
– Add numbers to registers
– Store registers in memory
– And so on

• However, it is very difficult to program using numbers

• Programs are slow to enter


– Each individual bit must be chosen by the
programmer
• The programs are not human readable

• Programs are long and tiresome to write


18
• Debugging is extremely difficult
Assembly Language
• If we give mnemonics (names) to the numbers
– It is easier to remember them
– We can program symbolically

• We call this assembly language programming

• Each different CPU has its own mnemonics and its own
assembly language (its own machine language)

- Assembly language programs are not portable across CPU architectures

19
Assembly
Language
Example

20
Assembly Language
• We can give names (labels) to memory locations
– In this case PRINT is the name of the memory location where the
routine is stored. DONE is the name of the memory location where
the return statement is stored
• There is a direct correspondence between mnemonic
assembly language and machine code.
– An assembler translates from assembly to machine code, a
disassembler translates from machine code to assembly language

21
Multiple Data Instructions
• Perform a single operation( add) on multiple pieces of
data simultaneously
- SIMD: Single Instruction, Multiple Data
- Commonly used in multimedia, vector and array processing
applications

22
Instruction Elements
OPCODE: task

Source OPERAND(s) Addresses


Result OPERAND

- Location of data (register, memory)

Source Result
OPCODE
OPERAND OPERAND

23
Opcodes means "operation codes". They tell the circuitry
(in this case, the microprocessor) which operation to
perform e.g. addition, subtraction.

Operands are the data contents on which the operation is


to be performed.

All instructions consist of opcodes and operands.

Opcode is an instruction that tells processor what to do


with the variable or data written besides it.
Operand is a variable that stores data(and data can be a
memory address or any data that we want to process).
Instruction Format

Machine-specific template that specifies


- Length of the op code
- Number of operands
- Length of operands

Simple
32-bit Instruction Format

25
Recap!
An instruction format defines the different component of an instruction. The main
components of an instruction are opcode (which instruction to be executed) and
operands (data on which instruction to be executed).

Opcode: The operation code (opcode) represents action that the processor must
execute. It tells the processor what basic operations to perform.

Operands: The operand code defines the parameters of the action and depends on
the operation. It specifies the locations of the data or the operand on which the
operation is to be performed. It can be data or a memory address.

Instruction Format

E.g. ADD B // Add the contents of register B to the content of


the accumulator.
MOV C, A // Copy the content of accumulator in the
register C.
Instructions
• Instruction
- Direction given to a computer
- Causes electrical or optical signals to be sent through specific
circuits for processing

• Instruction set
The instruction set provides commands to the
processor, to tell it what it needs to do.
- Design defines functions performed by the processor
- Differentiates computer architecture by the
• Number of instructions
• Complexity of operations performed by individual instructions
• Data types supported
• Format (layout, fixed vs. variable length)
• Use of registers
• Addressing (size, modes)
27
Instruction Set
• The set of all instructions for the particular CPU is called the
instruction set
– It is determined by the designers
• Instructions consist of one or more fields
– The mnemonic opcodes that indicate the operations to be
performed.
E.g. Increment the X register (INX)
– And (optionally) parameters called operands
E.g. Goto (JMP PRINT)
• Instructions are of different lengths

28
Instruction Format Examples

28

You might also like