CS501 Highlight Handout
CS501 Highlight Handout
CS501
Table of Contents
Appendix A.............................................................................................................. 4
FALSIM............................................................................................................... 4
Lecture No. 1 .................................................................................................................... 19
Introduction................................................................................................................... 19
Lecture No. 2 .................................................................................................................... 32
Instruction Set Architecture ......................................................................................... 32
Lecture No. 3 .................................................................................................................... 44
Introduction to SRC Processor ..................................................................................... 44
Lecture No. 4 .................................................................................................................... 50
ISA and Instruction Formats......................................................................................... 50
Lecture No. 5 .................................................................................................................... 64
Description of SRC in RTL .......................................................................................... 64
Lecture No. 6 .................................................................................................................... 73
RTL Using Digital Logic Circuits ................................................................................ 73
Lecture No. 7 .................................................................................................................... 87
Design Process for ISA of FALCONA ........................................................................ 87
Lecture No. 8 .................................................................................................................... 91
ISA of the FALCONA.................................................................................................. 91
Lecture No. 9 ...................................................................................................................104
Description of FALCONA and EAGLE using RTL ........................................104
Lecture No. 10 .................................................................................................................124
The FALCONE and ISA Comparison.........................................................................124
Lecture No. 11 .................................................................................................................148
CISC and RISC ...........................................................................................................148
Lecture No. 12 .................................................................................................................149
CPU Design .................................................................................................................149
Lecture No. 13 ................................................................................................................ 156
Structural RTL Description of the FALCONA .......................................................... 156
Lecture No. 14 .................................................................................................................162
External FALCONA CPU ...........................................................................................162
Lecture No. 15 ..................................................................................................................171
Logic Design and Control Signals Generation in SRC......................................171
Lecture No. 16 ..................................................................................................................183
Control Unit Design......................................................................................................183
Lecture No. 17 ..................................................................................................................193
Machine Reset and Machine Exceptions .....................................................................193
Lecture No. 18 ..................................................................................................................199
Pipelining .....................................................................................................................199
Lecture 19 .........................................................................................................................206
Pipelined SRC...............................................................................................................206
Lecture No. 20 ..................................................................................................................212
Hazards in Pipelining....................................................................................................212
Lecture 21 ........................................................................................................................ 218
Instruction Level Parallelism .......................................................................................218
Lecture No. 22 ................................................................................................................ .222
Appendix A
Reading Material
Handouts
Summary
1. Introduction to FALSIM
2. Preparing source files for FALSIM
3. Using FALSIM
4. FALCONA assembly language techniques
FALSIM
1. Introduction to FALSIM:
FALCON(A Assembler:
The FALCONA Assembler has two main modules, the 1stpass and the
2ndpass. The 1stpass module takes an assembly file with a (.asmfa)
extension and processes the file contents. It then creates a Symbol Table
which corresponds to the storage of all program variables, labels and data
values in a data structure at the implementation level. If the 1stpass
completes successfully a Symbol Table is produced as an output, which is
used by the 2ndpass module. Failures of the 1stpass are handled by the
assembler using its exception handling mechanism.
Last Modified: 12Jan11 Page 4
Advanced Computer ArchitectureCS501
The 2ndpass module sequentially processes the .asmfa file to interpret the
instruction opcodes, register opcodes and constants using the symbol table.
It then produces a list file with a .lstfa extension independent of successful
or failed pass. If the pass is successful a binary file with a .binfa extension is
produced which contains the machine code for the program in the assembly
file.
FALCON(A Simulator:
FALSIM Features:
The FALCONA Assembler provides its user with the following features:
Select Assembly File: Labeled as 1 in Figure 1, this feature enables the
user to choose a FALCONA assembly file and open it for processing by the
assembler.
List File: Labeled as 3, in Figure 1, the List File feature gives a detailed
insight of the FALCONA listing file, which is produced as a result of the
execution of the 1st and 2ndpass. It shows the Program Counter value in
hexadecimal and decimal formats along with the machine code generated for
every line of assembly code. These values are printed when the 2ndpass is
completed.
Last Modified: 12Jan11 Page 5
Advanced Computer ArchitectureCS501
Error Log: The Error Log is labeled as 4 in Figure 1. It informs the user
about the errors and their respective details, which occurs in any of the
passes of the assembler.
Search: Search is labeled as 5 in Figure 1 and helps the user to search for
a certain input with the options of searching with match whole and
match any parts of the string. The search also has the option of checking
with/without considering case(sensitivity. It searches the List File area
and highlights the search results using the yellow color. It also indicates the
total number of matches found.
Load Binary File: The button labeled as 11 in Figure 6, allows the user to
choose and open a FALCONA binary file with a (.binfa) extension. When a
file is being loaded into the simulator all the register, constants (if any) and
memory values are set.
Registers: The area labeled as 12 in Figure 6. enables, the user to see
values present in different registers before during and after execution.
Instruction: This area is labeled as 13 in Figure 6 and contains the value of
PC, address of an instruction, its representation in Assembly, the Register
Transfer Language, the opcode and the instruction type.
I/O Ports: I/O ports are labeled as 14 in Figure 6. These ports are available
for the user to enter input operation values and visualize output operation
values whenever an I/O operation takes place in the program. The input
value for an input operation is given by the user before an instruction
executes. The output values are visible in the I/O port area once the
instruction has successfully executed.
Processor’s State: Labeled as 16 in Figure 6, this area shows the current
Last Modified: 12Jan11 Page 6
Advanced Computer ArchitectureCS501
values of the Instruction register and the Program Counter while the program
executes.
Search: The search option for the FALCONA simulator is labeled as 17
in Figure 6. This feature is similar to the way the search feature of the
FALCONA Assembler works. It offers to highlight the search string which
goes as an input, with the All and Part option. The results of the search
are highlighted in the color yellow. It also indicates the total number of
matches.
Single Step: Single Step lets the user execute the program, one instruction
at a time. The next instruction is not executed unless the user does a single
step again. By default, the instruction to be executed will be the one next in
the sequence. It changes if the user specifies a different PC value using the
Change PC option (explained below).
Change PC: This option lets the user change the value of PC
(Program Counter). By changing the PC the user can execute the
instruction to which the specified PC points.
Change Register: Using the Change Register feature, the user can
change the value present in a particular register.
Change Memory Word: This feature enables the user to change values
present at a particular memory location.
Change I/O: Allows the user to give an I/O port value if the
instruction to be executed requires an I/O operation. Giving in the
input in any one of the I/O ports areas before instruction execution,
indicates that a particular I/O operation will be a part of the program
and it will have an input from some source. The value given by the
user indicates the input type and source.
�� The source file should contain ASCII text only. Each line should be
terminated by a carriage return. The extension .asmfa should be used
with each file name. After assembly, a list file with the original
filename and an extension .lstfa, and a binary file with an extension
.binfa will be generated by FALSIM.
�� Comments are indicated by a semicolon (;) and can be placed anywhere
in the source file. The FALSIM assembler ignores any text after the
semicolon.
�� Names in the source file can be of one of the following types:
�� Variables: These are defined using the .equ directive. A value must
also be assigned to variables when they are defined.
�� Addresses in the data and pointer area within the memory: These
can be defined using the .dw or the .sw directive. The difference
between these two directives is that when .dw is used, it is not
possible to store any value in the memory. The integer after .dw
identifies the number of memory words to be reserved starting at the
current address. (The directive .db can be used to reserve bytes in
memory.) Using the .sw directive, it is possible to store a constant or
the value of a name in the memory. It is also possible to use pointers
with this directive to specify addresses larger than 127. Data tables
and jump tables can also be set up in the memory using this directive.
However, the main program must start at address 126 or less , otherwise 2
3. Using FALSIM:
1 Any address between 4 and 14 can be used in place of the displacement field in load or
store instructions. Recall that the displacement field is just 5 bits in the instruction word.
2 This restriction is because of the face that the immediate operand in the movi
instruction must fit an 8bit field in the instruction word.
Last Modified: 12Jan11 Page 9
Advanced Computer ArchitectureCS501
�� Select one or both assembler options shown on the top right corner of
the assembler window labeled as 2. If no option is selected, the
symbol table and the instruction table will not be generated in the list
(.lstfa) file.
�� Click on the select assembly file button labeled as 1. This will open
the dialog box as shown in the Figure 2.
�� Select the path and file containing the source program that is to be
assembled.
�� Click on the open button. FALSIM will assemble the program and
generate two files with the same filename, but with different
extensions. A list file will be generated with an extension .lstfa, and a
binary (executable) file will be generated with an extension .binfa.
FALSIM will also display the list file and any error messages in two
separate panes, as shown in Figure 3.
�� This will open the simulation window with the executable program
loaded in it as shown in Figure 8. The details of the different panes in
this window were given in section 1 earlier. Notice that the first
instruction at address 0 is ready for execution. All registers are
initialized to 0. The memory contains the address of the ISR (i.e., 64h
which is 100 decimal) at location 2 and the address of the printer
Last Modified: 12Jan11 Page 10
Advanced Computer ArchitectureCS501
�� Click single step button labeled as 19. FALSIM will execute the
jump [main] instruction at address 0 and the PC will change to 20h
(32 decimal), which is the address of the first instruction in the main
program (i.e., the value of main).
�� Click again on the single step button. Note that when the ret r4
instruction executes, the value in r4 (i.e., 28h) is brought into the PC.
The blue highlight bar is placed on the next instruction after the call
Last Modified: 12Jan11 Page 11
Advanced Computer ArchitectureCS501
�� Double click on the value of the PC labeled as 20. This will open a
dialog box shown below. Enter a
value of the PC (i.e., 26h)
corresponding to the call r4, r6
instruction, so that it can be
executed again. A list of possible
PC values can also be pulled down
using, and 0026h can be selected
from there as well.
�� Change memory location 000A to a 0, and then single step the first
instruction in the printer driver. This will bring a 0 in r1, so that when
the next jnz r1, [message] instruction is executed, the branch will not
be taken and control will transfer to the next instruction after this
instruction. This is mivi r1, 1 at address 0036h.
�� Continue single stepping till the int instruction and note the changes
in different panes of the simulation window at each step.
�� When the int instruction executes, the PC changes to 64h, which is the
address of the first instruction in the ISR. Clicking single step executes
this instruction, and loads the address of temp (i.e., 0010h) which is a
temporary memory area for storing the environment. The five store
instructions in the ISR save the CPU environment (working registers)
before the ISR change them.
�� Single step through the ISR while noting the effects on various registers,
memory locations, and I/O ports till the iret instruction executes. This will
pass control back to the printer driver by changing the PC to the address of
the jump [finish] instruction, which is the next instruction after the int
instruction.
�� Double click on the value of the PC. Change it to point to the int
instruction and click single step to execute it again. Continue to single step
till the in r1, statusp instruction is ready for execution.
�� Change the I/O port at address 3Ah (which represents the status port at
address 58) to 80 and then single step the in r1, statusp instruction. The
value in r1 should be 0080.
�� Single step twice and notice that control is transferred to the movi r7,
FFFF instruction, which stores an error code of 1 in r1.
3
Figure 1
3The instruction was originally movi r7, (1. Since it was converted to machine language
by the assembler, and then reverse assembled by the simulator, it became movi r7,
FFFF. This is because the machine code stores the number in 16bits after sign
extension. The result will be the same in both cases.
Last Modified: 12Jan11 Page 13
Advanced Computer ArchitectureCS501
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
�� Large values (16bit values) can also be stored in registers using the mul
instruction combined with the addi instruction. The following
instructions bring a 201 in register r1.
movi r2, 10
movi r3, 20
mul r1, r2, r3 ; r1 contains 200 after this instruction
addi r1, r1, 1 ; r1 now contains 201
�� Moving from one register to another can be done by using the instruction
addi r2, r1, 0.
�� Bit setting and clearing can be done using the logical (and, or, not, etc)
instructions.
�� Using shift instructions (shiftl, asr, etc.) is faster that mul and div, if the
multiplier or divisor is a power of 2.
Lecture No. 1
Introduction
Reading Material
Summary
1) Distinction between computer architecture, organization and design
2) Levels of abstraction in digital design
3) Introduction to the course topics
4) Perspectives of different people about computers
5) General operation of a stored program digital computer
6) The FetchExecute process
7) Concept of an ISA(Instruction Set Architecture)
Introduction
This course is about Computer Architecture. We start by explaining a few key terms.
The General Purpose Digital Computer
How can we define a computer? There are several kinds of devices that can be termed
computers: from desktop machines to the microcontrollers used in appliances such as a
microwave oven, from the Abacus to the cluster of tiny chips used in parallel processors,
etc. For the purpose of this course, we will use the following definition of a computer:
“an electronic device, operating
under the control of instructions
stored in its own memory unit, that
can accept data (input), process data
arithmetically and logically, produce
output from the processing, and store
the results for future use.” [1]
Thus, when we use the term computer,
we actually mean a digital computer.
There are many digital computers,
which have dedicated purposes, for
example, a computer used in an
automobile that controls the spark
timing for the engine. This means that when we use the term computer, we actually mean
a generalpurpose digital computer that can perform a variety of arithmetic and logic
tasks.
The Computer as a System
Now we examine the notion of a system, and the place of digital computers in the general
universal set of systems. A system is a collection of elements, or components, working
together on one or more inputs to produce one or more desired outputs.
There are many types of systems in the world. Examples include:
Chemical systems
Optical systems
Biological systems
Electrical systems
Mechanical systems, etc.
These are all subsets of the general universal set of systems. One particular subset of
interest is an electrical system. In case of electrical systems, the inputs as well as the
outputs are electrical quantities, namely voltage and current. Digital systems are a
subset of electrical systems. The inputs and outputs are digital quantities in this case.
Generalpurpose digital computers are a subset of digital systems. We will focus on
generalpurpose digital computers in this course.
Essential Elements of a General Purpose Digital Computer
The figure shows the block diagram of
a modern generalpurpose digital
computer.
We observe from the diagram that a
generalpurpose computer has three
main components: a memory
subsystem, an input/ output subsystem,
and a central processing unit.
Programs are stored in the memory,
the execution of the program
instructions takes place in the CPU,
and the communication with the
external world is achieved through the
I/O subsystem (including the
peripherals).
Architecture
Now that we understand the term computer in our context, let us focus on the term
architecture. The word architecture, as defined in standard dictionaries, is “the art or
science of building”, or “a method or style of building”. [2]
Computer Architecture
This term was first used in 1964 by Amdahl, Blaauw, and Brooks at IBM [3]. They
defined it as
“the structure of a computer that a machine language programmer must understand to
write a correct (time independent) program for that machine.”
By architecture, they meant the programmer visible portion of the instruction set. Thus, a
family of machines of the same architecture should be able to run the same software
(instructions). This concept is now so common that it is taken for granted. The x86
architecture is a wellknown example.
The study of computer architecture includes
�� a study of the structure of a computer
�� a study of the instruction set of a computer
Last Modified: 12Jan11 Page 20
Advanced Computer ArchitectureCS501
of that particular level carry out the design activity for each level. These levels of
abstraction of a digital computers design are explained below.
Digital Design: Levels of Abstraction
ProcessorMemorySwitch level (PMS level)
The highest is the processormemoryswitch level. This is the level at which an architect
views the system. It is simply a description of the system components and their
interconnections. The components are specified in the form of a block diagram.
Instruction Set Level
The next level is instruction set level. It defines the function of each instruction. The
emphasis is on the behavior of the system rather than the hardware structure of the
system.
Register Transfer Level
Next to the ISA (instruction set architecture) level is the register transfer level. Hardware
structure is visible at this level. In addition to registers, the basic elements at this level are
multiplexers, decoders, buses, buffers etc. buffer is amount of data buses
The above three levels relate to “system design”.
Logic Design Level
The logic design level is also called the gate level. The basic elements at this level are
gates and flipflops. The behavior is less visible, while the hardware structure
predominates.
The above level relates to logic design.
Circuit Level
The key elements at this level are resistors, transistors, capacitors, diodes etc.
Mask Level
The lowest level is mask level dealing with the silicon structures and their layout that
implement the system as an integrated circuit.
The above two levels relate to “circuit design”.
The focus of this course will be the register transfer level and the instruction set level,
although we will also deal with the PMS level and the Logic Design Level.
Objectives of the course
This course will provide the students with an understanding of the various levels of
studying computer architecture, with emphasis on instruction set level and register
transfer level. They will be able to use basic combinational and sequential building
blocks to design larger structures like ALUs (Arithmetic Logic Units), memory
subsystems, I/O subsystems etc. It will help them understand the various approaches used
to design computer CPUs (Central Processing Units) of the RISC (Reduced Instruction
Set Computers) and the CISC (Complex Instruction Set Computers) type, as well as the
Memory subsystems
Course Outline
Introduction:
��Distinction between Computer Architecture, Organization and design
��Levels of abstraction in digital design
��Introduction to the course topics
Brief review of computer organization:
�� Perspectives of different people about computers
�� General operation of a stored program digital computer
�� The Fetch Execute process
�� Concept of an ISA
Foundations of Computer Architecture:
��A taxonomy of computers and their instructions
��Instruction set features
��Addressing Modes
��RISC and CISC architectures
��Measures of performance
An example processor: The SRC:
��Introduction to the ISA and instruction formats
��Coding examples and Hand assembly
��Using Behavioral RTL to describe the SRC
��Implementing Register Transfers using Digital Logic Circuits
ISA: Design and Development
��Outline of the thinking process for ISA design
��Introduction to the ISA of the FALCON A
��Solved examples for FALCONA
��Learning Aids for the FALCONA
Other example processors:
�� FALCONE
�� EAGLE and Modified EAGLE
�� Comparison of the four ISAs
CPU Design: imp
�� The Design Process
�� A UniBus implementation for the SRC
�� Structural RTL for the SRC instructions
�� Logic Design for the 1Bus SRC
�� The Control Unit
�� The 2and 3Bus Processor Designs
�� The Machine Reset
�� Machine Exceptions
Term Exam I
Advanced topics in processor design:
imp
�� Pipelining
�� InstructionLevel Parallelism
�� Microprogramming
Input(output (I/O):
�� I/O interface design
�� Programmed I/O
�� Interrupt driven I/O
�� Direct memory access (DMA)
Term Exam II
Arithmetic Logic Shift Unit (ALSU) implementation:
�� Addition, subtraction, multiplication & division for integer unit
�� Floating point unit
Memory subsystems:
�� Memory organization and design
�� Memory hierarchy
�� Cache memories
�� Virtual memory
References
[1] Shelly G.B., Cashman T.J., Waggoner G.A., Waggoner W.C., Complete Computer
Concepts: Microcomputer and Applications. Ferncroft Village Danvers, Massachusetts:
Boyd & Fraser, 1992.
[2] MerriamWebster Online; The Language Centre, May 12, 2003 ( http://www.m
w.com/home.htm).
[3] Patterson, D.A. and Hennessy, J.L., Computer Architecture A Quantitative
Approach, 2nd ed., San Francisco, CA: Morgan Kauffman Publishers Inc., 1996.
[4] Heuring V.P. and Jordan H.F., Computer Systems Design and Architecture. Melano
Park, CA: Addison Wesley, 1997.
A brief review of Computer Organization
Perceptions of Different People about Computers
There are various perspectives that a computer can take depending on the person viewing
it. For example, the way a child perceives a computer is quite different from how a
computer programmer or a designer views it. There are a number of perceptions of the
computer, however, for the purpose of understanding the machine, generally the
following four views are considered.
The Users View
A user is the person for whom the machine is designed, and who employs it to perform
some useful work through application software. This useful work may be composing
some reports in word processing software, maintaining credit history in a spreadsheet, or
even developing some application software using highlevel languages such as C or Java.
The list of useful work is not allinclusive. Children playing games on a computer may
argue that playing games is also useful work, maybe more so than preparing an internal
office memo.
At the users level, one is only concerned with things like speed of the computer, the
storage capacity available, and the behavior of the peripheral devices. Besides
performance, the user is not involved in the implementation details of the computer, as
the internal structure of the machine is made obscure by the operating system interface.
form a single module that can be loaded and executed. The modularity of
programs, that the linking step in assembly language makes possible, provides the
same convenience as it does in higherlevel languages; namely abstraction and
separation of concerns. Once the functionality of a module has been verified for
correctness, it can be reused in any number of other modules. The programmer
can focus on other parts of the program. This is the socalled modular approach,
or the topdown approach.
�� The debugger or monitor:
Assembly language programs are very lengthy and nonintuitive, hence quite
tedious and errorprone. There is also the disadvantage of the absence of an
operating system to handle runtime errors that can often crash a system, as
opposed to the higherlevel language programming, where control is smoothly
returned to the operating system. In addition to runtime errors (such as a divide
byzero error), there are syntax or logical errors.
A debugger, also called a monitor, is a computer program used to aid in
detecting these errors in a program. Commonly, debuggers provide functionality
such as
o The display and altering of the contents of memory, CPU registers and flags
o Disassembly of machine code (translating the machine code back to assembly
language)
Last Modified: 12Jan11 Page 26
Advanced Computer ArchitectureCS501
o Single stepping and breakpoints that allow the examination of the status of the
program and registers at desired points during execution.
While syntax errors and many logical errors can be detected by using debuggers,
the best debugger in the world can catch not every logical error.
�� The development system
The development system is a complete set of (hardware and software) tools
available to the system developer. It includes
o Assemblers
o Linkers and loaders
o Debuggers
o Compilers
o Emulators
o Hardwarelevel debuggers
o Logic analyzers, etc.
Difference between Higher(Level Languages and Assembly Language
Higherlevel languages are generally used to develop application software. These high
level programs are then converted to assembly language programs using compilers. So it
is the task of a compiler writer to determine the mapping between the highlevel
language constructs and assembly language constructs. Generally, there is a manyto
many mapping between highlevel languages and assembly language constructs. This
means that a given HLL construct can generally be represented by many different
equivalent assembly language constructs. Alternately, a given assembly language
construct can be represented by many different equivalent HLL constructs.
Highlevel languages provide various primitive data types, such as integer, Boolean and a
string, that a programmer can use. Type checking provides for the verification of proper
usage of these data types. It allows the compiler to determine memory requirements for
variables and helping in the detection of bad programming practices.
On the other hand, there is generally no provision for type checking at the machine level,
and hence, no provision for type checking in assembly language. The machine only sees
strings of bits. Instructions interpret the strings as a type, and it is usually limited to
signed or unsigned integers and floating point numbers. A given 32bit word might be an
instruction, an integer, a floatingpoint number, or 4 ASCII characters. It is the task of the
compiler writer to determine how highlevel language data types will be implemented
using the data types available at the machine level, and how type checking will be
implemented.
The Stored Program Concept
This concept is fundamental to all the generalpurpose computers today. It states that the
program is stored with data in computers memory, and the computer is able to
manipulate it as data. For example, the computer can load the program from disk, move it
around in memory, and store it back to the disk.
Even though all computers have unique machine language instruction sets, the stored
program concept and the existence of a program counter is common to all machines.
The sequence of instructions to perform some useful task is called a program. All of the
digital computers (the general purpose machine defined above) are able to store these
sequences of instructions as stored programs. Relevant data is also stored on the
computers secondary memory. These stored programs are treated as data and the
computer is able to manipulate them, for example, these can be loaded into the memory
for execution and then saved back onto the storage. IP contains the address of next instruction
General Operation of a Stored Program Computer to be executed IP IR is same
The machine language programs are brought into the memory and then executed
instruction by instruction. Unless a branch instruction is encountered, the program is
executed in sequence. The instruction that is to be executed is fetched from the memory
and temporarily stored in a CPU register, called the instruction register (IR). The
instruction register holds the instruction while it is decoded and executed by the central
processing unit (CPU) of the computer. However, before loading an instruction into the
instruction register for execution, the computer needs to know which instruction to load.
The program counter (PC), also called the instruction pointer in some texts, is the register
that holds the address of the next instruction in memory that is to be executed.
When the execution of an instruction is completed, the contents of the program counter
(which is the address of the next instruction) are placed on the address bus. The memory
places the instruction on the corresponding address on the data bus. The CPU puts this
instruction onto the IR (instruction register) to decode and execute. While this
instruction is decoded, its length in bytes is determined, and the PC (program counter)
is incremented by the length, so that the PC will point to the next instruction in the
memory. Note that the length of the instruction is not determined in the case of RISC
machines, as the instruction length is fixed in these architectures, and so the program
counter is always incremented by a fixed number. In case of branch instructions, the
contents of the PC are replaced by the address of the next instruction contained in the
present branch instruction, and the current status of the processor is stored in a register
called the Processor Status Word (PSW). Another name for the PSW is the flag register.
It contains the status bits, and control bits corresponding to the state of the processor.
Examples of status bits include the sign bit, overflow bit, etc. Examples of control bits
include interrupt enable flag, etc. When the execution of this instruction is completed, the
contents of the program counter are placed on the address bus, and the entire cycle is
repeated. This entire process of reading memory, incrementing the PC, and decoding the
instruction is known as the Fetch and Execute principle of the stored program computer.
This is actually an oversimplified situation. In case of the advanced processors of this
age, a lot more is going on than just the simple fetch and execute operation, such as
pipelining etc. The details of some of these more involved techniques will be studied later
on during the course.
The Concept of Instruction Set Architecture (ISA)
Now that we have an understanding of some of the relevant key terms, we revert to the
assembly language programmers perception of the computer. The programmers view is
limited to the set of all the assembly instructions or commands that can the particular
computer at hand execute understood/, in addition to the resources that these instructions
may help manage. These resources include the memory space and the entire programmer
accessible registers. Note that we use the term memory space instead of memory,
because not all the memory space has to be filled with memory chips for a particular
implementation, but it is still a resource available to the programmer.
This set of instructions or operations and the resources together form the instruction set
architecture (ISA). It is the ISA, which serves as an interface between the program and
the functional units of a computer, i.e., through which, the computers resources, are
accessed and controlled.
Similarly, the implementation domains used for gate, board and module interconnections
are
�� Polysilicon lines in ICs
�� Conductive traces on a printed
circuit board
�� Electrical cable
�� Optical fiber, etc.
At the lower levels of logic design, the
designer is concerned mainly with the
functional details represented in a
symbolic form. The implementation
details are not considered at these
lower levels. They only become an
issue at higher levels of logic design.
An example of a twotoone
multiplexer in various implementation
domains will illustrate this point.
Figure (a) is the generic logic gate
(abstract domain) representation of a
2to1 multiplexer.
Figure (b) shows the 2to1
multiplexer logic gate implementation
in the domain of TTL (VLSI on Silicon) logic using part number 257, with
interconnections in the domain of printed circuit
board traces.
Figure (c) is the implementation of the 2to1
multiplexer with a fiber optic directional coupler
switch, which has an interconnection domain of
IO
optical fiber.
Classical logic design versus computer logic
design I1
We have already studied the sequential circuit
design concepts in the course on Digital Logic Design, and thus are familiar with the
techniques used. However, these traditional techniques for a finite state machine are not
very practical when it comes to the design of a computer, in spite of the fact that a
computer is a finite state machine. The reason is that employing these techniques is much
too complex as the computer can assume hundreds of states.
Sequential Logic Circuit Design
When designing a sequential logic circuit, the problem is first coded in the form of a state
diagram. The redundant states may be eliminated, and then the state diagram is translated
into the next state table. The minimum number of flipflops needed to implement the
design is calculated by making state assignments in terms of the flipflop states. A
transition table is made using the state assignments and the next state table. The flip
flop control characteristics are used to complete a set of excitation tables. The
excitation equations are determined through minimization. The logic circuit can then be
drawn to implement the design. A detailed discussion of these steps can be found in most
books on Logic Design.
Last Modified: 12Jan11 Page 30
Advanced Computer ArchitectureCS501
PC
(a) Program Counter: Programmers view
Figure (b) illustrates the logic designers view of a 32bit program counter, implemented
as an array of 32 D flipflops. It shows the contents of the program counter being gated
out on A bus (the address bus) by applying a control signal PCout. The contents of the
B bus (also the address bus), can be stored in the program counter by asserting the
signal PCin on the leading edge of the clock signal CK, thus storing the address of the
next instruction in the program counter.
32 32
A Bus Q B Bus
D
PC
PCout
<
CK PCin
Lecture No. 2
Instruction Set Architecture
Reading Material
Summary
1) A taxonomy of computers and their instructions
2) Instruction set features
3) Addressing modes
4) RISC and CISC architectures
as well as the result of the operation. However, now that the memory is relatively
inexpensive, these are not considered very useful, and their use is severely limited for the
computation of expressions with many operands.
confused with opcodes. Opcodes are simply bitpatterns in the machine language format
of an instruction.
Place to find source operands
An instruction needs to specify the place from where the source operands will be
retrieved and used. Possible locations of the source operands are CPU registers, memory
cells and I/O locations. The source operands can also be part of an instruction itself; such
operands are called immediate operands.
Place to store the results destination on which result is to be stored.
An instruction also specifies the location in which the result of the operation, specified by
the instruction, is to be stored. Possible locations are CPU registers, memory cells and
I/O locations.
Source of the next instruction source operand is on which operation is perfromed on it
By default, in a program the next instruction in sequence is executed. So in cases where
the nextinsequence instruction execution is desired, the place of next instruction need
not be encoded within the instruction, as it is implicit. However, in case of a branch, this
information needs to be encoded in the instruction. A branch may be conditional or
unconditional, a subroutine call, as well as a call to an interrupt service routine.
Example
The table provides examples of assembly language commands and their machine
language equivalents. In the instruction
add cx, dx, the contents of the location
dx are added to the contents of the
location cx, and the result is stored in
cx. The instruction type is arithmetic,
and the opcode for the add instruction
is 0000, as shown in this example.
CLASSIFICATIONS OF
code size nbr of INSTRUCTIONS:
mem or byte
We can classify instructions according to the format shown below.
13 22 4address instructions 2,3 4 are used in general purpose register machines are used
10 19 3address instructions 3 bit address contain 3 operand
7 16
2address instructions 2 bits address contain 2 operand
4 7
1 10 1address instructions i address is accamulater
0address instructions 0 walee stack base machines no operand only push or pop
The distinction is based on the fact that some operands are accessed from memory, and
therefore require a memory address, while others may be in the registers within the CPU
or they are specified implicitly.
4(address instructions
The four address instructions specify the addresses of two source operands, the address of
the destination
operand and the next
instruction address.
4address
instructions are not
very common because the next instruction to be executed is sequentially stored next to
the current instruction in the
memory. Therefore, specifying its address is redundant. These instructions are used in
the microcoded control unit, which will be studied later.
3(address instruction
Last Modified: 12Jan11 Page 34
Advanced Computer ArchitectureCS501
A 3address instruction specifies the addresses of two operands and the address of the
destination operand.
2(address instruction
A 2address instruction has three fields; one for the opcode, the second field specifies
the address of one of the source operands as
well as the destination operand, and the last
field is used for holding the address of the
second source operand. So one of the fields serves two purposes; specifying a source
operand address and a destination operand address.
1(address instruction
A 1address instruction has a dedicated CPU register,
the result. There is no need of encoding the address of the accumulator register to access
the operand or to store the result, as its usage is implicit. There are two fields in the
instruction, one for specifying a source operand address and a destination operand
address.
0(address instruction
A 0address instruction uses a stack to hold both the operands and the
result. Operations are performed on the operands stored on the top of the
stack and the second value on the stack. The result is stored on the top of
the stack. Just like the use of an accumulator register, the addresses of
the stack registers need not be specified, their usage is implicit. Therefore, only one field
is required in 0address instruction; it specifies the opcode.
COMPARISON OF INSTRUCTION FORMATS:
Basis for comparison
Two parameters are used as the basis for comparison of the instruction sets discussed
above. These are
�� Code size
Code size has an effect on the storage requirements for the instructions; the
greater the code size, the larger the memory required.
�� Number of memory accesses
The number of memory accesses has an effect on the execution time of
instructions; the greater the number of memory accesses, the larger the time
required for the execution cycle, as memory accesses are generally slow.
Assumptions
We make a few assumptions, which are
�� A single byte is used for the op code, so 256 instructions can be encoded using
these 8 bits, as 28 = 256
�� The size of the memory address space is 16 Mbytes
�� A single addressable memory unit is a byte
HALF ADDRESSES
In the preceding discussion we have
talked about memory addresses. This
discussion also applies to CPU
registers. However, to specify/ encode
a CPU register, less number of bits is
required as compared to the memory addresses. Therefore, these addresses are also called
halfaddresses. An instruction that specifies one memory address and one CPU register
can be called as a 1½address instruction
Example
mov al, [34h]
THE PRACTICAL SITUATION
Real machines are not as simple as the classifications presented above. In fact, these
machines have a mixture of 3, 2, 1, 0, and 1½address instructions. For example, the
VAX 11 includes instructions from all classes.
CLASSIFICATION OF MACHINES ON THE BASIS OF OPERAND
AND RESULT LOCATION:
A distinction between machines can be made on the basis of the ALU instructions;
whether these instructions use data from the memory or not. If the ALU instructions use
only the CPU registers for the operands and result, the machine type is called load(
store. Other machines may have a mixture of registermemory, or memorymemory
instructions.
The number of memory operands supported by a typical ALU instruction may vary from
0 to 3.
Example
The SPARC, MIPS, Power PC, ALPHA: 0 memory addresses, max operands allowed = 3
X86, 68x series: 1 memory address, max operands allowed = 2
LOAD( STORE MACHINES
These machines are also called the registertoregister machines. They typically use the
1½ address instruction format. Only the load and store instructions can access the
memory. The load instruction fetches the required data from the memory and temporarily
stores it in the CPU registers. Other instructions may use this data from the CPU
registers. Then later, the results can be stored back into the memory by the store
instruction. Most RISC computers fall under this category of machines.
Advantages (of register(register instructions)
Registerregister instructions use 0 memory operands out of a total of 3 operands. The
advantages of such a scheme is:
�� The instructions are simple and fixed in length
�� The corresponding code generation model is simple
�� All instructions take similar number of clock cycles for execution
Disadvantages (register(register instructions)
�� The instruction count is higher; the number of instructions required to complete a
particular task is more as separate instructions will be required for load and store
operations of the memory
�� Since the instruction size is fixed, the instructions that do not require all fields
waste memory bits
Register(memory machines
In registermemory machines, some operands are in the memory and some are in
registers. These machines typically employ 1 or 1½ address instruction format, in which
one of the operands is an accumulator or a generalpurpose CPU registers.
Advantages
Registermemory operations use one memory operand out of a total of two operands. The
advantages of this instruction format are
�� Operands in the memory can be accessed without having to load these first
through a separate load instruction
�� Encoding is easy due to the elimination of the need of loading operands into
registers first
�� Instruction bit usage is relatively better, as more instructions are provided per
fixed number of bits
Disadvantages
�� Operands are not equivalent since one operand may have two functions (both
source operand and destination operand), and the source operand may be
destroyed
�� Different size encoding for memory and registers may restrict the number of
registers
�� The number of clock cycles per instruction execution vary, depending on the
operand location operand fetch from memory is slow as compared to operands in
CPU registers
Memory(Memory Machines
In memorymemory machines, all three of the operands (2 source operands and a
destination operand) are in the memory. If one of the operands is being used both as a
source and a destination, then the 2address format is used. Otherwise, memorymemory
machines use 3address formats of instructions.
Advantages
�� The memorymemory instructions are the most compact instruction where
encoding wastage is minimal.
�� As operands are fetched from and stored in the memory directly, no CPU registers
are wasted for temporary storage
Disadvantages
�� The instruction size is not fixed; the large variation in instruction sizes makes
decoding complex
�� The cycles per instruction execution also vary from instruction to instruction
�� Memory accesses are generally
slow, so too many references
cause performance degradation
Example 1
The expression a = (b+c)*d e is
evaluated with the 3, 2, 1, and 0
address machines to provide a
Last Modified: 12Jan11 Page 38
Advanced Computer ArchitectureCS501
In this addressing mode, data is the part of the instruction itself, and so there is no need of
address calculation. However, immediate addressing mode is used to hold source
operands only; cannot be used for storing results. The range of the operands is limited by
the number of bits available for encoding the operands in the instruction; for n bit fields,
the range is 2(n1) to +(2(n1)1).
Example: lda 123
In this example, the immediate
operand, 123, is loaded onto the
accumulator. No address calculation is
required.
Direct Addressing Mode
The address of the operand is specified
as a constant, and this constant is
coded as part of the instruction. The address space that can be accessed is limited address
space by the operand field size (2operand field size locations).
Example: lda [123]
As shown in the figure, the address of
the operand is stored in the instruction.
The operand is then fetched from that
memory address.
Indirect Addressing Mode
The address of the location where the
address of the data is to be found is
stored in the instruction as the operand.
Thus, the operand is the address of a memory location, which holds the address of the
operand. Indirect addressing mode can access a large address space (2memory word size
locations). To fetch the operand in this addressing mode, two memory accesses are
required. Since memory accesses are slow, this is not efficient for frequent memory
accesses. The indirect addressing mode
may be used to implement pointers.
Example: lda [[123]]
As shown in the figure, the address of
the memory location that holds the
address of the data in the memory is
part of the instruction.
REGISTER INDIRECT
ADDRESSING MODE
In the register indirect mode, the
address of memory location that
contains the operand is in a CPU
register. The address of this CPU
register is encoded in the instruction. A
large address space can be accessed
using this addressing mode (2register size
locations). It involves fewer memory
accesses compared to indirect addressing.
Example: lda [R1]
The address of the register that
contains the address of memory
location holding the operand is
encoded in the instruction. There is
one memory access involved.
Displacement addressing mode
The displacementaddressing mode is
also called based or indexed
addressing mode. Effective memory address is calculated by adding a constant (which is
usually a part of the instruction) to the value in a CPU register. This addressing mode is
useful for accessing arrays. The addressing mode may be called indexed in the situation
when the constant refers to the first element of the array (base) and the register contains
the index. Similarly, based refers to the situation when the constant refers to the offset
(displacement) of an array element with respect to the first element. The address of the
first element is stored in a register.
Example: lda [R1 + 8]
In this example, R1 is the address of
the register that holds a memory
address, which is to be used to
calculate the effective address of the
operand. The constant (8) is added to
this address held by the register and
this effective address is used to
retrieve the operand.
Relative addressing mode
The relative addressing mode is similar to the indexed addressing mode with the
exception that the PC holds the base address. This allows the storage of memory
operands at a fixed offset from the current instruction and is useful for short jumps.
Example: jump 4
The constant offset (4) is a part of the
instruction, and it is added to the
address held by the Program Counter.
Generally, computers can be classified as being RISC machines or CISC machines. These
concepts are explained in the following discussion.
RISC (Reduced instruction set computers)
RISC is more of a philosophy of computer design than a set of architectural features. The
underlying idea is to reduce the number and complexity of instructions. However, new
RISC machines have some instructions that may be quite complex and the number of
instructions may also be large. The common features of RISC machines are
One instruction per clock period
This is the most important feature of the RISC machines. Since the program execution
depends on throughput and not on individual execution time, this feature is achievable by
using pipelining and other techniques. In such a case, the goal is issuing an average of
one instruction per cycle without increasing the cycle time.
Fixed size instructions
Generally, the size of the instructions is 32 bits.
CPU accesses memory only for Load and Store operations
This means that all the operands are in the CPU registers at the time these are used in an
instruction. For this purpose, they are first brought into the CPU registers from the
memory and later stored back through the load and store operation respectively.
Simple and few addressing modes
The disadvantage associated with using complex addressing modes is that complex
decoding is required to calculate these addresses, which reduces the processor
performance as it takes significant time. Therefore, in RISC machines, few simple
addressing modes are used.
Less work per instruction
As the instructions are simple, less work is done per instruction, and hence the clock
period T can be reduced.
Improved usage of delay slots
A delay slot is the waiting time for a load or store operation to access memory or for a
branch instruction to access the target instruction. RISC designs allow the execution of
the next instruction after these instructions are issued. If the program or compiler places
an instruction in the delay slot that does not depend on the result of the previous
instruction, the delay slot can be used efficiently. For the implementation of this feature,
improved compilers are required that can check the dependencies of instructions before
issuing them to utilize the delay slots.
Efficient usage of Pre(fetching and Speculative Execution Techniques
Prefetching and speculative execution techniques are used with a pipelined architecture.
Instruction pipelining means having multiple instructions in different stages of execution
as instructions are issued before the previous instruction has completed its execution;
pipelining will be studied in detail later. The RISC machines examine the instructions to
check if operand fetches or branch instructions are involved. In such a case, the operands
or the branch target instructions can be prefetched. As instructions are issued before
the preceding instructions have completed execution, the processor will not know in case
of a conditional branch instruction, whether the condition will be met and the branch will
be taken or not. But instead of waiting for this information to be available, the branch can
be speculated as taken or not taken, and the instructions can be issued. Later if the
speculation is found to be wrong, the results can be discarded and actual target
instructions can be issued. These techniques help improve the performance of processors.
Last Modified: 12Jan11 Page 42
Advanced Computer ArchitectureCS501
Lecture No. 3
Introduction to SRC Processor
Reading Material
Vincent P. Heuring&Harry F. Jordan Chapter2, Chapter 3
Computer Systems Design and Architecture 2.3, 2.4, 3.1
Summary
1) Measures of performance
2) Introduction to an example processor SRC
3) SRC:Notation
4) SRC features and instruction formats
Measures of performance:
Performance testing
To test or compare the performance of machines, programs can be run and their
execution times can be measured. However, the execution speed may depend on the
particular program being run, and matching it exactly to the actual needs of the customer
can be quite complex. To overcome this problem, standard programs called benchmark
programs have been devised. These programs are intended to approximate the real
workload that the user will want to run on the machine. Actual execution time can be
measured by running the program on the machines.
Commonly used measures of performance
The basic measure of performance of a machine is time. Some commonly used measures
of this time, used for comparison of the performance of various machines, are
Execution time
MIPS
MFLOPS
Whetstones
Dhrystones
SPEC
Execution time
Execution time is simply the time it takes a processor to execute a given program. The
time it takes for a particular program depends on a number of factors other than the
performance of the CPU, most of which are ignored in this measure. These factors
include waits for I/O, instruction fetch times, pipeline delays, etc.
The execution time of a program with respect to the processor, is defined as
Execution Time = IC x CPI x T
Where, IC = instruction count
CPI = average number of system clock periods to execute an instruction
T = clock period
Strictly speaking, (IC�CPI) should be the sum of the clock periods needed to execute
each instruction. The manufacturers for each instruction in the instruction set usually
provide such information. Using the average is a simplification.
MIPS (Millions of Instructions per Second)
Another measure of performance is the millions of instructions that are executed by the
processor per second. It is defined as
MIPS = IC/ (ET x 106)
This measure is not a very accurate basis for comparison of different processors. This is
because of the architectural differences of the machines; some machines will require
more instructions to perform the same job as compared to other machines. For example,
RISC machines have simpler instructions, so the same job will require more instructions.
This measure of performance was popular in the late 70s and early 80s when the VAX
11/780 was treated as a reference.
MFLOPS (Millions of Floating Point Instructions per Second)
For computation intensive applications, the floatingpoint instruction execution is a better
measure than the simple instructions. The measure MFLOPS was devised with this in
mind. This measure has two advantages over MIPS:
�� Floating point operations are complex, and therefore, provide a better picture of
the hardware capabilities on which they are run
�� Overheads (operand fetch from memory, result storage to the memory, etc.) are
effectively lumped with the floating point operations they support
Whetstones
Whetstone is the first benchmark program developed specifically as a benchmark
program for performance measurement. Named after the Whetstone Algol compiler, this
benchmark program was developed by using the statistics collected during the compiler
development. It was originally an Algol program, but it has been ported to FORTRAN,
Pascal and C. This benchmark has been specifically designed to test floating point
instructions. The performance is stated in MWIPS (millions of Whetstone instructions per
second).
Dhrystones
Developed in 1984, this is a small benchmark program to measure the integer instruction
performance of processors, as opposed to the Whetstones emphasis on floating point
instructions. It is a very small program, about a hundred highlevellanguage statements,
and compiles to about 1~ 1½ kilobytes of code.
Disadvantages of using Whetstones and Dhrystones
Both Whetstones and Dhrystones are now considered obsolete because of the following
reasons.
�� Small, fit in cache
�� Obsolete instruction mix
�� Prone to compiler tricks
�� Difficult to reproduce results
�� Uncontrolled source code
We should note that both the Whetstone and Dhrystone benchmarks are small programs,
which encourage overoptimization, and can be used with optimizing compilers to
distort results.
SPEC
SPEC, System Performance Evaluation Cooperative, is an association of a number of
computer companies to define standard benchmarks for fair evaluation and comparison of
different processors. The standard SPEC benchmark suite includes:
�� A compiler
�� A Boolean minimization program
�� A spreadsheet program
�� A number of other programs that stress arithmetic processing speed
The latest version of these benchmarks is SPEC CPU2000.
Advantages
�� It provides for ease of publication.
�� Each benchmark carries the same weight.
�� SPEC ratio is dimensionless.
�� It is not unduly influenced by long running programs.
�� It is relatively immune to performance variation on individual benchmarks.
�� It provides a consistent and fair metric.
An example computer: the SRC: simple RISC computer
An example machine is introduced here to facilitate our understanding of various design
steps and concepts in computer architecture. This example machine is quite simple, and
leaves out a lot of details of a real machine, yet it is complex enough to illustrate the
fundamentals.
SRC Introduction
Attributes of the SRC
The SRC contains 32 General Purpose Registers: R0, R1,
, R31; each register is
of size 32bits.
Two special purpose registers are included: Program Counter (PC) and Instruction
Register (IR)
Memory word size is 32 bits
Memory space size is 232 bytes
32
Memory organization is 2 x 8 bits, this means that the memory is byte aligned
Memory is accessed in 32 bit words ( i.e., 4 byte chunks)
Bigendian byte storage is used
o Example:
lar R3, 56
This instruction will load the register R3 with the relative address itself
(PC+56).
�� The str is used to store register to memory using relative address (opcode = 4)
o Example:
str R8, 34
This instruction will store the register R8 contents to the memory location
M [PC+34]
The effective address is computed at runtime by adding a constant to the PC. This makes
the instructions relocatable.
Type C
Type C format has three load/store
instructions, plus three ALU
instructions. These load/ store instructions are
�� ld, the load register from memory instruction (opcode = 1)
o Example 1:
ld R3, 56
This instruction will load the register R3 with the contents of the memory
location M [56]; the rb field is 0 in this instruction, i.e., it is not used. This
is an example of direct addressing mode.
o Example 2:
ld R3, 56(R5)
The contents of the memory location M [56+R [5]] are loaded to the
register R3; the rb field � 0. This is an instance of indexed addressing
mode.
�� la is the instruction to load a register with an immediate data value (which can be
an address) (opcode = 5 )
o Example1:
la R3, 56
The register R3 is loaded with the immediate value 56. This is an instance
of immediate addressing mode.
o Example 2:
la R3, 56(R5)
The register R3 is loaded with the indexed address 56+R [5]. This is an
example of indexed addressing mode.
�� The st instruction is used to store register contents to memory (opcode = 3)
o Example 1:
st R8, 34
This is the direct addressing mode; the contents of register R8 (R [8]) are
stored to the memory location M [34]
o Example 2:
st R8, 34(R6)
An instance of indexed addressing mode, M [34+R [6]] stores the contents
of R8(R [8])
The ALU instructions are
�� addi, immediate 2s complement addition (opcode = 13)
o Example:
Last Modified: 12Jan11 Page 48
Advanced Computer ArchitectureCS501
Lecture No. 4
ISA and Instruction Formats
Reading Material
Vincent P. Heuring&Harry F. Jordan Chapter 2
Computer Systems Design and Architecture 2.3, 2.4,slides
Summary
1) Introduction to ISA and instruction formats
2) Coding examples and Hand assembly
st R8, 34
This is the direct addressing mode; the contents of register R8 (R [8]) are
stored to the memory location M [34]
o Example 2:
st R8, 34(R6)
An instance of indexed addressing mode, M [34+R [6]] stores the contents
of R8(R [8])
The ALU instructions are
�� addi, immediate 2s complement addition (opcode = 13)
o Example:
addi R3, R4, 56
R[3] R[4]+56 (rb field = R4)
�� andi, the instruction to obtain immediate logical AND, (opcode = 21 )
o Example:
andi R3, R4, 56
R3 is loaded with the immediate logical AND of the contents of register
R4 and 56(constant value)
�� ori, the instruction to obtain immediate logical OR (opcode = 23 )
o Example:
ori R3, R4, 56
R3 is loaded with the immediate logical OR of the contents of register R4
and 56(constant value)
Note:
1. Since the constant c2 field is 17 bits,
16
For direct addressing mode, only the first 2 bytes of memory can
16
be accessed (or the last 2 bytes if c2 is negative)
In case of the la instruction, only constants with magnitudes less
than ±216 can be loaded
During address calculation using c2, sign extension to 32 bits must
be performed before the addition
2. Type C instructions, with some modifications, may also be used for
shift instructions. Note the modification in the following figure.
The four shift instructions are
�� shr is the instruction used to
shift the bits right by using
value in (5bit) c3 field(shift count) (opcode = 26)
o Example:
shr R3, R4, 7
shift R4 right 7 times in to R3 and shifts zeros in from the left as the value
is shifted right. Immediate addressing mode is used.
�� shra, arithmetic shift right by using value in c3 field (opcode = 27)
o Example:
shra R3, R4, 7
This instruction has the effect of shift R4 right 7 times in to R3 and copies
the msb into the word on left as contents are shifted right. Immediate
addressing mode is used.
�� The shl instruction is for shift left by using value in (5bit) c3 field (opcode = 28)
Last Modified: 12Jan11 Page 53
Advanced Computer ArchitectureCS501
o Example:
shl R8, R5, 6
shift R5 left 6 times in to R8 and shifts zeros in from the right as the value
is shifted left. Immediate addressing mode is used.
�� shc, shift left circular by using value in c3 field (opcode = 29)
o Example:
shc R3, R4, 3
shift R4 circular 3 times in to R3 and copies the value shifted out of the
register on the left is placed back into the register on the right. Immediate
addressing mode is used.
Type D
Type D includes four ALU
instructions, four register based shift
instructions, two logical instructions
and two branch instructions.
The four ALU instructions are given below
�� add, the instruction for 2s complement register addition (opcode = 12)
o Example:
add R3, R5, R6
result of 2s complement addition R[5] + R[6] is stored in R3. Register
addressing mode is used.
�� sub , the instruction for 2s complement register subtraction (opcode = 14)
o Example:
sub R3, R5, R6
R3 will store the 2s complement subtraction, R[5] R[6]. Register
addressing mode is used.
�� and, the instruction for logical AND operation between registers (opcode = 20)
o Example:
and R8, R3, R4
R8 will store the logical AND of registers R3 and R4. Register addressing
mode is used.
�� or ,the instruction for logical OR operation between registers (opcode = 22)
o Example:
or R8, R3, R4
R8 is loaded with the value R[3] v R[4], the logical OR of registers R3 and
R4. Register addressing mode is used.
The four register based shift instructions use register addressing mode. These use a
modified form of type D, as shown in
figure
�� shr, shift right by using value in
register rc (opcode = 26)
o Example:
shr R3, R4, R5
This instruction will shift R4 right in to R3 using number in R5
�� shra, the arithmetic shift right by using register rc (opcode = 27)
o Example:
shra R3, R4, R5
brlzr R1,R3, R4
R1 will store the contents of PC, then branch to address in R3 (if R4 == 0)
o Example 2:
brlnz R1,R3, R4
R1 stores the contents of PC, then a branch is taken, to address in R3 (if
R4 � 0)
o Example 3:
brlpl R1,R3, R4
R1 will store PC, then
branch to address in R3
(if R4� 0)
o Example 4:
brlmi R1,R3, R4
R1 will store PC and
then branch to address in
R3 (if R4 < 0)
o Example 5:
brl R1,R3, R4
R1 will store PC, then it will ALWAYS branch to address in R3
o Example 6:
brlnv R1,R3, R4
R1 just stores the contents of PC but a branch is not taken (NEVER
BRANCH)
In the modified type D instructions for branch, the bits <2..0> are used for specifying the
condition; these condition codes are shown in the table.
The SRC Instruction Summary
The instructions implemented by the SRC
are listed, grouped on functionality basis.
Functional Groups of Instructions
Solution B:
We may solve the problem by assuming that a multiply instruction, similar to the add
instruction, exists in the instruction set of the SRC. The shl instruction will be replaced
by the mul instruction as given below.
ld R1, c ; c is a label used for a memory location
addi R3, R1, 58 ; R3 contains (c+58)
mul R7, R3, 4 : R7 contains 16(c+58)
ld R4, a
ld R5, b
add R6, R4, R5 ; R6 contains (a+b)
mul R8, R6, 2 ; R8 contains 4(a+b)
sub R9, R8, R7 ; the result is in R9
st R9, z ; store the result in memory location z
Note:
The memory labels a, b, c and z can be defined by using assembler directives like .dw or
.db, etc. in the source file.
Solution C:
We can perform multiplication with a multiplier that is not a power of 2 by doing
addition in a loop. The number of times the loop will execute will be equal to the
multiplier.
We have to convert these instructions to machine language. Let us start with the first
instruction:
ld R1, c
Notice that this is a type C instruction with the rb field missing.
1. We pick the opcode for this load instruction from the SRC instruction tables
given in the SRC instruction summary section. The opcode for the load register
ld instruction is 00001.
2. Next we pick the register code corresponding to register R1 from the register table
(given in the section encoding of general
purpose registers). The register code for
R1 is 00001.
3. The rb field is missing, so we place zeros
in the field: 00000
4. The value of c is provided by the
assembler, and should be converted to 17
bits. As c has been assigned the memory
address 208, the binary value to be
encoded is 00000 0000 1101 0000.
5. So the instruction ld R1, c is 00001 00001
00000 00000 0000 1101 0000 in the
machine language.
6. The hexadecimal representation of this
instruction is 0 8 4 0 0 0 D 0 h.
We can update the memory map with these
values.
We consider the next instruction,
addi R3, R1, 58.
Notice that this is a type C instruction.
1. We pick the opcode for the instruction addi from
the SRC instruction table. It is 01101
2. We pick the register codes for the registers R3 and
R1, these codes are 00011 and 00001 respectively
3. For the immediate data, 58, we use the binary
value, 00000 0000 0011 1010
4. So the complete instruction becomes: 01101
00011 00001 00000 0000 0011 1010
5. The hexadecimal representation of the instruction
is 6 8 C 2 0 0 3 A h
We update the memory map, as shown in table.
The next instruction is shl R7,R3, 4, at address 408.
Again, this is a type C instruction.
1. The opcode for the instruction shl is picked from
the SRC instruction table. It is 11100
2. The register codes for the registers R7 and R3
from the register table are 00111 and 00011
respectively
3. For the immediate data, 4, the corresponding binary value 00000 0000 0000 0100
is used.
4. We can place these codes in accordance with the type C instruction format to
obtain the complete instruction: 11100 00111 00011 00000 0000 0000 0100
5. The hexadecimal representation of the instruction is E1C60004
The memory map is updated, as shown in table.
The next instruction, ld R4, a, is also a type C instruction.
Rb field is missing in this instruction. To obtain the
machine equivalent, we follow the steps given below.
1. The opcode of the load instruction ld is 00001
2. The register code corresponding to the register R4
is obtained from the register table, and it is 00100
3. As the 5 bit rb field is missing, we can encode
zeros in its place: 00000
4. The value of a is provided by the assembler, and
is converted to 17 bits. It has been assigned the
memory address 200, the binary equivalent of
which is: 00000 0000 1100 1000
5. The complete instruction becomes: 00001 00100 00000 00000 0000 1100 1000
6. The hexadecimal equivalent of the instruction is 0 9 0 0 0 0 C 8 h
Memory map can be updated with this value.
The next instruction is also a load type C instruction, with
the rb field missing.
ld R5, b
The machine language conversion steps are
1. The opcode of the load instruction is obtained
from the SRC instruction table; it is 00001
2. The register code for R5, obtained from the
register table, is 00101
3. Again, the 5 bit rb field is missing. We encode
zeros in its place: 00000
4. The value of label b is provided by the assembler,
and should be converted to 17 bits. It has been
assigned the memory address 204, so the binary
value is: 00000 0000 1100 1100
5. The complete instruction is: 00001 00101 00000 00000 0000 1100 1100
6. The hexadecimal value of this instruction is 0 9 4
000CCh
Memory map is then updated with this value.
The next instruction is a type Dadd instruction, with the
constant field missing:
add R6,R4,R5
The steps followed to obtain the assembly code for this
instruction are
1. The opcode of the instruction is obtained from
the SRC instruction table; it is 01100
2. The register codes for the registers R6, R4 and R5
are obtained from the register table; these are
Last Modified: 12Jan11 Page 61
Advanced Computer ArchitectureCS501
4. The value of the label z is provided by the assembler, and should be converted to
17 bits. Notice that the memory address assigned to z is 212. The 17 bit binary
equivalent is: 00000 0000 1101 0100
5. The complete instruction becomes: 00011 01001 00000
00000 0000 1101 0100
6. The hexadecimal form of this instruction is 1 A 4 0 0 0 D 4
h
The memory map, after the conversion of all the instructions, is
We have shown the memory map as an array of 4 byte cells in the
above solution. However, since the memory of the SRC is arranged
in 8 bit cells (i.e. memory is byte aligned), the real representation of
the memory map is :
Solution:
Lecture No. 5
Description of SRC in RTL
Reading Material
Handouts Slides
Summary
1) Reverse Assembly
2) Description of SRC in the form of RTL
3) Behavioral and Structural description in terms of RTL
Reverse Assembly
Typical Problem:
Given a machine language instruction for the SRC, it may be required to find the
equivalent SRC assembly language instruction
Example:
Reverse assemble the following SRC machine language instructions:
68C2003A h
E1C60004 h
61885000 h
724E8000 h
1A4000D4 h
084000D0 h
Solution:
1. Write the given hexadecimal instruction in binary form
68C2003A h 0110 1000 1100 0010 0000 0000 0011 1010 b
2. Examine the first five bits of the instruction, and pick the corresponding mnemonic
from the SRC instruction set listing arranged according to ascending order of opcodes
01101 b 13 d addi add immediate
3. Now we know that this instruction uses the type C format, the two 5bit fields after the
opcode field represent the destination and the source registers respectively, and that the
remaining 17bits in the instruction represent a constant
We can do it a bit faster now! Step1: Here is step1 for all instructions
The meaning of the remaining fields will depend on the instruction type (i.e., the
instruction format)
Summary
Note: est of the fields of above given tables are left as an exercise for students.
Using RTL to describe the SRC
RTL stands for Register Transfer Language. The Register Transfer Language provides a
formal way for the description of the behavior and structure of a computer. The RTL
facilitates the design process of the computer as it provides a precise, mathematical
representation of its functionality. In this section, a Register Transfer Language is
presented and introduced, for the SRC (Simple RISC Computer), described in the
previous discussion.
Behavioral RTL
Behavioral RTL is used to describe the functionality of the machine only, i.e. what the
machine does.
Structural RTL
Structural RTL describes the hardware implementation of the machine, i.e. how the
functionality made available by the machine is implemented.
Behavioral versus Structural RTL:
In computer design, a topdown approach is adopted. The computer design process
typically starts with defining the behavior of the overall system. This is then broken down
into the behavior of the different modules. The process continues, till we are able to
define, design and implement the structure of the individual modules. Behavioral RTL is
used for describing the behavior of machine whereas structural RTL is used to define the
structure of machine, which brings us to the some more hardware features.
Using RTL to describe the static properties of the SRC
In this section we introduce the RTL by using it to describe the various static properties
of the SRC.
Specifying Registers
The format used to specify registers is
Register Name<register bits>
For example, IR<31..0> means bits numbered 31 to 0 of a 32bit register named IR
(Instruction Register).
Naming using the := naming operator:
The := operator is used to name registers, or part of registers, in the Register Transfer
Language. It does not create a new register; it just generates another name, or alias for
an already existing register or part of a register. For example,
Op<4..0>: = IR<31..27> means that the five most significant bits of the register IR will
be called op, with bits 4..0.
Fields in the SRC instruction
In this section, we examine the various fields of an SRC instruction, using the RTL.
op<4..0>: = IR<31..27>; operation code field
Last Modified: 12Jan11 Page 66
Advanced Computer ArchitectureCS501
The five most significant bits of an SRC instruction, (stored in the instruction register in
this example), are named op, and this field is used for specifying the operation.
ra<4..0>: = IR<26..22>; target register field
The next five bits of the SRC instruction, bits 26 through 22, are used to hold the address
of the target register field, i.e., the result of the operation performed by the instruction is
stored in the register specified by this field.
rb<4..0>: = IR<21..17>; operand, address index, or branch target register
The bits 21 through 17 of the instruction are used for the rb field. rb field is used to hold
an operand, an address index, or a branch target register.
rc<4..0>: = IR<16..12>; second operand, conditional test, or shift count register
The bits 16 through 12, are the rc field. This field may hold the second operand,
conditional test, or a shift count.
c1<21..0>: = IR<21..0>; long displacement field
In some instructions, the bits 21 through 0 may be used as long displacement field.
Notice that there is an overlap of fields. The fields are distinguished in a particular
instruction depending on the operation.
c2<16..0>: = IR<16..0>; short displacement or immediate field
The bits 16 through 0 may be used as short displacement or to specify an immediate
operand.
c3<11..0>: = IR<11..0>; count or modifier field
The bits 11 through 0 of the SRC instruction may be used for count or modifier field.
Describing the processor state using RTL
The Register Transfer Language can be used to describe the processor state. The
following registers and bits together form the processor state set.
PC<31..0>; program counter (it holds the memory address of next
instruction to be executed)
IR<31..0>; instruction register, used to hold the current instruction
Run; one bit run/halt indicator
Strt; start signal
R [0..31]<31..0>; 32, 32 bit general purpose registers
Difference between our notation and notation used by the text (H&J)
specified directly. Instead, the effective address may have to be calculated at runtime.
These effective address calculations can be represented in RTL, as illustrated through the
examples below.
Displacement address
disp<31..0> := ((rb=0) : c2<16..0> {sign extend},
Last Modified: 12Jan11 Page 68
Advanced Computer ArchitectureCS501
iE:= (
(op<4..0>= 1) : R [ra] � M [disp],
(op<4..0>= 2) : R [ra] � M [rel],
...
...
(op<4..0>=31) : Run � 0,); iF);
As shown above, Instruction Execution can be described by using a long list of
conditional operations, which are inherently disjoint.
One of these statements is executed, depending on the condition met, and then the
instruction fetch statement (iF) is invoked again at the end of the list of concurrent
statements. Thus, instruction fetch (iF) and instruction execution statements invoke each
other in a loop. This is the fetchexecute cycle of the SRC.
Concurrent Statements
The long list of concurrent, disjoint instructions of the instruction execution (iE) is
basically the complete instruction set of the processor. A brief overview of these
instructions is given below.
Load(Store Instructions
(op<4..0>= 1) : R [ra] � M [disp], load register (ld)
This instruction is to load a register using a displacement address specified by the
instruction, i.e. the contents of the memory at the address disp are placed in the register
R [ra].
(op<4..0>= 2) : R [ra] � M [rel], load register relative (ldr)
If the operation field op of the instruction decoded is 2, the instruction that is executed
is loading a register (target address of this register is specified by the field ra) with
memory contents at a relative address, rel. The relative address calculation has been
explained in this section earlier.
(op<4..0>= 3) : M [disp] � R [ra], store register (st)
If the opcode is 3, the contents of the register specified by address ra, are stored back to
the memory, at a displacement location disp.
(op<4..0>= 4) : M[rel] � R[ra], store register relative (str)
If the opcode is 4, the contents of the register specified by the target register address ra,
are stored back to the memory, at a relative address location rel.
(op<4..0>= 5) : R [ra] � disp, load displacement address (la)
For opcode 5, the displacement address disp is loaded to the register R (specified by the
target register address ra).
(op<4..0>= 6) : R [ra] � rel, load relative address (lar)
For opcode 6, the relative address rel is loaded to the register R (specified by the target
register address ra).
Branch Instructions
(op<4..0>= 8) : (cond : PC � R [rb]), conditional branch (br)
If the opcode is 8, a conditional branch is taken, that is, the program counter is set to the
target instruction address specified by rb, if the condition cond is true.
(op<4..0>= 9) : (R [ra] � PC,
cond : (PC � R [rb]) ), branch and link (brl)
If the op field is 9, branch and link instruction is executed, i.e. the contents of the
program counter are stored in a register specified by ra field, (so control can be returned
to it later), and then the conditional branch is taken to a branch target address specified by
rb. The branch and link instruction is useful for returning control to the calling program
after a procedure call returns.
The conditions that these conditional branches depend on are specified by the field c3
that has 3 bits. This simply means that when c3<2..0> is equal to one of these six values.
We substitute the expression on the right hand side of the : in place of cond
These conditions are explained here briefly.
cond := (
c3<2..0>=0 : 0, never
If the c3 field is 0, the branch is never taken.
c3<2..0>=1 : 1, always
If the field is 1, branch is taken
c3<2..0>=2 : R [rc]=0, if register is zero
If c3 = 2, a branch is taken if the register rc = 0.
c3<2..0>=3 : R [rc] � 0, if register is nonzero
If c3 = 3, a branch is taken if the register rc is not equal to 0.
c3<2..0>=4 : R [rc]<31>=0 if positive or zero
If c3 is 4, a branch is taken if the register value in the register specified
by rc is greater than or equal to 0.
c3<2..0>=5 : R [rc]<31>=1), if negative
If c3 = 5, a branch is taken if the value stored in the register specified by
rc is negative.
Arithmetic and Logical instructions
(op<4..0>=12) : R [ra] � R [rb] + R [rc],
If the opcode is 12, the contents of the registers rb and rc are added and the result is
stored in the register ra.
(op<4..0>=13) : R [ra] � R [rb] + c2<16..0> {sign extend},
If the opcode is 13, the content of the register rb is added with the immediate data in the
field c2, and the result is stored in the register ra.
(op<4..0>=14) : R [ra] � R [rb] R [rc],
If the opcode is 14, the content of the register rc is subtracted from that of rb, and the
result is stored in ra.
(op<4..0>=15) : R [ra] � (R [rc],
If the opcode is 15, the content of the register rc is negated, and the result is stored in ra.
(op<4..0>=20) : R [ra] � R [rb] & R [rc],
If the op field equals 20, logical AND of the contents of the registers rb and rc is obtained
and the result is stored in register ra.
(op<4..0>=21) : R [ra] � R [rb] & c2<16..0> {sign extend},
If the op field equals 21, logical AND of the content of the registers rb and the immediate
data in the field c2 is obtained and the result is stored in register ra.
(op<4..0>=22) : R [ra] � R [rb] ~ R [rc],
If the op field equals 22, logical OR of the contents of the registers rb and rc is obtained
and the result is stored in register ra.
(op<4..0>=23) : R [ra] � R [rb] ~ c2<16..0> {sign extend},
If the op field equals 23, logical OR of the content of the registers rb and the immediate
data in the field c2 is obtained and the result is stored in register ra.
(op<4..0>=24) : R [ra] � ¬R [rc],
If the opcode equals 24, the content of the logical NOT of the register rc is obtained, and
the result is stored in ra.
Last Modified: 12Jan11 Page 71
Advanced Computer ArchitectureCS501
Shift instructions
(op<4..0>=26): R [ra]<31..0 > � (n � 0) © R [rb] <31..n>,
If the opcode is 26, the contents of the register rb are shifted right n bits times. The bits
that are shifted out of the register are discarded. 0s are added in their place, i.e. n number
of 0s is added (or concatenated) with the register contents. The result is copied to the
register ra.
(op<4..0>=27) : R [ra]<31..0 > � (n � R [rb] <31>) © R [rb] <31..n>,
For opcode 27, shift arithmetic operation is carried out. In this operation, the contents of
the register rb are shifted right n times, with the most significant bit, bit 31, of the register
rb added in their place. The result is copied to the register ra.
(op<4..0>=28) : R [ra]<31..0 > � R [rb] <31(n..0> © (n � 0),
For opcode 28, the contents of the register rb are shifted left n bits times, similar to the
shift right instruction. The result is copied to the register ra.
(op<4..0>=29) : R [ra]<31..0 > � R [rb] <31(n..0> © R [rb]<31..32(n >,
The instruction corresponding to opcode 29 is the shift circular instruction. The contents
of the register rb are shifted left n times, however, the bits that move out of the register in
the shift process are not discarded; instead, these are shifted in from the other end (a
circular shifting). The result is stored in register ra.
where
n := ( (c3<4..0>=0) : R [rc],
(c3<4..0>!=0) : c3 <4..0> ),
Notation: � means replication
© Means concatenation
Miscellaneous instructions
(op<4..0>= 0) , No operation (nop)
If the opcode is 0, no operation is carried out for that clock period. This instruction is
used as a stall in pipelining.
(op<4..0>= 31) : Run � 0, Halt the processor (Stop)
); iF );
If the opcode is 31, run is set to 0, that is, the processor is halted.
After one of these disjoint instructions is executed, iF, i.e. instruction Fetch is carried out
once again, and so the fetchexecute cycle continues.
Flow diagram
Flow diagram is the symbolic
representation of FetchExecute cycle. Its
top block indicates instruction fetch and
then next block shows the instruction
decode by looking at the first 5bits of the
fetched instruction which would represent
opcode which may be from 0 to
31.Depending upon the contents of this
opcode the appropriate processing would
take place. After the appropriate
processing, we would move back to top
block, next instruction is fetched and the
same process is repeated until the instruction with opcode 31 would reach and halt the
system.
Note:For SRC Assembler and Simulator consult Appendix.
Last Modified: 12Jan11 Page 72
Advanced Computer ArchitectureCS501
Lecture No. 6
RTL Using Digital Logic Circuits
Reading Material
Handouts Slides
Summary
�� Using Behavioral RTL to Describe the SRC (continued)
�� Implementing Register Transfer using Digital Logic Circuits
iE:= (
(op<4..0>= 1) : R [ra] � M [disp],
(op<4..0>= 2) : R [ra] � M [rel],
...
...
(op<4..0>=31) : Run � 0,); iF);
Concurrent Statements
The long list of concurrent, disjoint instructions of the instruction execution (iE) is
basically the complete instruction set of the processor. A brief overview of these
instructions is given below:
Load(Store Instructions
(op<4..0>= 1) : R [ra] � M [disp], load register (ld)
This instruction is to load a register using a displacement address specified by the
instruction, i.e., the contents of the memory at the address disp are placed in the register
R [ra].
Branch Instructions
(op<4..0>= 8) : (cond : PC � R [rb]), conditional branch (br)
If the opcode is 8, a conditional branch is taken, that is, the program counter is set to the
target instruction address specified by rb, if the condition cond is true.
(op<4..0>= 9) : (R [ra] � PC,
cond : (PC � R [rb]) ), branch and link (brl)
If the op field is 9, branch and link instruction is executed, i.e. the contents of the
program counter are stored in a register specified by ra field, (so control can be returned
to it later), and then the conditional branch is taken to a branch target address specified by
rb. The branch and link instruction is useful for returning control to the calling program
after a procedure call returns.
The conditions that these conditional branches depend on, are specified by the field c3
that has 3 bits. This simply means that when c3<2..0> is equal to one of these six values,
we substitute the expression on the right hand side of the : in place of cond.
These conditions are explained here briefly.
cond := (
c3<2..0>=0 : 0, never
If the c3 field is 0, the branch is never taken.
c3<2..0>=1 : 1, always
If the field is 1, branch is taken
c3<2..0>=2 : R [rc]=0, if register is zero
If c3 = 2, a branch is taken if the register rc = 0.
c3<2..0>=3 : R [rc] � 0, if register is nonzero
If c3 = 3, a branch is taken if the register rc is not equal to 0.
c3<2..0>=4 : R [rc]<31>=0 if positive or zero
If c3 is 4, a branch is taken if the register value in the register specified
by rc is greater than or equal to 0.
c3<2..0>=5 : R [rc]<31>=1), if negative
If c3 = 5, a branch is taken if the value stored in the register specified by
rc is negative.
Last Modified: 12Jan11 Page 74
Advanced Computer ArchitectureCS501
Shift instructions
(op<4..0>=26): R [ra]<31..0 > � (n � 0) © R [rb] <31..n>,
If the opcode is 26, the contents of the register rb are shifted right n bits times. The bits
that are shifted out of the register are discarded. 0s are added in their place, i.e. n number
of 0s is added (or concatenated) with the register contents. The result is copied to the
register ra.
(op<4..0>=27) : R [ra]<31..0 > � (n � R [rb] <31>) © R [rb] <31..n>,
For opcode 27, shift arithmetic operation is carried out. In this operation, the contents of
the register rb are shifted right n times, with the most significant bit, i.e., bit 31, of the
register rb added in their place. The result is copied to the register ra.
(op<4..0>=28) : R [ra]<31..0 > � R [rb] <31(n..0> © (n � 0),
For opcode 28, the contents of the register rb are shifted left n bits times, similar to the
shift right instruction. The result is copied to the register ra.
(op<4..0>=29) : R [ra]<31..0 > � R [rb] <31(n..0> © R [rb]<31..32(n >,
The instruction corresponding to opcode 29 is the shift circular instruction. The contents
of the register rb are shifted left n times, however, the bits that move out of the register in
the shift process are not discarded; instead, these are shifted in from the other end (a
circular shifting). The result is stored in register ra.
where
Last Modified: 12Jan11 Page 75
Advanced Computer ArchitectureCS501
n := ( (c3<4..0>=0) : R [rc],
(c3<4..0>!=0) : c3 <4..0> ),
Notation:
� means replication
© means concatenation
Miscellaneous instructions
(op<4..0>= 0) , No operation (nop)
If the opcode is 0, no operation is carried out for that clock period. This instruction is
used as a stall in pipelining.
(op<4..0>= 31) : Run � 0, Halt the processor (Stop)
); iF );
If the opcode is 31, run is set to 0, that is, the processor stops execution.
After one of these disjoint instructions is executed, iF, i.e. instruction Fetch is carried out
once again, and so the fetchexecute cycle continues.
We have studied the register transfers in the previous sections, and how they help in
implementing assembly language. In this section we will review how the basic digital
logic circuits are used to implement instructions register transfers. The topics we will
cover in this section include:
1. A brief (and necessary) review of logic circuits
2. Implementing simple register transfers
3. Register file implementation using a bus
4. Implementing register transfers with mathematical operations
5. The Barrel Shifter
6. Implementing shift operations
There are various types of flipflops; most common type, the D flipflop is shown in the
figure given. The given truth table for this positiveedge triggered D flipflop shows that
the flipflop is set (i.e. stores a 1) when the data input is high on the leading (also called
the positive) edge of the clock; it is reset (i.e., the flipflop stores a 0) when the data input
is 0 on the leading edge of the clock. The clear input will reset the flipflop on a low
input.
The n(bit register
A nbit register can be formed by
grouping n flipflops together. So a
register is a device in which a
group of flipflops operate
synchronously.
A register is useful for storing
binary data, as each flipflop can
store one bit. The clock input of
the flipflops is grouped
together, as is the enable input.
As shown in the figure, using
the input lines a binary number
can be stored in the register by
applying the corresponding
logic level to each of the flip
flops simultaneously at the
positive edge of the clock.
The next figure shows the
symbol of a 4bit register used
for an integrated circuit. In0
through In3 are the four input
lines, Out0 through Out3 are the
four output lines, Clk is the
clock input, and En is the enable
line. To get a better
understanding of this register,
consider the situation where we want
to store the binary number 1000 in the
register. We will apply the number to
the input lines, as shown in the figure given.
On the leading edge of the clock, the number will be stored in the register. The enable
input has to be high if the number is to be stored into the register.
.
Waveform/Timing diagram
control input lines. For an nto1 multiplexer, there are n input lines, log2n control lines,
and 1 output line. The given figure shows a 4to1 multiplexer. There are 4 input lines;
we number these lines as line 0 through line 3. Subsequently, there are 2 select lines (as
log24 = 2).
For a better understanding, let us consider a case where we want to transfer the input of
line 3 to the output of the multiplexer. We will need to apply the binary number 11 on the
select lines (as the binary number 11 represents the decimal number 3). By doing so, the
output of the multiplexer will be the input on line 3, as shown in the test circuit given.
Timing waveform
Tri(state buffers
The tristate buffer, also called the three
state buffer, is another important
component in the digital logic domain. It
has a single input, a single output, and
an enable line. The input is concatenated
to the output only if it is enabled through
the enable line, otherwise it gives a high
impedance output, i.e. it is tristated, or
electrically disconnected from the input
These buffers are available both in the
inverting and the noninverting form. The
inverting tristate buffers output the
inverted input when they are enabled,
as opposed to their noninverting
counterparts that simply output the input
when enabled. The circuit symbol of the
tristate buffers is shown. The truth table
this circuit, the output of the source register RS is connected to the input of the
destination registers RD. However, notice that the transfer will not take place unless the
enable input of the destination register is activated. We may say that the transfer is
being controlled by the enable line (or the control signal). Now, we are able to control the
transfer by selectively enabling the control signal, through the use of other combinational
logic that may be the equivalent of our condition. The condition is, in general, a Boolean
expression, and in this example, the condition is equivalent to LRD =1.
Two(way transfers
In the above example, only oneway transfer was possible, i.e., we could only copy the
contents of RS to RD if the condition was met. In order to be able to achieve twoway
transfers, we must also provide a path from the output of the register RD to input of
register RS. This will enable us to implement
Cond1: RD � RS
Cond2: RS � RD
Connecting multiple registers
We have seen how two registers can be connected. However, in a computer we need to
connect more than just two registers. In order to connect these registers, one may argue
that a connection between the input and output of each be provided. This solution is
shown for a scenario where there are 5 registers that need to be interconnected.
We can see that in this solution, an mbit register requires two connections of mwires
each. Hence five mbit registers in a pointtopoint scheme require 20 connections;
each with m wires. In general, n registers in a point to point scheme require n (n1)
connections. It is quite obvious that this solution is not going to scale well for a large
number of registers, as is the case in real machines. The solution to this problem is the
use of a bus architecture, which is explained in the following sections.
Buses
A bus is a device that provides a shared data
path to a number of devices that are connected
to it, via a set of wires or a set of
conductors. The modern computer systems
extensively employ the bus architecture.
Control signals are needed to decide which two
entities communicate using the shared medium,
i.e. the bus, at any given time. This control
signals can be open collector
gate based, tristate buffer
based, or they can be
implemented using
multiplexers.
register C. The second step is to transfer the contents of the register C to the register R4.
This is done by activating the control Cout, which will load the contents of register C
onto the data bus, and by activating the control LR4, which will let the contents of the
bus be written to the register R4. This will complete the conditional shiftandstore
operation. These steps are summarized in the table shown below.
Lecture No. 7
Design Process for ISA of FALCON(A
Reading Material
Hnadouts Slides
Summary
8) Outline of the thinking process for ISA Design
9) Introduction to the ISA of FALCONA
Instruction Set Architecture (ISA) Design: Outline of the thinking
process
In this module we will learn to appreciate, understand and apply the approach adopted in
designing an instruction set architecture. We do this by designing an ISA for a new
processor. We have named our processor FALCONA, which is an acronym for First
Architecture for Learning Computer Organization and Networks (version A). The term
Organization is intended to include Architecture and Design in this acronym.
Elements of the ISA
Before we go onto designing the instruction set architecture for our processor FALCON
A, we need to take a closer look at the defining components of an ISA. The following
three key components define any instruction set architecture.
1. The operations the processor can execute
2. Data access mode for use as operands in the operations defined
3. Representation of the operations in memory
We take a look at all three of the components in more detail, and wherever appropriate,
apply these steps to the design of our sample processor, the FALCONA. This will help
us better understand the approach to be adopted for the ISA design of a processor. A
more detailed introduction to the FALCONA will be presented later.
The operations the processor can execute
All processors need to support at least three categories (or functional groups) of
instructions
Arithmetic, Logic, Shift
Data Transfer
Control
ISA Design Steps Step 1
We need to think of all the instructions of each type that ought to be supported by our
processor, the FALCONA. The following are the instructions that we will include in the
ISA for our processor.
Arithmetic:
add, addi (and with an immediate operand), subtract, subtractimmediate,
multiply, divide
Logic:
Last Modified: 12Jan11 Page 87
Advanced Computer ArchitectureCS501
Shift:
shiftl (12), shiftr (13), asr (15)
Data Transfer:
load (29), store (28), in (24), out (25), mov (6), movi (7)
Control:
jpl (16), jmi (17), jnz (18), jz (19), jump (20), call (22), ret (23), int (26), iret (27)
Last Modified: 12Jan11 Page 88
Advanced Computer ArchitectureCS501
Miscellaneous instructions:
nop (21), reset (30), halt (31)
Now we list these instructions with
their opcodes in the binary form, as
they would appear in the machine
instructions of the FALCONA.
Data access mode for
operations
As mentioned earlier, the instruction
set architecture of a processor defines
a number of things besides the
instructions implemented; the
resources each instruction can access,
the number of registers available to the processor, the number of registers each
instruction can access, the instructions that are allowed to access memory, any special
registers, constants and any alternatives to the generalpurpose registers. With this in
mind, we go on to the next steps of our ISA design.
ISA Design Steps Step 5
We now need to select the number and types of operands for various instructions that we
have selected for the FALCONA ISA.
ALU instructions may have 2 to 3 registers as operands. In case of 2 operands, a constant
(an immediate operand) may be included in the instruction.
For the load/store type instructions, we require a register to hold the data that is to be
loaded from the memory, or stored back to the memory. Another register is required to
hold the base address for the memory access. In addition to these two registers, a field is
required in the instruction to specify the
constant that is the displacement to the base
address.
In jump instructions; we require a field for
specifying the register that holds the value that
is to be compared as the condition for the
branch, as well as a destination address, which
is specified as a constant.
Once we have decided on the number and
types of operands that will be required in each
of the instruction types, we need to address the
issue of assigning specific bitfields in the
instruction for each of these operands. The number of bits required to represent each of
these operands will eventually determine the instruction word size. In our example
processor, the FALCONA, we reserve eight generalpurpose registers. To encode a
3
register in the instructions, 3 bits are required (as 2 =8). The registers are encoded in the
binary as shown in the given table.
Therefore, the instructions that we will add support for FALCONA processor will have
the given general format. The instructions
in the FALCONA processor are going to
be variations of this format, with four
different formats in all. The exact format is dependent on the actual number of operands
in a particular instruction.
ISA Design Steps Step 6
The next step towards completely defining the instruction set architecture of our
processor is the design of memory and its organization. The number of the memory cells
that we may have in the organization depends on the size of the Program Counter register
(PC), and the size of the address bus. This is because the size of the program counter and
the size of the address bus put a limitation on the number of memory cells that can be
referred to for loading an instruction for execution. Additionally, the size of the data bus
puts a limitation on the size of the memory word that can be referred to in a single clock
cycle.
ISA Design Steps Step 7
Now we need to specify which instructions will be allowed to access the memory. Since
the FALCONA is intended to be a RISClike machine, only the load/ store instructions
will be allowed to access the memory.
ISA Design Steps Step 8
Next we need to select the memory
addressing modes. The given table lists
the types of addressing modes that will
be supported for the load/store
instructions.
FALCON(A: Introduction
FALCON stands for First Architecture for Learning Computer Organization and
Networks. It is a RISClike generalpurpose processor that will be used as a teaching
aid for this course. Although the FALCONA is a simple machine, it is powerful enough
to explain a variety of fundamental concepts in the field of Computer Architecture .
Programmers view of the FALCON(A
FALCONA, an example of a GPR
(General Purpose Register) computer,
is the first version of the FALCON
processor. The programmers view of
the FALCONA is given in the figure
shown. As it is clear from the figure,
the CPU contains a register file of 8
registers, named R0 through R7. Each
of these registers is 16 bits in length.
Aside from these registers, there are
two specialpurpose registers, the Program Counter (PC), and the Instruction Register
16 16
(IR). The main memory is organized as 2 x 8 bits, i.e. 2 cells of 1 byte each. The
memory word size is 2 bytes (or 16 bits). The input/output space is 256 bytes (8 bit I/O
ports). The storage in these registers and memory is in the bigendian format.
Lecture No. 8
ISA of the FALCON(A
Reading Material
Handouts Slides
Summary
Introduction to the ISA of the FALCON(A
Examples for the FALCON(A
7. jpl (opcode= 16) In this instruction, the value contained in the register specified
in the field ra is checked, and if it is positive, the jump is taken.
jpl r3, [label] (R[3]�0): PC � PC+ (labelPC);
Note that, in all the instructions for jump, the jump can be specified by a constant, a
variable, a label or an address (that holds the value by which the PC is to be advanced).
A variable can be defined through the use of the .equ directive. An address (of data) can
be specified using the directive .db or .dw. A label can be specified with any
instruction. In its usage, we follow the label by a colon : before the instruction itself.
For example, the following is an instruction that has a label alfa attached to it
alfa: movi r3 r4
Labels implement relative jumps, 128 locations backwards or 127 locations forward
(relative to the current position of program control, i.e. the value in the program counter).
The compiler handles the interpretation of the field c2 as a constant/ variable/ label/
address. The machine code just contains an 8bit constant that is added to the program
counter at runtime.
9. jump (opcode= 20)
This instruction instructs the processor to advance the program counter by the
displacement specified, unconditionally (an unconditional jump). The assembler
allows the displacement (or the jump) to be specified in any of the following ways
jump [ra + constant]
jump [ra + variable]
jump [ra + address]
jump [ra + label]
The types of unconditional jumps that are possible are
�� Direct
�� Indirect
�� PC relative (a near jump)
�� Register relative (a far jump)
The c2 field may be a constant, variable, an address or a label.
A direct jump is specified by a PClabel.
An indirect jump is implemented by using the C2 field as a variable.
In all of the above instructions, if the value of the register ra is zero, then the Program
Counter is incremented (or decremented) by the signextended value of the constant
specified in the instruction. This is called the PCrelative jump, or the near jump. It is
denoted in RTL as:
(ra=0):PC� PC+(8�C2<7>)©C2<7..0>;
If the register ra field is nonzero, then the Program Counter is assigned the sum of the
signextended constant and the value of register specified in the field ra. This is known as
the registerrelative, or the far jump. In RTL, this is denoted as:
(ra�0):PC� R[ra]+(8�C2<7>)©C2<7..0>;
Note that C2 is computed by sign extending the constant, variable, address, or (label
PC). Since we have 8 bits available for the C2 field (which can be a constant, variable,
Last Modified: 12Jan11 Page 94
Advanced Computer ArchitectureCS501
address or a PClabel), the range for the field is 128 to + 127. Also note that the compiler
does not allow an instruction with a negative sign before the register name, such as jump
[r2]. If the C2 field is being used as an address, it should always be an even value for
the jump instruction. This is because our instruction word size is 16 bits, whereas in
instruction memory, the instruction memory cells are of 8 bits each. Two consecutive
cells together make an instruction.
Type III
There are nine instructions of the FALCONA that belong to Type III. These are:
1. andi (opcode = 9)
The andi instruction bitwise ands the constant specified in the instruction with
the value stored in the register specified in the second operand register and stores
the result in the destination register. An example is:
andi r4, r3, 5
This instruction will bitwise and the constant 5 and R[3], and assign the value
thus obtained to the register R[4], as given .
R [4] � R [3] & 5
2. addi (opcode = 1)
This instruction is to add a constant value to a register; the result is stored in a
destination register. An example:
addi r4, r3,4 R [4] � R [3] + 4
3. subi (opcode = 3)
The subi instruction will subtract the specified constant from the value stored in a
source register, and store to the destination register. An example follows.
subi r5, r7, 9 R [5] � R [7] 9
4. ori (opcode= 11)
Similar to the andi instruction, the ori instruction bitwise ors a constant with a
value stored in the source register, and assigns it to the destination register. The
following instruction is an example.
ori r4, r7, 3 R[4] � R[7] ~ 3
5. shiftl (opcode = 12)
This instruction shifts the value stored in the source register (which is the second
operand), and shifts the bits left as many times as is specified by the third
operand, the constant value. For instance, in the instruction
shiftl r4, r3, 7
The contents of the register are shifted left 7 times, and the resulting number is
assigned to the register r4.
6. shiftr (opcode = 13)
This instruction shifts to the right the value stored in a register. An example is:
shiftr r4, r3,9
7. asr (opcode = 15)
An arithmetic shift right is an operation that shifts a signed binary number
stored in the source register (which is specified by the second operand), to the
right, while leaving the signbit unchanged. A single shift has the effect of
dividing the number by 2. As the number is shifted as many times as is specified
in the instruction through the constant value, the binary number of the source
register gets divided by the constant value times 2. An example is
asr r1, r2, 5
This instruction, when executed, will divide the value stored in r2 by 10, and
assign the result to the register r1.
8. load (opcode= 29)
This instruction is to load a register from the memory. For instance, the
instruction
load r1, [r4 +15]
will add the constant 15 to the value stored in the register r4, access the memory
location that corresponds to the number thus resulting, and assign the memory
contents of this location to the register r1; this is denoted in RTL by:
R[1] � M[R[4]+15]
9. store (opcode= 28)
This instruction is to store a value in the register to a particular memory location.
In the example:
store r6, [r7+13]
The contents of the register r6 are being stored to the memory location that
corresponds to the sum of the constant 13 and the value stored in the register r7.
M[R[7]+13] � R[6]
Type III Modified
There are 3 instructions in the modified form of the Type III instructions. In the modified
Type III instructions, the field c1 is unused.
1. mov (opcode = 6 )
This instruction will move (copy) data of a source register to a destination
register. For instance, in the following example, the contents of the register r3 are
copied to the register r4.
mov r4, r3
In RTL, this can be represented as
R[4] � R[3]
2. not (opcode = 14 )
This instruction inverts the contents of the source register, and assigns the value
thus obtained to the destination register. In the following example, the contents of
register r2 are inverted and assigned to register r4.
not r4, r2
In RTL:
R[4] � !R[2]
3. call (opcode = 22 )
Procedure calls are often encountered in programming languages. To add support
for procedure (or subroutine) calls, the instruction call is used. This instruction
first stores the return address in a register and then assigns the Program Counter a
new value (that specifies the address of the subroutine). Following is an example
of the call instruction
call r4, r3
This instruction saves the current contents (the return address) of the Program
Counter into the register r4 and assigns the new value to the PC from register r3.
R[4] � PC, PC � R[3]
Type IV
Six instructions belong to the instruction format Type IV. These are
1. add (opcode = 0 )
This instruction adds contents of a register to those of another register, and
assigns to the destination register. An example:
and r4, r3, r5
R[4] � R[3] +R[5]
2. sub (opcode = 2 )
This instruction subtracts value of a register from another the value stored in
another register, and assigns to the destination register. For example,
sub r4, r3, r5
In RTL, this is denoted by
R[4] � R[3] R[5]
3. mul (opcode = 4 )
The multiply instruction will store the product of two register values, and stores in
the destination register. An example is
mul r5, r7, r1
The RTL notation for this instruction will be
R[0] © R[5] � R[7]*R[1]
4. div (opcode= 5)
This instruction will divide the value of the register that is the second operand, by the
number in the register specified by the third operand, and assign the result to the
destination register.
div r4, r7, r2 R[4]�R[0] ©R[7]/R[2],R[0]�R[0] ©R[7]%R[2]
5. and (opcode= 8)
This and instruction will obtain a bitwise and of the values of two registers and
assigns it to a destination register. For instance, in the following example, contents of
register r4 and r5 are bitwise anded and the result is assigned to the register r1.
and r1, r4, r5
In RTL we may write this as
R[1] � R[4] & R[5]
6. or (opcode= 10)
To bitwise or the contents of two registers, this instruction is used. For instance,
or r6, r7,r2
In RTL this is denoted as
R[6] � R[7] ~ R[2]
Solution
The solution to this problem is quite straightforward. The types of these instructions, as
well as the fields, have already been discussed in the preceding sections.
We can also find the machine code for these instructions. The machine code (in the
hexadecimal representation) is given for these instructions in the given table.
Example 2:
Identify the addressing modes and Register Transfer Language (RTL) description
(meaning) for the given FALCONA instructions
Solution
Addressing modes relate to the way architectures specify the address of the objects they
access. These objects may be constants and registers, in addition to memory locations.
Example 3: Specify the condition for the branch instruction and the status of the PC after
the branch instruction executes with a true branch condition
Solution
We have looked at the various jump instructions in our study of the FALCONA. Using
that knowledge, this problem can be solved easily.
Example 4: Specify the binary encoding of the different fields in the given FALCONA
instructions.
Solution
We can solve this problem by referring back to our discussion of the instruction format
types. The opcodes for each of the instructions can also be looked up from the tables. ra,
rb and rc (where applicable) registers values are obtained from the register encoding
table we looked at. The constants C1 and C2 are there in instruction type III and II
respectively. The immediate constant specified in the instruction can also be simply
converted to binary, as shown.
Lecture No. 9
Description of FALCON(A and EAGLE using RTL
Reading Material
Handouts Slides
Summary
4) Use of Behavioral Register Transfer Language (RTL) to describe the
FALCONA
5) The EAGLE
6) The Modified EAGLE
Specifying Registers
In RTL, we will refer to a register by its abbreviated, alphanumeric name, followed by
the number of bits in the register enclosed in angle brackets < >. For instance, the
instruction register (IR), of 16 bits (numbered 0 to 15), will be referred to as,
IR<15..0>
Naming of the Fields in a Register
We can name the different fields of a register using the := notation. For example, to name
the most significant bits of the instruction register as the operation code (or simply op),
we may write:
op<4..0> := IR<15..11>
Note that using this notation to name registers or register fields will not create a new copy
of the data or the register fields; it is simply an alias for an already existing register, or
part of a register.
Fields in the FALCON(A Instructions
We now use the RTL naming operator to name the various fields of the RTL instructions.
Naming the fields appropriately helps us make the study of the behavior of a processor
more readable.
op<4..0>:= IR<15..11>: operation code field
ra<2..0> := IR<10..8>: target register field
rb<2..0> := IR<7..5>: operand or address index
rc<2..0> := IR<4..2>: second operand
c1<4..0> := IR<4..0>: short displacement field
c2<7..0> := IR<7..0>: long displacement or the immediate field
We are already familiar with these fields, and their usage in the various instruction
formats of the RTL.
Describing the Processor State using RTL
The processor state defines the contents of all the register internal to the CPU at a given
time. Maintaining or restoring the machine or processor state is important to many
operations, especially procedure calls and interrupts; the processor state needs to be
restored after a procedure call or an interrupt so normal operation can continue.
Our processor state consists of the following:
PC<15..0>: program counter (the PC holds the memory address of the next
instruction)
IR<15..0>: instruction register (used to hold the current instruction)
Run: one bit run/halt indicator
Strt: start signal
R [0..7]<15..0>: 8 general purpose registers, each consisting of 16 bits
FALCON(A in a black
box
The given figure shows
what a processor appears as
to a user. We see a start
button that is basically used
to start up the processor,
and a run indicator that
turns on when the processor
is in the running state.
Last Modified: 12Jan11 Page 105
Advanced Computer ArchitectureCS501
There may be several other indicators as well. The start button as well as the run indicator
can be observed on many machines.
Using RTL to describe the dynamic properties of the FALCON(A
We have just described some of the static properties of the FALCONA. The RTL can
also be employed to describe the dynamic behavior of the processor in terms of
instruction interpretation and execution.
Conditional expressions can be specified using the RTL. For instance, we may specify a
We will now employ the notation that we have learnt to understand the fetchexecute
We again highlight the difference between the , and ;. Statements separated by a ,
take place during the same clock pulse. In other words, the order of execution of
statements separated by , does not matter.
On the other hand, statements separated by a ; take place on successive clock pulses. In
other words, if statements are separated by ; the one on the left must complete before
the one on the right starts. However, some things written with one RTL statement can
take several clocks to complete.
We return to our discussion of the instructionfetch phase. The statement
!Run&Strt : Run � 1
is executed when Run is 0, and Strt is 1, that is, Strt has been set. It is used to set the
Run bit. No action takes place when both Run and Strt are 0.
The following two concurrent register transfers are performed when Run is set to 1, (as
: is a conditional operator; if the condition is met, the specified action is taken).
IR � M[PC]
PC � PC + 2
Since these instructions appear concurrent, and one of the instructions is using the value
of PC that the other instruction is updating, a question arises; which of the two values of
the PC is used in the memory access? As a rule, all right hand sides of the register
transfers are evaluated before the left hand side is evaluated/updated. In case of
simultaneous register transfers (separated by a ,), all the right hand side expressions are
evaluated in the same clockcycle, before they are assigned. Therefore, the old, un
incremented value of the PC is used in the memory access, and the incremented value is
assigned to the PC afterwards. This corresponds to masterslave flipflop operation in
logic circuits.
This makes the PC point to the next instruction in the instruction memory. Once the
instruction has been fetched, the instruction execution starts. We can also use i.F for
Last Modified: 12Jan11 Page 107
Advanced Computer ArchitectureCS501
instruction_Fetch and i.E for instruction_Execution. This will make the Fetch operation
easy to write.
iF := ( !Run&Strt : Run � 1, Run : (IR � M[PC], PC � PC + 2;
iE ) );
Instruction Execution (Describing the Execute operation using RTL)
Once an instruction has been fetched from the instruction memory, and the program
counter has been incremented to point to the next instruction in the memory, instruction
execution commences. In the instruction fetchexecute cycle we showed in the preceding
discussion, the entire instruction execution code was aliased iE (or
instruction_Execution), through the assignment operator :=. Now we look at the
instruction execution in detail.
iE := (
(op<4..0>= 1) : R[ra] � R[rb]+ (11� c1<4>)© c1<4..0>,
(op<4..0>= 2) : R[ra] � R[rb](R[rc],
...
...
(op<4..0>=31) : Run � 0,); iF );
As we can see, the instruction execution can be described in RTL by using a long list of
concurrent, conditional operators that are inherently disjoint. Being inherently
disjointed implies that at any instance, only one of the conditions can be met; hence one
of the statements is executed. The long list of statements is basically all of the
instructions that are a part of the FALCONA instruction set, and the condition for their
execution is related to the operation code of the instruction fetched. We will take a closer
look at the entire list in our subsequent discussion. Notice that in the instruction execute
phase, besides the long list of concurrent,
disjoint instructions, there is also the
instruction fetch or iF sequenced at the
end. This implies that once one of the
instructions from the list is executed, the
instruction fetch is called to fetch the next
instruction. As shown before, the
instruction fetch will call the instruction
execute after fetching a certain instruction,
hence the instruction fetchexecute cycle
continues.
The instruction fetchexecute cycle is shown schematically in the above given figure.
We now see how the various instructions in the execute code of the fetchexecute cycle
of FALCONA, are represented using the RTL. These instructions form the instruction
set of the FALCONA.
jump instructions
Some of the instructions listed for the instruction execution phase are jump instruction, as
shown. (Note . . . implies that more instructions may precede or follow, depending on
whether it is placed before the instructions shown, or after).
iE := (
. . .
. . .
If opcode is 20, the branch is taken unconditionally (the jump instruction).
(op<4..0>=20) : (cond PC � R[ra]+C2(sign extended)),
Last Modified: 12Jan11 Page 108
Advanced Computer ArchitectureCS501
If the opcode is 16, the condition for branching is checked, and if the condition is being
met, the branch is taken; otherwise it remains untaken, and normal program flow will
continue.
(op<4..0>= 16) : cond : (PC � PC+C2 (sign extended ))
. . .
. . .
Arithmetic and Logical Instructions
Several instructions provide arithmetic and logical operations functionality. Amongst the
list of concurrent instructions of the iE phase, the instructions belonging to this category
are highlighted:
iE := (
. . .
. . .
If opcode is 0, the instruction is add. The values in register rb and rc are added and the
result is stored in register ra
(op<4..0>=0) : R[ra] � R[rb] + R[rc],
Similarly, if opcode is 1, the instruction is addi; the immediate constant specified by the
constant field C1 is sign extended and added to the value in register rb. The result is
stored in the register ra.
(op<4..0>=1) : R[ra] �R[rb] + (11� C1<4>)© C1<4..0>,
For opcode 2, value stored in register rc is subtracted from the value stored in register rb,
and the result is stored in register ra.
(op<4..0>=2) : R[ra] � R[rb] ( R[rc],
If opcode is 3, the immediate constant C1 is signextended, and subtracted from the
value stored in rb. Result is stored in ra.
(op<4..0>=3) : R[ra] � R[rb]( (11� C1<4>)© C1<4..0>,
For opcode 4, values of rb and rc register are multiplied and result is stored in the
destination register.
(op<4..0>=4) : R[ra] � R[rb] * R[rc],
If the opcode is 5, contents of register rb are divided by the value stored in rc, result is
concatenated with 0s, and stored in ra. The remainder is stored in R0.
(op<4..0>=5) : R[ra] � R[0] ©R[rb]/R[rc],
R[0] � R[0] ©R[rb]%R[rc],
If opcode equals 8, bitwise logical AND of rb and rc register contents is assigned to ra.
(op<4..0>=8) : R[ra] � R[rb] & R[rc],
If opcode equals 8, bitwise logical OR of rb and rc register contents is assigned to ra.
(op<4..0>=10) : R[ra] � R[rb] ~ R[c],
For opcode 14, the contents of register specified by field rc are inverted (logical NOT is
taken), and the resulting value is stored in register ra.
(op<4..0>=14) : R[ra] � ! R[rc],
. . .
. . .
Shift Instructions
The shift instructions are also a part of the instruction set for FALCONA, and these are
listed in the instruction execute phase in the RTL as shown.
iE := (
. . .
Last Modified: 12Jan11 Page 109
Advanced Computer ArchitectureCS501
. . .
If the opcode is 12, the contents of the register rb are shifted right N bits. N is the
number specified in the constant field. The space that has been created due to the shift out
of bits is filled with 0s through concatenation. In RTL, this is shown as:
(op<4..0>=12) : R[ra]<15..0> � R [rb]<(15(N)..0>©(N�0),
If opcode is 13, rb value is shifted left, and 0s are inserted in place of shifted out
contents at the right side of the value. The result is stored in ra.
(op<4..0>=13) : R[ra]<15..0> � (N�0)©R [rb]<(15)..N>,
For opcode 15, arithmetic shift right operation is carried out on the value stored in rb.
The arithmetic shift right shifts a signed binary number stored in the source register to the
right, while leaving the signbit unchanged. Note that � means replication, and © means
concatenation.
(op<4..0>=15) : R[ra]<15..0> � N�(R [rb]<15>)© (R [rb]<15..N>),
. . .
. . .
Data transfer instructions
Several of the instructions belong to the data transfer category.
iE := (
. . .
. . .
Opcode 29 specifies the load instruction, i.e. a memory location is referenced and the
value stored in the memory location is copied to the destination register. The effective
address of the memory location to be referenced is calculated by sign extending the
immediate field, and adding it to the value specified by register rb.
(op<4..0>=29) : R[ra]� M[R[rb]+ (11� C1<4>)© C1<4..0>],
A value is stored back to memory from a register using the opcode 28. The effective
address in memory where the value is to be stored is calculated in a similar fashion as the
load instruction.
(op<4..0>=28) : M[R[rb]+ (11� C1<4>)© C1<4..0>] � R [ra],
The move instruction has the opcode 6. The contents of one register are copied to
another register through this instruction.
(op<4..0>=6) : R[ra] � R[rb],
To store an immediate value (specified by the field C2 of the instruction) in a register, the
opcode 7 is employed. The constant is first signextended.
(op<4..0>=7) : R[ra] � (8�C2<7>)©C2<7..0>,
If the opcode is 24, an input is obtained from a certain input device, and the input word
is stored into register ra. The input device is selected by specifying its address through the
constant C2.
. . .
Miscellaneous instructions
Some more instruction included in the FALCON(A are
iE := (
. . .
. . .
The nooperation (nop) instruction, if the opcode is 21. This instructs the processor to do
nothing.
(op<4..0>= 21) : ,
If the opcode is 31, setting the run bit to 0 halts the processor.
(op<4..0>= 31) : Run � 0, Halt the processor (halt)
At the end of this concurrent list of instructions, there is an instruction i.F (the instruction
fetch). Hence when an instruction is executed, the next instruction is fetched, and the
cycle continues, unless the processor is halted.
); iF );
The EAGLE
(Original version)
Another processor that we are going to study is the EAGLE. We have developed two
versions of it, an original version, and a modified version that takes care of the limitations
in the original version. The study of multiple processors is going to help us get
thoroughly familiar with the processor design, and the various possible designs for the
processor. However, note that these machines are simplified versions of what a real
machine might look like.
Introduction
The EAGLE is an accumulatorbased machine. It is a simple processor that will help us
in our understanding of the processor design process.
EAGLE is characterized by the following:
�� Eight General Purpose Registers of the CPU. These are named R0, R1
R7. Each
register is 16bits in length.
�� Two 16bit system registers transparent to the programmer are the Program
Counter (PC) and the Instruction Register (IR). (Being transparent to the
programmer implies the programmer may not directly manipulate the values to
these registers. Their usage is the same as in any other processor)
�� Memory word size is 16 bits
�� The available memory space size is 216 bytes
�� Memory organization is 216 x 8 bits. This means that there are 216 memory cells,
each one byte long.
�� Memory is accessed in 16 bit words (i.e., 2 byte chunks)
�� Littleendian byte storage is employed.
EAGLE Features
The following features characterize the EAGLE.
�� Instruction length is variable. Instructions are either 8 bits or 16 long, i.e.,
instruction size is either 8bits or 16bits.
�� The instructions may have either one or two operands.
�� The only way to access memory is through load and store instructions.
�� Limited addressing modes are supported
EAGLE: Instruction Formats
There are five instruction formats for the EAGLE. These are
Type Z Instruction Format
The Z format instructions are halfword (1 byte)
instructions, containing just the opcode field of 8 bits,
as shown
Type Y Instruction Format
The type Y instructions are also halfword. There is
an opcode field of 5 bits, and a register operand field
ra.
Type Z
There are four type Z instructions,
�� halt(opcode=250)
This instruction halts the processor
�� nop(opcode=249)
nop, or the nooperation instruction stalls the processor for the time of execution
of a single instruction. It is useful in pipelining.
�� init(opcode=251)
This instruction is used to initialize all the registers, by setting them to 0
�� reset(opcode=248)
This instruction is used to initialize the processor to a known state.In this
instruction the control step counter is set to zero so that the operation begins at the
start of the instruction fetch and besides this PC is also set to a known value so
that machine operation begins at a known instruction.
Type Y
Seven instructions of the processor are of type Y. These are
�� add(opcode=11)
The type Y add instruction adds register ras contents to register R0. For example,
add r1
�� and(opcode=19)
This instruction obtains the logical AND of the value stored in register specified
by field ra and the register R0, and assigns the result to R0, as shown in the
example:
and r5
which is represented in RTL as
R[0] � R[1]&R[0]
�� div(opcode=16)
This instruction divides the contents of register R0 by the value stored in the
register ra, and assigns result to R0. The remainder is stored in the divisor
register, as shown in example,
div r6
In RTL, this is
R[0] � R[0]/R[6]
R[6] � R[0]%R[6]
�� mul (opcode = 15)
This instruction multiplies the values stored in register R0 and the operand
register, and assigns the result to R0). For example,
mul r4
In RTL, we specify this as
R[0] � R[0]*R[4]
�� not (opcode = 23)
The not instruction inverts the operand registers value and assigns it back to the
same register, as shown in the example
not r6
R[6] � ! R[6]
�� or (opcode=21)
The or instruction obtains the bitwise OR of the operand registers and R0s
value, and assigns it back to R0. An example,
or r5
R[0] � R[0] ~ R[5]
�� sub (opcode=12)
The sub instruction subtracts the value of the operand register from R0 value,
assigning it back to register R0. Example:
sub r7
In RTL:
R[0] � R[0] R[7]
Type X
Only one instruction falls under this type. It is the mov instruction that is useful for
register transfers
�� mov (opcode = 0)
The contents of one register are copied to the destination register ra.
Example: mov r5, r1
RTL Notation: R[5]� R[1]
Type W
Again, only one instruction belongs to this type. It is the branch instruction
�� br (opcode = 252)
This is the unconditional branch instruction, and the branch target is specified by
the 8bit immediate field. The branch is taken by incrementing the PC with the
new value. Hence it is a near jump. For instance,
br 14
PC � PC+14
Type V
Most of the instructions of the processor EAGLE are of the format type V. These are
�� addi (opcode = 13)
The addi instruction adds the immediate value to the register ra, by first sign
extending the immediate value. The result is also stored in the register ra. For
example,
addi r4, 31
In behavioral RTL, this is
R[4] � R[4]+(8�c<7>)©c<7
0>;
�� andi (opcode = 20 )
Logical AND of the immediate value and register ra value is obtained when this
instruction is executed, and the result is assigned back to register ra. An example,
andi r6, 1
R[6] � R[6] &1
�� in (opcode=29)
This instruction is to read in a word from an IO device at the address specified by
the immediate field, and store it in the register ra. For instance,
in r1, 45
In RTL this is
R[1] � IO[45]
�� load (opcode=8)
The load instruction is to load the memory word into the register ra. The
immediate field specifies the location of the memory word to be read. For
instance,
load r3, 6
R[3] � M[6]
�� brn (opcode = 28)
Upon the brn instruction execution, the value stored in register ra is checked, and
if it is negative, branch is taken by incrementing the PC by the immediate field
value. An example is
brn r4, 3
In RTL, this may be written as
if R[4]<0, PC � PC+3
�� brnz (opcode = 25 )
For a brnz instruction, the value of register ra is checked, and if found nonzero,
the PCrelative branch is taken, as shown in the example,
brnz r6, 12
Which, in RTL is
if R[6]!=0, PC � PC+12
Last Modified: 12Jan11 Page 117
Advanced Computer ArchitectureCS501
�� brp (opcode=27)
brp is the branch if positive. Again, ra value is checked and if found positive, the
PCrelative near jump is taken, as shown in the example:
brp r1, 45
In RTL this is
if R[1]>0, PC � PC+45
�� brz (opcode=8)
In this instruction, the value of register ra is checked, and if it equals zero, PCrelative
branch is taken, as shown,
brz r5, 8
In RTL:
if R[5]=0, PC � PC+8
�� loadi (opcode=9)
The loadi instruction loads the immediate constant into the register ra, for
instance,
loadi r5,54
R[5] � 54
�� ori (opcode=22)
The ori instruction obtains the logical OR of the immediate value with the ra
register value, and assigns it back to the register ra, as shown,
ori r7, 11
In RTL,
R[7] � R[7]~11
�� out (opcode=30)
The out instruction is used to write a register word to an IO device, the address of
which is specified by the immediate constant. For instance,
out 32, r5
In RTL, this is represented by
IO[32] � R[5]
�� shiftl (opcode=17)
This instruction shifts left the contents of the register ra, as many times as is
specified through the immediate constant of the instruction. For example:
shiftl r1, 6
�� shiftr( opcode=18)
This instruction shifts right the contents of the register ra, as many times as is
specified through the immediate constant of the instruction. For example:
shiftr r2, 5
�� store (opcode=10)
The store instruction stores the value of the ra register to a memory location
specified by the immediate constant. An example is,
store r4, 34
RTL description of this instruction is
M[34] � R[4]
�� subi (opcode=14)
The subi instruction subtracts the immediate constant from the value of register
ra, assigning back the result to the register ra. For instance,
subi r3, 13
Last Modified: 12Jan11 Page 118
Advanced Computer ArchitectureCS501
Instruction formats
There are four instruction format types
in the modified EAGLE processor as
well. These are
Lecture No. 10
The FALCON(E and ISA Comparison
Reading Material
Handouts Slides
Summary
3) The FALCONE
4) Instruction Set Architecture Comparison
THE FALCON(E
Introduction
FALCON stands for First Architecture for Learning Computer Organization and
Networks. We are already familiar with our example processor, the FALCONA, which
was the first version of the FALCON processor. In this section we will develop a new
version of the processor. Like its predecessor, the FALCONE is a GeneralPurpose
Register machine that is simple, yet is able to elucidate the fundamentals of computer
design and architecture.
The FALCONE is characterized by the following
�� Eight General Purpose Registers (GPRs), named R0, R1
R7. Each registers is 4
bytes long (32bit registers).
�� Two special purposes registers, named BP and SP. These registers are also 32bit
in length.
�� Two special registers, the Program Counter (PC) and the Instruction Register
(IR). PC points to the next instruction to be executed, and the IR holds the current
instruction.
�� Memory word size is 32 bits (4
bytes).
�� Memory space is 232 bytes
�� Memory is organized as 1byte
cells, and hence it is 232 x 8
bits.
�� Memory is accessed in 32bit
words (4byte chunks, or 4
consecutive cells)
�� Byte storage format is little
endian.
Type B instructions
The type B instructions also have 5 bits (27 through 31) reserved for the opcode. There
is a register operand field, ra, and an immediate or displacement field in addition to the
opcode field.
Type C instructions
Type C instructions have the 5bit opcode field, two 3bit operand registers (rb is the
source register, ra is the destination register), a 17bit immediate or displacement field, as
well as a 3bit function field. The function field is used to differentiate between
instructions that may have the same opcode, but different operations.
Type D instructions
Type D instructions have the 5bit opcode field, three 3bit operand registers, 14 bits are
unused, and a 3bit function field.
There are two more special registers that we need to represent; the SP and the BP. We
will use these registers in place of the operand register rb in the load and store
instructions only, and therefore, we may encode these as
Type A instructions
Four instructions of the FALCONE belong to type A. These are
�� nop (opcode = 0)
This instruction instructs the processor to do nothing. It is generally useful in
pipelining. We will study more on pipelining later in the course.
�� ret (opcode = 15)
The return instruction is used to return control to the normal flow of a program
after an interrupt or a procedure call concludes
�� iret (opcode = 17)
The iret instruction instructs the processor to return control to the address
specified by the immediate field of the instruction. Setting the program counter to
the specified address returns control.
�� near jmp (opcode = 18)
A near jump is a PCrelative jump. The PC value is incremented (or decremented)
by the immediate field value to take the jump.
Type B instructions
Five instructions belong to the type B format of instructions. These are:
�� push (opcode = 8)
This instruction is used to push the contents of a register onto the stack. For
instance, the instruction,
push R4
will push the contents of register R4 on top of the stack
�� pop (opcode = 9)
The pop instruction is used to pop a value from the top of the stack, and the value
is read into a register. For example, the instruction
pop R7
will pop the uppermost element of the stack and store the value in register R7
�� ld (opcode = 10)
This instruction with opcode (10) loads a memory word from the address
specified by the immediate filed value. This word is brought into the operand
register ra. For example, the instruction,
ld R7, 1254h
will load the contents of the memory at the address 1254h into the register R7.
�� st (opcode = 12)
The store instruction of (opcode 12) stores a value contained in the register
operand into the memory location specified by the immediate operand field. For
example, in
st R7, 1254h
the contents of register R7 are saved to the memory location 1254h.
Type C instructions
There are four data transfer instructions, as well as nine ALU instructions that belong to
type C instruction format of the FALCONE.
The data transfer instructions are
�� lds (opcode = 4)
The load instruction with opcode (4)loads a register from the memory, after
calculating the address of the memory location that is to be accessed. The
effective address of the memory location to be read is calculated by adding the
immediate value to the value stored by the register rb. For instance, in the
Last Modified: 12Jan11 Page 127
Advanced Computer ArchitectureCS501
example below, the immediate value 56 is added to the value stored by the
register R4, and the resultant value is the address of the memory location which is
read
lds R3, R4(56)
In RTL, this can be shown as
R [3] M[R [4]+56]
�� sts (opcode = 5)
This instruction is used to store the register contents to the memory location, by
first calculating the effective memory address. The address calculation is similar
to the lds instruction. An example:
sts R3, R4 (56)
In RTL, this is shown as
M[R [4]+56] R [3]
�� in (opcode = 6)
This instruction is to load a register from an input/output device. The effective
address of the I/O device has to be calculated before it is accessed to read the
word into the destination register ra, as shown in the example:
in R5, R4(100)
In RTL:
R[5] IO[R[4]+100]
�� out (opcode = 7)
This instruction is used to write / store the register contents into an input/output
device. Again, the effective address calculation has to be carried out to evaluate
the destination I/O address before the write can take place. For example,
out R8, R6 (36)
RTL representation of this is
IO[R [6]+36] R [8]
Three of the ALU instructions that belong to type C format are
�� addi (opcode = 2)
The addi instruction is to add a constant to the value of operand register rb, and
assign the result to the destination register ra. For example, in the following
instruction, 56 is added to the value of register R4, and result is assigned to the
register R3.
addi R3, R4, 56
In RTL this can be shown as
R[3] R[4]+56
Note that if the immediate constant specified was a negative number, then this
would become a subtract operation.
�� andi (opcode = 2)
This instruction is to calculate the logical AND of the immediate value and the rb
register value. The result is assigned to destination register ra. For instance
andi R3, R4, 56
R[3] R[4]&56
Note that the logical AND is represented by the symbol &
�� ori (opcode = 2)
This instruction calculates the logical OR of the immediate field and the value in
operand register rb. The result is assigned to the destination register ra. Following
is an example:
ori R3, R4, 56
The RTL representation of this instruction:
R [3] R [4]~56
Note that the symbol ~ is used to represent logical OR.
Type D Instructions
Four of the instructions that belong to this instruction format type are the ALU
instructions shown below. There are other instructions of this type as well, listed in the
tables at the end of this section.
�� add (opcode = 1)
This instruction is used to add two numbers. The numbers are stored in the registers
specified by rb and rc. Result is stored into register ra. For instance, the instruction,
add R3, R5, R6
adds the numbers in register R5, R6, storing the result in R3. In RTL, this is given by
R [3] R [5] + R [6]
�� sub (opcode = 1)
This instruction is used to carry out 2s complement subtraction. Again, register
addressing mode is used, as shown in the example instruction
sub R3, R5, R6
RTL representation of this is
R[3] R[5] R[6]
�� and (opcode = 1)
For carrying out logical AND operation on the values stored in registers, this
instruction is employed. For instance
and R8, R3, R4
In RTL, we can write this as
R [8] R [3] & R [4]
�� or (opcode = 1)
For evaluating logical OR of values stored in two registers, we use this
instruction. An example is
or R8, R3, R4
In RTL, this is
R [8] R [3] ~ R [4]
Falcon(E
Instruction Summary
The following are the tables that list the instructions that form the instruction set of the
FALCONE. These instructions have been grouped with respect to the functionality they
provide.
Instruction Length
With reference to the instruction lengths in a particular ISA, there are two decisions to be
made; whether the instruction will be fixed in length or variable, and what will be the
instruction length or the range (in case of variable instruction lengths).
Instruction Length
The required instruction length mainly depends on the number of instruction required to
be in the instruction set of a processor (the greater the number of instructions supported,
the more bits are required to encode the operation code), the size of the register file
(greater the number of registers in the register file, more is the number of bits required to
encode these in an instruction), the number of operands supported in instructions (as
obviously, it will require more bits to encode a greater number of operands in an
instruction), the size of immediate operand field (the greater the size, the more the range
of values that can be specified by the immediate operand) and finally, the code density
(which implies how many instructions can be encoded in a given number of bits).
A summary of the instruction lengths of our processors is given in the table below.
length and code density. The maximum number of operands supported by the instruction
set of each processor under study is given in the given table. So FALCONA, FALCON
E and the SRC processors may have 3, 2, 1 or no operands, depending on the instruction.
EAGLE has a maximum number of 2 operands; it may have one operand or no operands
in an instruction.
Explicit operand specification in an instruction gives flexibility in storage. Implicit
operands like an accumulator or a stack reduces the instruction size, as they need not be
coded into the instruction. Instructions of the processor EAGLE have implicit operands,
and we saw that the result is automatically stored in the accumulator, without the
accumulator being specified as a destination operand in the instruction.
Number and Size of General Purpose Registers
While designing a processor, another decision that has to be made is about the number of
registers present in the register file, and the size of the registers.
Increasing the number of registers in the register file of the CPU will decrease the
memory traffic, which is a desirable attribute, as memory accesses take relatively much
longer time than register access. Memory traffic decreases as the number of registers is
increased, as variables are copied into the registers and these do not have to be accessed
from memory over and over again. If there is a small number of registers, the values
stored previously will have to be saved back to memory to bring in the new values; more
registers will solve the problem of swapping in, swapping out. However, a very large
register file is not feasible, as it will require more bits of the instruction to encode these
registers. The size of the registers affects the range of values that can be stored in the
registers.
The number of registers in the register file, along with the size of the registers, for each of
the processors under study, is in the given table.
Memory specifications
Memory design is an integral part of the processor design. We need to decide on the
memory space that will be available to the processor, how the memory will be organized,
memory word size, memory access bus width, and the storage format used to store words
in memory. The memory specifications for the processor under comparison are:
Following are the data transfer instructions included in the instruction sets of our
processors.
Register to register transfers
As we can see from the given table on the next page, in the processor EAGLE, register to
register transfers are of two types only: register to accumulator, or accumulator to
register. Accumulator is a specialpurpose register.
FALCONA has a mov instruction, which can be used to move data of any register to any
other register. FALCONE has the instructions lds and sts which are used to load/store
a register from/to memory after effective address calculation.
SRC does not provide any instruction for data movement between generalpurpose
registers. However, this can be accomplished indirectly, by adopting either of the
following two approaches:
�� A registers contents can be loaded into another register via memory. First storing
the content of a register to a particular memory location, and then reading the
contents of the memory from that location into the register we want to copy the
value to can achieve this. However, this method is very inefficient, as it requires
memory accesses, which are inherently slow operations.
�� A better method is to use the addi instruction with the constant set to 0.
Register to memory
EAGLE has instructions to load values from memory to the special purpose register,
names the accumulator, as well as saving values from the accumulator to memory. Other
register to memory transfers is not possible in the EAGLE processor. FALCONA,
FALOCNE and the SRC have simple load, store instructions and all registermemory
transfers are supported.
Memory to memory
In any of the processors under study, memorytomemory transfers are not supported.
However, in other processors, these may be a possibility.
otherwise the program flow may continue linearly. The branch conditions may be
specified by any of the following methods:
�� Condition codes
�� Condition register
�� Comparison and branching
Condition codes
The ALU may contain some special bits (also called flags), which may have been set (or
raised) under some special circumstances. For instance, a flag may be raised if there is an
overflow in the addition results of two register values, or if a number is negative. An
instruction can then be ordered in the program that may change the flow depending on
any of these flags values. The EAGLE processor uses these condition codes for branch
condition evaluation.
Condition register
A special register is required to act as a branch register, and any other arbitrary register
(that is specified in the branch instruction), is compared against that register, and the
branching decision is based on the comparison result of these two registers. None of the
processors under our study use this mode of conditional branching.
Compare and branch
In this mode of conditional branching, comparison is made part of the branching
instruction. Therefore, it is somewhat more complex than the other two modes. All the
processors we are studying use this mode of conditional branching.
Size of jumps
Jumps are deviations from the linear program flow by a specified constant. All our
processors, except the SRC, support PCrelative jumps. The displacement (or the jump)
relative to the PC is specified by the constant field in the instruction. If the constant field
is wider (i.e. there are more bits reserved for the constant field in the instruction), the
jump can be of a larger magnitude. Shown table specifies the displacement size for
various processors.
Addressing Modes
All processors support a variety of addressing modes. An addressing mode is the method
by which architectures specify the address of an object they will access. The object may
be a constant, a register or a location in memory.
Common addressing modes are
�� Immediate
An immediate field may be provided in instructions, and a constant value may be
given in this immediate field, e.g. 123 is an immediate value.
�� Register
A register may contain the value we refer to in an instruction, for instance,
register R4 may contain the value being referred to.
�� Direct
By direct addressing mode, we mean the constant field may specify the location
of the memory we want to refer to. For instance, [123] will directly refer to the
memory location 123s contents.
�� Register Indirect
A register may contain the address of memory location to which we want to refer
to, for example, M [R3].
�� Displacement
In this addressing mode, the constant value specified by the immediate field is
added to the register value, and the resultant is the index of memory location that
is referred to, e.g. M [R3+123]
�� Relative
Relative addressing mode implies PCrelative addressing, for example, [PC+123]
will refer to the memory location that is 123 words farther than the memory index
currently stored in the program counter.
�� Indexed or scaled
The values contained in two registers are added and the resultant value is the
index to the memory location we refer to, in the indexed addressing mode. For
example, M [[R1]+[R2]]. In the scaled addressing mode, a register value may be
scaled as it is added to the value of the other register to obtain the index of
memory location to be referred to.
�� Auto increment/ decrement
In the auto increment mode, the value held in a register is used as the index to
memory location that holds the value of operand. After the operands value is
retrieved, the register value is automatically increased by 1 (or by any specified
constant). e.g. M [R4]+, or M [R4]+d. In the auto decrement mode, the register
value is first decremented and then used as a reference to the memory location
that referred to in the instruction, e.g. (M [R4].
As may be obvious to the reader, some of these addressing modes are quite simple, others
are relatively complex. The complex addressing modes (such as the indexed) reduce the
instruction count (thus improving code density), at the cost of more complex
implementation.
The given table lists the addressing modes supported by the processors we are studying.
Note that the registeraddressing mode is a special case of the relative addressing mode,
with the constant equal to 0, and only the PC can be used as a source. Also note that, in
the shown table, relative implies PCrelative.
The given table lists the size of the immediate field in our processors.
FALCON(E
The instructions unique to the FALCONE processor are listed:
�� push
To push the contents of a specified general purpose register to the stack
�� pop
To pop the value that is at the top of the stack
�� ldr
To load a register with memory contents using displacement addressing mode
�� str
To store a register value into memory, using displacement addressing mode
�� bl
To branch if source operand is less than target address
�� bg
To branch if source operand is greater than target address
�� muli
To multiply an immediate value with a value stored in a register
�� divi
To divide a register value by the immediate value
�� xor, xori
To evaluate logical exclusive or
�� ror, rori
SRC
Following are the instructions that are unique to the SRC processor, among of the
processors under study
�� ldr
To load register from memory using PCrelative address
�� lar
To load a register with a word from memory using relative address
�� str
To store register value to memory using relative address
�� brlnv
This instruction is to tell the processor to never branch at that point in program.
The instruction saves the program counters contents to the register specified
�� brlpl
This instruction instructs the processor to branch to the location specified by a
register given in the instruction, if the condition registers value is positive.
Return address is saved before branching.
�� brlmi
This instruction instructs the processor to branch to the location specified by a
register given in the instruction, if the condition registers value is negative.
Return address is saved before branching.
�� brlzr
This instruction instructs the processor to branch to the location specified by a
register given in the instruction, if the condition registers value equals zero.
Return address is saved before branching.
�� brlnz
This instruction instructs the processor to branch to the location specified by a
register given in the instruction, if the condition registers value does not equal
zero. Return address is saved before branching.
Problem Comparison
Given is the code for a simple C statement:
a=(b2)+4c
The given table gives its implementation in all the four processors under comparison.
Note that this table highlights the code density for each of the processors; EAGLE, which
has relatively fewer specialized instructions, and so it takes more instructions to carry out
this operation as compared with the rest of the processors.
Lecture No. 11
CISC and RISC
Reading Material
Vincent P. Heuring&Harry F. Jordan Chapter 3
Computer Systems Design and Architecture 3.3, 3.4
Summary
5) A CISC microprocessor:The Motorola MC68000
6) A RISC Architecture:The SPARC
Lecture No. 12
CPU Design
Reading Material
Vincent P. Heuring&Harry F. Jordan Chapter 4
Computer Systems Design and Architecture 4.1, 4.2, 4.3
Summary
7) The design process
8) A UniBus implementation for the SRC
9) Structural RTL for the SRC instructions
During the design procedure we specify the implementation details at an advanced level.
These details can affect the clock cycle per instruction and the clock cycle time. Hence
following things should be kept in mind during the design phase.
�� Effect on overall performance
�� Amount of control hardware
�� Development time
Processor Design
Let us take a look at the steps involved in the processor design procedure.
1. ISA Design
The first step in designing a processor is the specification of the instruction set of
the processor. ISA design includes decisions involving number and size of
instructions, formats, addressing modes, memory organization and the
programmers view of the CPU i.e. the number and size of general and special
purpose registers.
2. Behavioral RTL Description
In this step, the behavior of processor in response to the specific instructions is
described in register transfer language. This abstract description is not bound to
any specific implementation of the processor. It presents only those static
(registers) and dynamic aspects (operations) of the machine that are necessary to
understand its functionality. The unit of activity here is the instruction execution
unlike the clock cycle in actual case. The functionality of all the instructions is
described here in special register transfer notation.
3. Implementation of the Data Path
The data path design involves decisions like the placement and interconnection of
various registers, the type of flipflops to be used and the number and kind of the
interconnection buses. All these decisions affect the number and speed of register
transfers during an operation. The structure of the ALU and the design of the
memorytoCPU interface also need to be decided at this stage. Then there are the
control signals that form the interface between the data path and the control unit.
These control signals move data onto buses, enable and disable flipflops, specify
the ALU functions and control the buses and memory operations. Hence an
integral part of the data path design is the seamless embedding of the control
signals into it.
4. Structural RTL Description
In accordance with the chosen data path implementation, the structural RTL for every
instruction is described in this step. The structural RTL is formed according to the
proposed microarchitecture which includes many hidden temporary registers
necessary for instruction execution. Since the structural RTL shows the actual
implementation steps, it should satisfy the time and space requirements of the CPU as
specified by the clocking interval and the number of registers and buses in the data
path.
5. Control Unit Design
The control unit design is a rather tricky process as it involves timing and
synchronization issues besides the usual combinational logic used in the data path
design. Additionally, there are two different approaches to the control unit design; it
2. MAR
The Memory Address Register takes input from the ALSU as the address of the
memory location to be accessed and transfers the memory contents on that
location onto the memory subsystem.
3. MBR
The Memory Buffer Register has a bidirectional connection with both the
memory subsystem and the registers and ALSU. It holds the data during its
transmission to and from memory.
4. PC
The Program Counter holds the address of the next instruction to be executed. Its
value is incremented after loading of each instruction. The value in PC can also be
changed based on a branch decision in ALSU. Therefore, it has a bidirectional
connection with the internal processor bus.
5. IR
Last Modified: 12Jan11 Page 151
Advanced Computer ArchitectureCS501
The Instruction Register holds the instruction that is being executed. The
instruction fields are extracted from the IR and transferred to the appropriate
registers according to the external circuitry (not shown in this diagram).
6. Registers A and C
The registers A and C are required to hold an operand or result value while the
bus is busy transmitting some other value. Both these registers are programmer
invisible.
7. ALSU
There is a 32bit Arithmetic Logic Shift Unit, as shown in the diagram. It takes
input from memory or registers via the bus, computes the result according to the
control signals applied to it, and places it in the register C, from where it is finally
transferred to its destination.
Timing Step Generator
To ensure the correct and
controlled execution of instructions
in a program, and all the related
operations, a timing device is
required. This is to ensure that the
operations of essentially different
instructions do not mix up in time.
There exists a timing step
generator that provides mutually
exclusive and sequential timing
intervals. This is analogous to the
clock cycles in the actual processor. A possible implementation of the timing step
generator is shown in the figure.
Each mutually exclusive step is carried out in one timing interval. The timing intervals
can be named T0, T1
T7. The given figure is helpful in understanding the mutual
exclusiveness in time of these timing intervals.
Processor design
Structural RTL descriptions of selected
SRC instructions
Structural RTL for the SRC
The structural RTL describes how a
particular operation is performed using a
specific hardware implementation. In
order to present the structural RTL we
assume that there exists a timing step
generator, which provides mutually
exclusive and sequential timing intervals, analogous to the clock cycles in actual
processor.
PC is incremented. In T1 the instruction is brought from the memory into the Memory
Buffer Register(MBR), and the incremented PC is updated. In the third and final time
step of the instruction fetch phase, the instruction from the memory buffer register is
written into the IR for execution.What follows the instruction fetch phase, is the
instruction execution phase. The number of timing steps taken by the execution phase
generally depends on the type and function of instruction. The more complex the
instruction and its implementation, the more timing steps it will require to complete
execution. In the following discussion, we will take a look at various types of
instructions, related timing steps requirements and data path implementations of these in
terms of the structural RTL.
processor with signals to differentiate between the various types of shifts that are to be
performed.
Structural RTL for Register(to(Register add
To enhance our understanding of the instruction execution phase implementation, we will
now take a look at some more instructions of
the SRC. The structural RTL for a simple add
instruction add ra, rb, rc is given in table.
The first three instruction fetch steps are
common to all instructions. Execution of
instruction starts from step T3 where the first
operand is moved to register A. The second
step involves computation of the sum and
result is transferred to the destination in step T5. Hence the complete execution of the add
instruction takes 6 time steps. Other arithmetic/logic instructions having the similar
structural RTL are sub, and and or. The only difference is in the T4 step where
the sign changes to (), (^), or (~) according to the opcode.
Structural RTL for the not instruction
The first three steps T0 to T2 are used up in fetching the instruction as usual. In step T3,
the value of the operand specified by the register is brought into the ALSU, which will
use the control function NOT, negate the value (i.e. invert it), and the result moves to the
register C. In the time step R4, this result is assigned to the destination register through
the internal bus. Note that we need control signals to coordinate all of this; a control
signal to allow reading of the instructionspecified source register in T3, control signal
for the selection of appropriate function to be carried out at the ALSU, and control signal
to allow only the instructionspecified
destination register to read the result value
from the data bus.
The table shown outlines these steps for the
instruction: not ra, rb
Structural RTL for the addi instruction
Again, the first three time steps are for the
instruction fetch. Next, the first operand is brought into ALSU in step T3 through register
A. The step T4 is of interest here as the second operand c2 is extracted from the
instruction in IR register, sign extended to 32 bits, added to the first operand and written
into the result register C. The execution of instruction completes in step T5 when the
result is written into the destination register. The sign extension is assumed to be carried
out in the ALSU as no separate extension unit is provided.
Sign extension for 17(bit c2 is the same as:(15�IR<16> ©IR<16..0>)
Sign extension for 22(bit c1 is the same as:(10�IR<21> ©IR<21..0>)
The given table outlines the time steps for the instruction addi:
Other instructions that have the same
structural RTL are subi, andi and ori.
RTL for the load (ld) and store (st)
instructions
The syntax of load instructions is:
ld ra, c2(rb)
And the syntax of store instructions is:
st ra, c2(rb)
Last Modified: 12Jan11 Page 154
Advanced Computer ArchitectureCS501
The given table outlines the time steps in fetching and executing a load and a store
instruction. Note that the first 6 time steps (T0 to T5) for both the instructions are the
same.
The first three steps are those of instruction fetch. Next, the register A gets the value of
register rb, in case it is not zero. In time step T4, the constant is signextended, and added
to the value of register A using the ALSU. The result is assigned to register C. Note that
in the RTL outlined above, we are sign extending a field of the Instruction Register(32
bit). It is so because this field is the constant field in the instruction, and the Instruction
Register holds the instruction in execution. In step T5, the value in C is transferred to the
Memory Address Register (MAR). This completes the effective address calculation of the
memory location to be accessed for the load/ store operation.If it is a load instruction in
time step T6, the corresponding memory location is accessed and result is stored in
Memory Buffer Register (MBR). In step T7, the result is transferred to the destination
register ra using the data bus.If the instruction is to store the value of a register, the time
step T6 is used to store the value of the register to the MBR. In the next and final step, the
value stored in MBR is stored in the memory location indexed by the MAR.We can look
at the datapath figure and visualize how all these steps can take place by applying
appropriate control signals. Note that, if more time steps are required, then a counter with
more bits and a larger decoder can be used, e.g., a 4bit counter along with a 4to16
decoder can produce up to 16 time steps.
Lecture No. 13
Structural RTL Description of the FALCON(A
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 4
Computer Systems Design and Architecture 4.2.2, slides
Summary
�� Structural RTL Description of the SRC (continued
)
�� Structural RTL Description of the FALCONA
Comparing the uni-bus implementation of FALCON-A with that of SRC results in the
following differences:
�� FALCON-A processor bus has 16 lines or is 16-bits wide while that of SRC is
32-bits wide.
�� All registers of FALCONA are of 16bits while in case of SRC all registers are
32bits.
�� Number of registers in FALCONA are 8 while in SRC the number of registers is
32.
�� Special registers i.e. Program Counter (PC) and Instruction Register (IR) are 16
bit registers while
in SRC these are
32bits.
�� Memory Address
Register (MAR)
and Memory Buffer
Register (MBR) are
also of 16bits
while in SRC these
are of 32bits.
MAR and MBR are dual
port registers. At one side
they are connected to
internal bus and at other
side to external memory in order to point to a particular address for reading or writing
data from or to the memory and MBR would get the data from the memory.
Last Modified: 12Jan11 Page 157
Advanced Computer ArchitectureCS501
almost same as of sub instruction except in timing step T4 we have + sign for addition
instead of sign as in sub instruction. Other instructions that belong to the same group
are and, or and sub.
Structural RTL for multiplication instruction
mul ra, rb, rc
This instruction is only present in this processor and not in SRC. The first three steps are
exactly same as of other instructions and would fetch the mul instruction. In step T3 we
will bring the contents of register R
[rb] in the buffer register A at the
input of ALSU. In step T4 we take
the multiplication of A with the
contents of R[rc] and put it at the
output of the ALSU in two registers
C and CH. CH would contain the
higher 16bits while register C
would contain the lower 16bits.
Now these two registers cannot
transfer the data in one bus cycle to
the registers, since the width is 16bits. So we need to have 2 timing steps, in T5 we
transfer the higher byte to register R[0] and in T6 the lower 16bits are transferred to the
placeholder R[a]. As a result of multiplication instruction we need 3 timing steps for
Instruction Fetch and 4 timing steps for Instruction Execution and 7 steps altogether.
Structural RTL for division instruction
div ra, rb, rc
In this instruction first three steps
are the same. In step T3 the
contents of register rb are placed in
buffer register A and in step T4 we
take the contents of register R[0] in
to the register AH. We assume
before using the divide instruction
that we will place the higher 16
bits of dividend to register R[0].
Now in T5 the actual division takes
place in two concurrent operations.
We have the dividend at the input
of ALSU unit represented by concatenation of AH and A. Now as a result of division
instruction, the first operation would take the remainder. This means divide AH
concatenated with A with the contents given in register rc and the remainder is placed in
register CH at the output of ALSU. The quotient is placed in C. In T6 we take C to the
register R[ra] and in T7 remainder available in CH is taken to the default register R[0]
through the bus. In divide instruction 5 timing steps are required to execute the
instruction while 3 to fetch the instruction.
Note: Corresponding to mul and div instruction one should be careful about the
additional register R[0] that it should be properly loaded prior to use the instructions e.g.
if in the divide instruction we dont have the appropriate data available in R[0] the result
of divide instruction would be wrong.
This is tested by the contents given by the register ra. So condition within square brackets
is R[ra]. This means test the data given in register ra. There are different possibilities and
so the data could be positive, negative or zero. For this particular instruction it would be
tested if the data were zero. If the data were zero, the CON would be 1.
In T4 we just take the contents of the PC into the buffer register A. In T5 we add up the
contents of A to the constant c2 after sign extension. This addition will give us the
effective address to which a jump would be taken. In T6, this value is copied to the PC.
In FALCONA, the number of conditional jumps is more than in SRC. Some of which
are shown below:
�� jz (opcode= 19) jump if zero
jz r3, [4] (R[3]=0): PC� PC+ 2;
�� jnz (opcode= 18) jump if not zero
jnz r4, [variable] (R[4]�0): PC� PC+ variable;
�� jpl (opcode= 16) jump if positive
jpl r3, [label] (R[3]�0): PC � PC+ (labelPC);
�� jmi (opcode= 17) jump if negative
jmi r7, [address] (R[7]<0): PC� PC+ address;
The unconditional jump instruction will be explained in the next lecture.
Lecture No. 14
External FALCON(A CPU
Reading Material
Summary
�� Structural RTL Description of the FALCONA (continued
)
�� External FALCONA CPU Interface
In the case of a constant, variable, an address or (labelPC) the jump ranges from 128 to
127 because of the restriction on 8bit constant c2. Now, for example if we have jump
[r0+a], it means jump to a. On the other hand if we have jump [ r2] that is not allowed
by the assembler. The target address should be even because we have each instruction
with 2 bytes. So the types available for the unconditional jumps are either direct,
indirect, PCrelative or register relative. In the case of direct jump the constant c2 would
define the target address and in the case of indirect jump constant c2 would define the
indirect location of memory from where we could find out the address to jump. While in
the case of PCrelative if the contents of register ra are zero then we have near jump and
the type of jump for this would be PCrelative. If ra is not be zero then we have a far
jump and the contents of register ra will be added with the constant c2 after sign
extension to determine the jump address.
This instruction is opposite to the in instruction. First three instructions would fetch the
instruction. In step T3 the contents of register ra are placed in to the buffer register C and
then in Step T4 from C the data is placed at the output port indicated by the c2 constant.
So this instruction is just opposite to the in instruction.
Structural RTL for the call instruction
call ra, rb
In this instruction we need to give the control to the procedure, subroutine or to another
address specified in the program. First
three steps would fetch the call
instruction. In step T3 we store the
present contents of PC in to the buffer
register C and then from C we transfer
the data to the register ra in step T4.
As a result register ra would contain
the original contents of PC and this
would be a pointer to come back after
executing the subroutine and it would
be later used by a return instruction. In
step T5 we take the contents of register
rb, which would actually indicate to
the point where we want to go. So in
step T6 the contents of C are placed in
PC and as a result PC would indicate the position in the memory from where new
execution has to begin.
Structural RTL for return
instruction
ret ra
After instruction fetch in first 3 steps
T0T2, the register data in ra is placed
in the buffer register C through ALSU
unit. PC is loaded with contents of this
buffer register in step T4. Assuming
that bus activity is synchronized,
appropriate control signals are
available to us now.
Control signals required at different
timing steps of FALCON(A
instructions
The following table shows the details of the control signals needed. The first column is
the time step, as before. In the second column the structural RTLs for the particular step
is given, and the
corresponding
control signals are
shown in the third
column. Internal bus
is active in step T0,
Last Modified: 12Jan11 Page 165
Advanced Computer ArchitectureCS501
causing the contents of the PC to be placed in the Memory Address register MAR and
simultaneously the PC is incremented by 2 and placed it in the buffer register C.
Recalling previous lectures, to write data in to a particular register we need to enable the
load signal. In case of fetch instruction in step T0, control signal LMAR is enabled to
cause the data from internal bus to be written in to the address register. To provide data to
the bus through tristate buffers we need to activate the out control signal named as
PCout, making contents of the PC available to the ALSU and so control unit provides
the increment signal INC2 to increment the PC. As the ALSU is the combinational
circuit, the PCout signal causes the contents over the 2nd input of ALSU incremented by
2 and so the data is available in buffer register C. Control signal LC is required to write
data into the buffer register C form the ALSU output. Now note that INC2 is one of the
ALSU functions and also it is a control signal. So knowing the control signals, which
need to be activated at a particular step, is very important.
So, at step T0 the control signal PCout is activated to provide data to the internal bus.
Now control signal LMAR causes the data from the bus to be read into the register
MAR. The ALSU function INC2 increments the PC to 2 and the output are stored in the
buffer register C by the control signal LC. The data from memory location addressed by
MAR is read into Memory Buffer Register MBR in the next timing step T1. In the mean
time there is no activity on the internal bus, the output from the buffer register C (the
incremented value of the PC) is placed in the PC through bus. For this the control signal
LPC is activated.
To enable tristate buffer of Memory Address Register MAR, we need control signal
MARout. Another control signal is required in step T1 to enable memory read i.e.
MRead. In order to enable buffer register C to provide its data to the bus we need
Cout control signal and in order to enable the PC to read from C we need to enable its
load signal, which is LPC. To read data coming from memory into the Memory Buffer
Register MBR, LMBRcontrol signal is enabled. So in T2 we need 5 control signals, as
shown.
In T2, the instruction register IR is loaded with data from the MBR, so we need two
control signals,MBRout to enable its tristate buffers and the other signal required is the
load signal for IR register LIR. Fetch operation is completed in steps T0T2 and
appropriate control signals are generated. Those control signals, which are not shown,
would remain deactivated. All control signals are activated simultaneously so the order
of these controls signals is immaterial. Recall that in SRC the fetch operation is
implemented in the same way, but INC4 is used instead of INC2 because the
instruction length is 4 bytes.
Now we take a look at other examples for control signals required during execution
phase.
For various instructions, we will define other control signals needed in the execution
phase of each instruction but fetch cycle will be the same for all instructions.
Another important fact is the interface of the CPU with an external memory and the I/O
depending upon whether the I/O is memory mapped or nonmemory mapped. The
processor will generate some control signals, used by the memory or I/O to read/write
data to/from the I/O devices or from the memory. Another assumption is that the memory
read is fast enough. Therefore data from memory must be available to the processor in a
fixed time interval, which in this particular example is T2.
For a slow data transfer, the concept of handshaking is used. Some idle states are
introduced and buffer is prepared until the data is available. But for simplicity, we will
Last Modified: 12Jan11 Page 166
Advanced Computer ArchitectureCS501
assume that memory is fast enough and data is available in buffer register MBR to the
CPU.
Example Problem
This table contains a partial memory map showing the addresses and the corresponding
data values.
The next table shows the register map showing the contents of all the CPU registers.
Solution:
In this table the second column contains the RTL descriptions of the instructions. We
have to specify the address bus and data bus contents for each instruction execution. For
load instruction the contents of register r5+12 are placed on the address bus. From
register map shown in the previous table we can see that the contents of r5 are 1234h.
Now contents of r5 are added with displacement value 12 in decimal .In other words the
address bus will carry the hexadecimal value 1234h+ Ch = 1240h.Now for load
instruction, the contents of memory location at address 1240h will be placed on the data
bus. From the memory map shown in the previous table we can see that memory location
1240h contains 785h. Now to read this data from this location, MRead control signal will
be activated shown by 1 in the next column and MWrite would be 0.Similarly RTL
description is given for the 2nd instruction. In this instruction, only registers are involved
so there is no need to activate external bus. So data bus, address bus and control bus
columns will contain ? or unknown. The next instruction is jump. Here PC is
incremented by the jump offset, which is 52 in this case. As before, the external bus will
remain inactive and control signals will be zero. The next instruction is store. Its RTL
description is given. For store instruction, the register contents have to be placed at
memory location addressed by R [3] +17. As this is a memory write operation, the
MWrite will be 1 and MRead will be zero. Now the effective address will be determined
by adding the contents of R [3] with the displacement value 17 after its conversion to the
hexadecimal. The resulting effective address would be C300h. In this way we can
complete the table for other instructions.
Addressing Modes
This table lists the addressing mode for each instruction given in the previous example.
Lecture No. 15
Logic Design and Control Signals Generation in SRC
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 4
Computer Systems Design and Architecture 4.4
Summary
1) Logic Design for the Unibus SRC
2) Control Signals Generation in SRC
As shown in the Table: 1, some control signals are to let register values to be written onto
buses, or read from the buses. Similarly, some signals are required to read/ write memory
contents onto the bus. The memory is assumed to be fast enough to respond during a
given time slot; if that is not true, wait states have to be inserted. We require four control
signals to be issued in the time step T0:
PCout: This control signal allows the contents of the Program Counter register to be
written onto the internal processor bus.
LMAR: This signal enables write onto the memory address register (MAR), thus the
value of PC that is on the bus, is copied into this register
INC4: It lets the PC value to be incremented by 4 in the ALSU, and result to be
stored in C. Notice that the value of PC has been received by the ALSU as an
operand. This control signal allows the constant 4 to be added to it.
The ALSU is assumed to include an INC4 function
LC: This enables the input to the register C for writing the incremented value of PC
onto it.
During the time step T1, the following control signals are applied:
LMBR: This enables the write for the register MBR. When this signal is activated,
whatever value is on the bus, can be written into the MBR.
MRead: Allow memory word to be gated from the external CPU data bus into the
MBR.
MARout: This signal enables the tristate buffers at the output of MAR.
Cout: This will enable writing of the contents of register C onto the processors
internal data bus.
LPC: This will enable the input to the PC for receiving a value that is currently on the
internal processor bus. Thus the PC will receive an incremented value.
At the final time step, T2, of the instruction fetch phase, the following control signals
are issued:
MBRout: To enable the tristate buffers with the MBR.
LIR: To allow the IR read the value from the internal bus. Thus the instruction stored
in the MBR is read into the Instruction Register (IR).
Similar control signals will allow the instruction execution as well. We have already
mentioned the external CPU buses that read from the memory and write back to it. In the
given figure, we had not shown these external (address and data buses) in detail. Fig.2
will help us understand this external interface.
Example problem:
(a) What will be the logic levels on the external SRC buses when each of the given SRC
instruction is executing on the processor? Complete Table: 2. all numbers are in the
decimal number system, unless noted otherwise.
(b) Specify memory addressing modes for each of the SRC instructions given in Table: 2.
Assumptions:
All memory content is aligned properly.
In other words, all the memory accesses start at addresses divisible by 4.
Value in the PC = 000DC348h
Notes:
* Relative addressing is always PC relative in the SRC
*** Displacement addressing mode is the same as Based or Indexed in the SRC. It is
also the same as Register Relative addressing mode
CPU data bus. The MBR also drives the internal CPU bus as well as the external CPU
data bus. Similar to the MAR register, tristate buffers are provided at the connection
points of the MBR, as illustrated in the Fig.7.
Register connections
The register file containing the General Purpose Registers is programmer visible.
Instructions may refer to any of these registers, as source operands in an operation or as
the destination registers. Appropriate circuitry is needed to enable the specified register
for read/ write. Intuitively, we can tell that we require connections of the register to the
CPU internal bus, and we need control signals that will enable specified registers to be
read/ write enabled as a corresponding instruction is decoded. Fig.8 illustrates the register
connections and the control signals generation in the unibus data path of the SRC. We
can see from this figure that the ra, rb and rc fields of the Instruction Register specify the
destination and source registers. The control signals RAE, RBE and RCE can be applied
to select any of the ra, rb or rc field respectively to apply its contents to the input of 5to
32 decoder. Through the decoder, we get the signal for the specific register to be
accessed. The BUS2R control signal is activated if it is desired to write into the register.
On the other hand, if the register contents are to be written to the bus, the control signal
R2BUS is activated.
In this alternate circuitry, there is a separate 5to32 decoder for each of the register fields
of the instruction register. The output of these decoders is allowed to be read out and
enables the decoded register, if the control signal (RAE, RBE or RCE) is active.
Table: 4
At time step T3, the control RBE is applied, which will enable the register rb to write its
contents onto the internal CPU bus, as it is decoded. The writing from the register onto
the bus is enabled by the control signal R2BUS. Control signal LA allows the bus
contents to be transferred to the register A (which will supply it to the ALSU). At time
step T4, the control signals applied are RCE, R2BUS, ADD, LC, to respectively enable
the register rc, enable the register to write onto the internal CPU bus (which will supply
the second operand to the ALSU from the bus), select the add function of the ALSU
(which will add the values) and enable register C (so the result of the addition operation
is stored in the register C). Similarly in T5, signals Cout, RAE and BUS2R are activated.
Sign extension
When we copy constant values to registers that are 32 bits wide, we need to sign extend
the values first. These values are in the 2s complement form, and to signextend these
values, we need to copy the most significant bit to all the additional bits in the register.
We consider the field c2, which is a 17 bit constant. Sign extension of c2 requires that we
copy c2<16> to all the leftmost bits of the destination register, in addition to copying the
original constant values to the register. This means that bus<31...17> should be the same
as c2<16>. A 15 line tristate buffer can perform this sign extension. So we apply c2<16>
to all the inputs of this tristate buffer as illustrated in the Fig.10.
The table shows that the control signals for the addi instruction are the same as the add
instruction, except in the time step T4. At this time step, the control signals that are
applied are c2out, ADD and LC, to respectively do the following:
Enable the read of the constant c2 (which is sign extended) onto the internal processor
bus. Add the values using the ALSU and finally assign the result to register C by
enabling write for this register.
Note that, by default, the value of register R0 is 0 in some cases. So, when the selected
register turns out to be 0 (as rb field is 0), the line connecting the output of the register R0
is not enabled, and instead a hardwired 0 is output from the tristate buffer onto the CPU
internal bus. An alternate circuitry for achieving the same is shown in the Fig.12.
Lecture No. 16
Control Unit Design
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 4
Summary
�� Control Signals Generation in SRC (continued
)
�� The Control Unit
�� 2Bus Implementation of the SRC Data Path
This is the branch and zero instruction we looked at earlier. The control signals for this
instruction are:
As usual, the first three steps are for the instruction fetch phase. Next, the following
control signals are issued:
LCON to enable the CON circuitry to operate, and instruct it to check for the appropriate
condition (whether it is branch if zero, or branch if not equal to zero, etc.)
RCE to allow the register rc value to be read.
R2BUS allows the bus to read from the selected register.
At step T4:
RBE to allow the register rb value to be read. rb value is the branch target address.
R2BUS allows the bus to read from the selected register.
LPC (if CON=1): this control signal is issued conditionally, i.e. only if CON is 1, to
enable the write for the program counter. CON is set to 1 only if the specified condition is
met. In this way, if the condition is met, the program counter is set to the branch address.
Branch and link instructions
The branch and link instruction is similar to the branch instruction, with an additional
step, T4. Step T4 of the simple conditional branch instruction becomes the step T5 in this
case.
Hardwired approach is relatively faster, however, the final circuit is quite complex. The
microprogrammed implementation is usually slow, but it is much more flexible.
Finitestate machine concepts are usually used to represent the CU. Every state
corresponds to one clock cycle i.e., 1 state per clock. In other words each timing step
could be considered as just 1 state and therefore from one timing step to other timing
step, the state would change. Now, if we consider the control unit as a black box, then
there would be four sets of inputs to the control unit. These are as follows:
1. The output of timing step generator (There are 8 disjoint timing steps in our
example T0T7).
2. Opcode (opcode is first given to the decoder and the output of the decoder is
given to the control unit).
3. Data path generated signals, like the CON control signal,
4. Signals from external events, like Interrupt generated by the Interrupt generator.
The accompanying block diagram shows the inputs to the control unit. The output control
signals generated from control unit to the various parts of the processor are also shown in
the figure.
The following figure shows how the operation code (opcode) field of the Instruction
Register is decoded to generate a set of signals for the Control unit.
This is an example for the FALCONA processor where the instruction is 16bit long.
Similar concepts will apply to the SRC, in which case the instruction word is 32 bits and
IR <31...27> contains the opcode. Similar concepts will apply to the SRC, in which case
Last Modified: 12Jan11 Page 187
Advanced Computer ArchitectureCS501
the instruction word is 32 bits and IR<31..27> contains the opcode. The most significant
5 bits represent the opcode. These 5bits from the IR are fed to a 5to32 decoder. These
32 outputs are numbered from 0to31 and named as op0, op1 up to op31. Only one of
these 32 outputs will be active at a given time .The active output will correspond to
instruction executing on the processor.
To design a control unit, the next step is to write the Boolean Equations. For this we need
to browse through the structural descriptions to see which particular control signals occur
in different timing steps. So, for each instruction we have one such table defining
structural RTL and the control signals generated at each timing step. After browsing we
need to check that which control signal is activated under which condition. Finally we
need to write the expression in the form of a logical expression as the logical combination
of AND and OR of different control signals. The given table shows Boolean
Equations for some example control signals.
For example, PCout would be active in every T0 timing step. Then in timing interval T3
the output of the PC would be activated if the opcode is 20 or 22 which represent jump
and subroutine call. In step T4 if the opcode is 16, 17, 18 or 19, again we need PCout
activated and these 4 instructions correspond to the conditional jumps. We can say that in
other words in step T1, PCout is always activated OR in T3 it is activated if the
instruction is either jump or subroutine call OR in T4 if there is one of the conditional
jumps. We can write an equation for it as
PCout=T0+T3.(OP20+OP22)+T4.(OP16+OP17+OP18+OP19)
In the form of logic circuit the implementation is shown in the figure. We can see that we
OR the opode 20 and 22 and AND it with T3, then OR all the op16 up to op19
and AND it with T4, then T0 and the AND outputs of T3 and T4 are OR together
to obtain the PCout.
In the same way the logic circuit for LPC control signal is as shown and the equation
would be :
LPC=T1+T5.OP20+T6.CON.(OP16+OP17+OP18+OP19)
We can formulate Boolean equations and draw logic circuits for other control signals in
the same way.
frequency of the clock which controls the generation of the timing intervals T0, T1
T7.
So, we can not arbitrarily increase the frequency of this clock. As an example consider
the transfer of the contents of a register R1 to a register R2. The minimum time required
to perform this transfer is given by
t = t + t + tcomb + t
min g bp 1
The details are explained in the text with reference to Fig 4.10. Thus, the maximum clock
frequency based on this transfer will be 1/tmin. Students are encouraged to study example
4.1 of the text.
Structural RTL for the sub instruction using the 2(bus data path implementation
Next, we look at the structural RTL as well as the control signals that are issued in
sequence for instruction execution in a 2bus implementation of the data path. The given
table illustrates the Register Transfer Language representation of the operations for
carrying out instruction fetch, and execution for the sub instruction.
The first three steps belong to the instruction fetch phase; the instruction to be executed is
fetched into the Instruction Register and the PC value is incremented to point to the next
inline instruction. At step T3, the register R[rb] value is written to register A. At the time
step T4, the subtracted result from the ALSU is assigned to the destination register R[ra].
Notice that we did not need to store the result in a temporary register due to the
availability of two buses in place of one. At the end of this sequence, the timing step
generator is initialized to T0.
Control signals for the fetch operation
The control signals for the instruction fetch phase are shown in the table. A brief
explanation is given below:
At time step T3, the execution may begin, and the control signals issued at this stage
depend on the actual instruction encountered. The control signals issued for the
instruction fetch phase are the same for all the instructions.
Note that, we assume the memory to be fast enough to respond during a given time slot.
If that is not true, wait states have to be inserted. Also keep in mind that the control
signals during each time slot are activated simultaneously, while those for successive
time slots are activated in sequence. If a particular control signal is not shown, its value is
zero.
Lecture No. 17
Summary
�� 3bus implementation for the SRC
�� The Machine Reset
�� Machine Exceptions
Structural RTL for the Subtract Instruction using the 3(bus Data Path
Implementation
We now consider how instructions are fetched and executed in 3bus architecture. For
this purpose, the same sub instruction example is followed.
receives the memory word indexed by the MAR, and the PC value is incremented. At
time step T1, the instruction register is assigned the instruction word that was loaded
into the MBR in the previous time step. This concludes the instruction fetch and now
the instruction execution can commence.
In the next time step, T2, the instruction is executed by subtracting the values of
register rc from rb, and assigning the result to the register ra.
At the end of each sequence, the timing step generator is initialized to T0
The reset instruction is mainly used for debugging purposes, as most processors halt
operations immediately or within a few cycles of receiving the reset instruction. The
processors state may then be examined in its halted state.
Some processors have two types of reset operations. Soft reset implies initializing PC
and interrupt flags. Hard reset initializes other processor state registers in addition to
PC and interrupts enable flags. The software reset instruction asserts the external reset
pin of the processor.
Hard Reset
The SRC should perform a hard reset upon receiving a start (Strt) signal. This initializes
the PC and the general registers.
Soft Reset
The SRC should perform a soft reset upon receiving a reset (rst) signal. The soft reset
results in initialization of PC only.
The reset signal in SRC is assumed to be external and asynchronous.
PC Initialization
There are basically two approaches to initialize a PC.
1. Direct Approach
The PC is loaded with the address of the startup routine upon resetting.
2. Indirect Approach
The PC is initialized with the address where the address of the startup routine is
located. The reset instruction loads the PC with the address of a jump instruction. The
jump instruction in turn contains the address of the required routine.
An example of a reset operation is found in the 8086 processor. Upon receiving the
reset instruction the 8086 initializes its PC with the address FFFF0H. This memory
location contains a jump instruction to the bootstrap loader program. This program
provides the system initialization
Let us examine the contents of each phase in the given table. In step T0, if the Rst
signal is not asserted, the address of the new instruction is delivered to memory and the
value of PC is incremented by 4 and stored in another register. If the Rst signal is
asserted, the Rst signal is immediately cleared, the PC is cleared to zero and T, the
step counter is also set to zero. This behavior (in case of Rst assertion) is the same for
all steps. In step T1, if the rst signal is not asserted, the value stored at the delivered
memory word is stored in the memory data register and the PC is set to its incremented
value.
In step T2, the stored memory data is transferred to the instruction register.
In step T3, the register operand values are read.
In step T4, the mathematical operation is executed.
In step T5, the calculated value is written back to register file.
During all these steps if the Rst signal is asserted, the value of PC is set to 0 and the
value of the step counter is also set to zero.
Machine Exceptions
Types of Exception
Program Exceptions
These are exceptions raised during the process of decoding and executing the
instruction. Examples are illegal instruction, raised in response to executing an
instruction which does not belong to the instruction set. Another example would
be the privileged instruction exception.
Hardware Exceptions
There are various kinds of hardware exceptions. An example would be of a timer
which raises an exception when it has counted down to zero.
Trace and debugging Exceptions
Variable trace and debugging is a tricky task. An easy approach to make it
possible is through the use of traps. The exception handler which would be called
after each instruction execution allows examination of the program variables.
Nonmaskable Exceptions
These are high priority exceptions reserved for events with catastrophic
consequences such as power loss. These exceptions cannot be suppressed by the
processor under any condition. In case of a power loss the processor might try to
save the system state to the hard drive, or alert an alternate power supply.
Interrupts (External Exceptions)
Exception handlers may be written for external interrupts, thus allowing programs
to respond to external events such as keyboard or mouse events.
Lecture No. 18
Pipelining
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 4
Computer Systems Design and Architecture 4.8
Summary
�� SRC Exception Processing Mechanism
�� Introduction to Pipelining
�� Complications Related to Pipelining
�� Pipeline Design Requirements
Correction: Please note that the phrase instruction fetch should be used where the
speaker has used instruction interpretation.
The following tables on the next few pages summarize the changes needed in the SRC
description for including exceptions:
Instruction_Fetch:=
PC PC + 4;
Instruction_Execution),
Instruction_Fetch);
R[rb] IPC<31..0>;
IPC<31..0> R[rb];
T1 MD M[MA], PC C;
T2 IR MD;
T3 Instruction_Execution;
Instruction_Fetch:= Events
Normal
(Run&!Rst&!(ireq&IE):(IR M[PC], PC PC+4;
Instruction_Execution), Fetch
Soft Reset
Run&Rst: (Rst 0 , IE 0, PC 0; Instruction_Fetch),
Hard Reset
Introduction to Pipelining
Last Modified: 12Jan11 Page 201
Advanced Computer ArchitectureCS501
1. Instruction fetch
As the name implies, the instruction is fetched from the
instruction memory in this stage. The fetched instruction bits
are loaded into a temporary pipeline register.
3. ALU5 operation
5 The ALU is also called the ALSU in some cases, in particular, where its shifting capabilities need to be
highlighted. ALSU stands for Arithmetic Logic Shift Unit.
Last Modified: 12Jan11 Page 202
Advanced Computer ArchitectureCS501
In this stage, the fetched operand values are fed into the ALU along with the function
which is required such as addition, subtraction, etc. The result is stored into temporary
pipeline registers. In case of a memory access such as a load or a store instruction, the
ALU calculates the effective memory address in this stage.
4. Memory access
For a load instruction, a memory read operation takes place. For a store instruction, a
memory write operation is performed. If there is no memory access involved in the
instruction, this stage is simply bypassed.
5. Register write
The result is stored in the destination register in this stage.
Remember that the performance gain in a pipeline is limited by the slowest stage in the
pipeline.
There is a datadependence among the above two instructions. The register R3 is being
written to in the instruction S1, while it is being read from in the instruction S2. If the
instruction S2 is executed before instruction S1 is completed, it would result in an
incorrect value of R3 being used.
1. Pipeline stalls
These are inserted into the pipeline to block instructions from entering the pipeline until
some instructions in the later part of the pipeline have completed execution. Hence our
modified code would become
Last Modified: 12Jan11 Page 203
Advanced Computer ArchitectureCS501
S1: add r3, r2, r1
stall6
stall
stall
S2: sub r4, r5, r3
2. Data forwarding
When using data forwarding, special hardware is added to the processor, which allows
the results of a particular pipeline stage to be transferred directly to another stage in the
pipeline where they are required. Data may be forwarded directly from the execute stage
of one instruction to the decode stage of the next instruction. Considering the above
example, S1 will be in the execute stage when S2 will be decoded. Using a comparator
we can determine that the destination operand of S1 and source operand of S2 are the
same. So, the result of S1 may be directly forwarded to the decode stage.
Other complications include the branch delay and the load delay. These are
explained below:
Branch delay
Branches can cause problems for pipelined processors. It is difficult to predict whether a
branch will be taken or not before the branch condition is tested. Hence if we treat a
branch instruction like any normal instruction, the instructions following the branch will
be loaded in the stages following the stage which carries the branch instruction. If the
branch is taken, then those instructions would need to be removed from the pipeline and
their effects if any, will have to be undone. An alternate method is to introduce stalls, or
nop instructions, after the branch instruction.
Load delay
Another problem surfaces when a value is loaded into a register and then immediately
used in the next operation. Consider the following example:
S1: load r2, 34(r1)
S2: add r5, r2, r3
In the above code, the correct value of R2 will be available after the memory access
stage in the instruction S1. Hence even with data forwarding a stall will need to be placed
between S1 and S2, so that S2 fetches its operands only after the memory access for S1
has been made.
separate so that instructions may be fetched while the register values are being stored
and/or loaded from data memory. There should be a single data path so as not to
complicate the flow of instructions and maintain the order of program execution. There
should be a three port register file so that if the register write and register read stages
overlap, they can be performed in parallel, i.e., the two register operands may be read
while the destination register may be written. The data should be latched in between each
pipeline stage using temporary pipeline registers. Since the clock cycle depends on the
slowest pipeline stage, the ALU operations must be able to complete quickly so that the
cycle time is not increased for the rest of the pipeline.
For the instruction add r1, r2, r3: Instruction Fetch – Register Read – Execute – Register Write,
whereas for the instruction add r1, r2, a (remember a represents a memory address), we
have Instruction Fetch – Register Read – Memory Access – Execute – Register Write
The data path is defined in terms of registers placed in between these stages. It specifies
how the data will flow through these registers during the execution of an instruction. The
data path becomes more complex if forwarding or bypassing mechanism is added to the
processor.
Lecture 19
Pipelined SRC
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 5
Computer Systems Design and Architecture 5.1.3
Summary
1. Instruction Fetch
2. Instruction decode/operand fetch
3. ALU operation
4. Memory access
5. Register write
As shown in the next diagram, there are several registers between each stage.
After the instruction has been fetched, it is stored in IR2 and the incremented value of the
program counter is held in PC2. When the register values have been read, the first
register value is stored in X3, and the second register value is stored in Y3. IR3 holds the
opcode and ra. If it is a store to memory instruction, MD3 holds the register value to be
stored.
After the instruction has been executed in the ALU, the register Z4 holds the result. The
opcode and ra are passed on to IR4. During the write back stage, the register Z5 holds the
value to be stored back into the register, while the opcode and ra are passed into IR5.
There are also two separate memories and several multiplexers involved in the pipeline
operation. These will be shown at appropriate places in later figures.
The number after a particular register name indicates the stage where the value of this
register is used.
1. ALU Instructions
2. Load/Store instructions
3. Branch Instructions
We will now discuss how to design a common pipeline for all three categories of
instructions.
1. ALU instructions
In the diagram shown, X3 and Y3 are temporary registers to hold the values between
pipeline stages. X3 is loaded with operand value from the register file. Y3 is loaded with
either a register value from the register file or a constant from the instruction. The
operands are then available to the ALU. The ALU function is determined by decoding the
opcode bits. The result of the ALU operation is stored in register Z4, and then stored in
the destination register in the register write back stage. There is no activity in the memory
access stage for ALU instructions. Note that Z5, IR3, IR4, and IR5 are not shown
Last Modified: 12Jan11 Page 207
Advanced Computer ArchitectureCS501
explicitly in the figure. The purpose of not including these registers is to keep the
drawing simple. However, these registers will transfer values as instructions progress
through the pipeline. This comment also applies to some other figures in this discussion.
2. Load/Store instructions
The instruction is loaded into IR2 and the incremented value of the PC is loaded in PC2.
In the next stage, X3 is loaded with the value in PC2 if the relative addressing mode is
used, or the value in rb if the displacement addressing mode is used. Similarly, C1 is
transferred to Y3 for the relative addressing mode, and c2 is transferred to Y3 for the
displacement addressing mode. The store instruction is completed once memory access
has been made and the memory location has been written to. The load instruction is
completed once the loaded value is transferred back to the register file. The following
figure shows the schematic for a load instruction. A similar schematic can be drawn for
the store instruction.
3. Branch Instructions
Branch Instructions usually involve calculating the target address and evaluating a
condition. The condition is evaluated based on the c2 field of the IR and by using the
value in R[rc]. If the condition is true, the PC is loaded with the value in R[rb], otherwise
it is incremented by 4 as usual. The following figure shows these details.
The pipelined data path implementation diagrams shown earlier for the three SRC
instruction categories must be combined and refined to get a working system. These
details get complicated very quickly. A detailed combined diagram is shown in Figure
5.7 of the text book.
Last Modified: 12Jan11 Page 209
Advanced Computer ArchitectureCS501
In most cases, the signals defined above are used in the same stage where they are
generated. If that is not the case, a number used after the signal name indicates the stage
where the signal is generated.
Using these definitions, we can develop RTL statements for describing the pipeline
activity as well as the equations for the multiplexer select signals for different stages of
the pipeline. This is shown in the next diagram.
Consider the RTL description of the Mp1 signal, which controls the input to the PC. It
simply means that if the branch and cond signals are not activated, then the PC is
incremented by 4, otherwise if both are activated then the value of R1 is copied in to the
PC.
The multiplexer Mp2 is used to decide which registers are read from the register file. If
the store signal is activated then R[rb] from the instruction bits is read from the register
file so that its value may be stored into memory, otherwise R[rc] is read from the register
file.
The multiplexer Mp3 is used to decide which registers are read from the register file for
operand 2. If either rl or branch is activated then the updated value of PC2 is transferred
to X3, otherwise if dsp or alu is activated, the value of R[ra] from the register file is
transferred to the x3. In the same way, multiplexer Mp4 is used to select an input from
Y3.
In the same way, multiplexer Mp4 is used to select an input for Y3.
The multiplexer MP5 is used to decide which value is transferred to be written back to
the register file. If the load signal is activated data from memory is transferred to Z5,
however if the load signal is not activated then data from Z4 (which is the result of ALU)
is transferred to Z5 which is then written back to the register file.
Lecture No. 20
Hazards in Pipelining
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 5
Computer Systems Design and Architecture 5.1.5, 5.1.6
Summary
�� Structural RTL for Pipeline Stages
�� Instruction Propagation Through the Pipeline
�� Pipeline Hazards
�� Data Dependence Distance
�� Data Forwarding
�� Compiler Solution to Hazards
�� SRC Hazard Detection and Correction
�� RTL for Hazard Detection and Pipeline Stall
Instruction Fetch
IR2 M [PC];
PC2 PC+4;
ALU operation
Memory access
Write back
Add instruction moves to the execute stage, the results are written to Z4 on the
trailing edge of the clock. Ld instruction moves to decode stage. The operands
are fetched to calculate the displacement address. Br instruction enters the
pipeline. The value in PC is incremented from 208 to 212.
Fourth Clock Cycle
Add does not access memory. The result is written to Z5 at the trailing edge of
clock. The address is being calculated here for ld. The results are written to Z4.
Br is in the decode stage. Since this branch is always true, the contents of PC are
modified to new address. Str instruction enters the pipeline. The value in PC is
incremented from 212 to 216.
The result of addition is written into register r1. Add instruction completes. Ld
accesses data memory at the address specified in Z4 and result stored in Z5 at
Last Modified: 12Jan11 Page 213
Advanced Computer ArchitectureCS501
falling edge of clock. Br instruction just propagates through this stage without
any calculation. Str is in the decode stage. The operands are being fetched for
address calculation to X3 and Y3. The instruction at address 400 enters the
pipeline. The value in PC is incremented from 400 to 404.
Pipeline Hazards
The instructions in the pipeline at any given time are being executed in parallel. This
parallel execution leads to the problem of instruction dependence. A hazard occurs when
an instruction depends on the result of previous instruction that is not yet complete.
Classification of Hazards
There are three categories of hazards
1. Branch Hazard
2. Structural Hazard
3. Data Hazard
Branch hazards
The instruction following a branch is always executed whether or not the branch is taken.
This is called the branch delay slot. The compiler might issue a nop instruction in the
branch delay slot. Branch delays cannot be avoided by forwarding schemes.
Structural hazards
A structural hazard occurs when attempting to access the same resource in different ways
at the same time. It occurs when the hardware is not enough to implement pipelining
properly e.g. when the machine does not support separate data and instruction memories.
Last Modified: 12Jan11 Page 214
Advanced Computer ArchitectureCS501
Data hazards
Data hazard occur when an instruction attempts to access some data value that has not yet
been updated by the previous instruction. An example of this RAW (read after write) data
hazard is;
The register r2 is written in clock cycle 5 hence the sub instruction cannot proceed
beyond stage 2 until the add instruction leaves the pipeline.
Pipeline stalls
Consider the following sequence of instructions going
through the SRC pipeline
200: shl r6, r3, 2
204: str r3, 32
208: sub r2, r4,r5
212: add r1,r2,r3
216: ld r7, 48
There is a data hazard between instruction three and four
that can be resolved by using pipeline stalls or bubbles
When using pipeline stalls, nop instructions are placed in between dependent instructions.
The logic behind this scheme is that if opcode in stage 2 and 3 are both alu, and if ra in
stage 3 is the same as rb or rc in stage 2, then a pause signal is issued to insert a bubble
between stage 3 and 2. Similar logic is used for detecting hazards between stage 2 and 4
and stage 4 and 5.
Data Forwarding
By adding data forwarding mechanism to the SRC data path, the stalls can be completely
eliminated at least for the ALU instructions. The hazard detection is required between
stages 3 and 4, and between stages 3 and 5. The testing and forwarding circuits employ
wider IRs to store the data required in later stages. The logic behind this method is that if
the ALU is activated for both 3 and 5 and ra in 5 is the same as rb in 3 then Z5 which
hold the currently loaded or calculated result is directly forwarded to X3. Similarly, if
both are ALU operations and instruction in stage 3 does not employ immediate operands
then value of Z5 is transferred to Y3. Similar logic is used to forward data between stage
3 and 4.
alu3&alu2&((ra3=rb2)~((ra3=rc2)&!imm2)):
(pause2, pause1, op3 0)
Meaning:
If opcode in stage 2 and 3 are both ALU, and if ra in stage 3 is same as rb or rc in stage 2,
issue a pause signal to insert a bubble between stage 3 and 2
Following is the complete RTL for detecting hazards among ALU instructions in
different stages of the pipeline
between
Stage 2 and 3 alu3&alu2&((ra3=rb2)~((ra3=rc2)&!imm2)):
Lecture 21
Instruction Level Parallelism
Reading Material
Vincent P. Heuring & Harry F. Jordan Chapter 5
Computer Systems Design and Architecture 5.2
Summary
Dependence RTL
(ra5=rc3)&!imm3: Y Z5);
Stage 34 alu4&alu3:((ra4=rb3):X Z4,
(ra4=rc3)&!imm3: Y Z4);
Instruction(Level Parallelism
There are two ways to increase the number of instructions executed in a given time by a
processor
�� By increasing the clock speed
�� By increasing the number of instructions that can execute in parallel
Increasing the clock speed is an IC design issue and depends on the advancements in
chip technology.
The computer architect or logic designer can not thus manipulate clock speeds to
increase the throughput of the processor.
The computer architect cannot increase the clock speed of a microprocessor however
he/she can increase the number of instructions processed per unit time. In pipelining we
discussed that a number of instructions are executed in a staggered fashion, i.e. various
instructions are simultaneously executing in different segments of the pipeline. Taking
this concept a step further we have multiple data paths hence multiple pipelines can
execute simultaneously. There are two main categories of these kinds of parallel
instruction processors VLIW (very long instruction word) and superscalar.
Superscalar Architecture
As stated earlier the superscalar design uses multiple pipelines to implement instruction
level parallelism.
BPU calculates the branch target address ahead of time to save CPU cycles
Branch instructions are routed from the queue to the BPU where target address is
calculated and supplied when required without any stalls
BPU also starts executing branch instructions by speculating and discards the results
if the prediction turns out to be wrong
Last Modified: 12Jan11 Page 220
Advanced Computer ArchitectureCS501
Superscalar Design
The superscalar architecture uses multiple instruction issues and uses techniques such as
branch prediction and speculative instruction execution, i.e. it speculates on whether a
particular branch will be taken or not and then continues to execute it and the following
instructions. The results are not written back to the registers until the branch decision is
confirmed. Most superscalar architectures contain a reorder buffer. The reorder buffer
acts like an intermediary between the processor and the register file. All results are
written onto the reorder buffer and when the speculated course of action is confirmed, the
reorder buffer is committed to the register file.
Superscalar Processors
o PowerPC 601
o Intel P6
o DEC Alpha 21164
VLIW Architecture
VLIW stands for Very Long Instruction Word typically 64 or 128 bits wide. The longer
instruction word carries information to route data to register files and execution units.
The executionorder decisions are made at the compile time unlike the superscalar design
where decisions are made at run time. Branch instructions are not handled very efficiently
in this architecture. VLIW compiler makes use of techniques such as loop unrolling and
code reordering to minimize dependencies and the occurrence of branch instructions.
Lecture No. 22
Microprogramming
Reading Material
Summary
�� Microprogramming
�� Working of a General Microcoded Controller
�� Microprogram Memory
�� Generating Microcode for Some Sample Instructions
�� Horizontal and Vertical Microcode Schemes
�� Microcoded 1bus SRC Design
�� The SRC Microcontroller
Microprogramming
In the previous lectures, we have discussed how to implement logic circuitry for a control
unit based on logic gates. Such an implementation is called a hardwired control unit. In a
micro programmed control unit, control signals which need to be generated at a certain
time are stored together in a control word. This control word is called a microinstruction.
A collection of microinstructions is called a microprogram. These microprograms
generate the sequence of necessary control signals required to process an instruction.
These microprograms are stored in a memory called the control store.
As described above microprogramming or microcoding is an alternative way to design
the control unit. The microcoded control unit is itself a small stored program computer
consisting of
MicroPC
Microprogram memory
Microinstruction word
The relationship between control The control signals here are stored as words
inputs and control outputs is a series in a microcode memory.
of Boolean functions.
Hardwired control units are generally Microcode units simplify the computer logic
faster. but it is comparatively slower.
A microcoded controller works in the same way as a small general purpose computer.
1. Fetch a microinstruction and increment microPC.
2. Execute the instruction present in microIR.
3. Fetch the next instruction and so on
C Bits
These form the control signal
field
M Bits
These form the branch address
field
B Bits
These form the branch control
field.
Microprogram Memory
This small memory contains microroutines for all the instructions in the ISA
The microPC supplies the address and it returns the control word stored at that
address
It is much faster and smaller than a typical main memory
The control word for an instruction is used to generate the equivalent microcode
sequence
Each step in RTL corresponds to a microinstruction executed to generate the control
signals.
Each bit in the control words in the microprogram memory represents a control signal.
The value of that bit decides whether the signal is to be activated or not.
The first three addresses from 100 to 102 represent microcode for instruction fetch and
the last three addresses from 203 to 205 represent microcode for sub instruction. In the
first cycle at address 100, the control signal PCout, LMAR, LC, and INC4 are activated
and all other signals are deactivated. All these control signals are for the SRC processor.
So, if the microPC contains 100, the contents of microprogram memory are copied into
the micro IR. This corresponds to the structural RTL description of the T0 clock during
Last Modified: 12Jan11 Page 224
Advanced Computer ArchitectureCS501
instruction fetch phase. In the same way, the content of address 101 corresponds to T1,
and the content of address 102 corresponds to T2.
Microprogram controller
controls the sequence of
the flow of
microinstructions.
The inputs to the
microcontroller are from
the branch control fields
specified in the microcode
word.
Its output controls the 4
to 1 multiplexer inside the
microcoded control unit.
It implements
conditional execution and
both conditional and
unconditional branch
4(1 Multiplexer
The multiplexer supplies one of the four possible values to the microPC
The incremented value of the microPC is used when dealing with the normal flow of
microinstructions.
The opcode from the instruction is used to set the microPC when a microroutine is
initially being loaded.
A branch can be implemented by choosing one alternative from each of the following
two lists.
This scheme provides flexibility in choosing branches as we can form any combination
of conditions and addresses.
Branching Equivalent
�o�n�tr�o�l
� A�d�d�re�ss
�A�d�d�re�ss
Action C
�S�ig�n�al �s
� B�ra�n�ch
�ra�n�ch
� b�rn�z
construct
� �brp
� �brn
� �brz
� C
� B
400 00 0 0 0 0 0
xxx No branch,goto next {
};
address in sequence401
401 01 1 0 0 0 0
goto
xxx To the address supplied {
};
by opcode initial address;
402 10 0 0 1 0 0
xxx To external address if Z {
}; if Z then
flag is set goto Ext. Add.
403 11 0 0 0 0 1
200 To 200 if N flag is set, {
}; if N then
else to 404 goto Label1;
404 11 0 0 0 1 0 000 406 To 406 if N is false, else While (N)
to 405 {...};
405 11 1 0 0 0 0
404 Branch to 404 While contd
Any high level construct such as ifelse, while, repeat etc. can be implemented using
microcode
A variety of microcode compilers similar to the high level compilers are available that
allow easier programming in microcode
This similarity between high level language and microcode simplifies the task of
controller design.
In horizontal microcode schemes, there are no intermediate decoders and the control
word bits are directly connected to their destination i.e. each bit in the control word is
directly connected to some control signal and the total number of bits in the control word
is equal to the total number of control signals in the CPU.
Vertical microcode schemes employ an extra level of decoding to reduce the control
word width. From an n bit control word we may have 2n bit signal values.
In the SRC the bits from the opcode in the instruction register are decoded to fetch the
address of the suitable microroutine from the microprogram memory. The microprogram
controller for the SRC microcoded control unit employs the logic for handling exceptions
and reset process. Since the SRC does not have any condition codes, we use the CON and
n signals instead of N and Z flags to control branches in case of branch if equal to zero or
branch if less than instructions.
The microprogram controller for the SRC microcoded control unit employs the logic
for handling exceptions and reset process
Since the SRC does not have any condition codes, we use the CON and n signals
instead of N and Z flags to control branches
�r(�C�O�N=�0�)
�M�u�x�C�o�n�tr�o�l
�r(�n�=�1�) RTL
�r(�n�=�0�)
�o�n�tr�o�l
� A�d�d�re�ss
�A�d�d�re�ss
�S�ig�n�al �s
� B�ra�n�ch
� B�ra�n�ch
�A�R
C�o�u �t
� LM
�d
� En
� B
� B
� B
� C
� �P
300 00 0 0 0 0 0 1 1
xxx MAR PC: C PC + 4;
Assume the first control word at address 300. The RTL of this instruction is MAR PC
combined with C PC+4. To facilitate these actions the PCout signal bit and the LMAR
signal bit are set to one, so that the value of the PC may be written to the internal
processor bus and written onto the MAR. The instructions at 300, 301 and 302 form the
microcode for instructions fetch. If we examine the RTL we can see all the functionality
of the fetch instruction. The value of PC is incremented, the old value of PC is sent to
memory, the instruction from the sent address is loaded into memory buffer register.
Then the opcode of the fetched instruction is used to invoke the appropriate microroutine.
Bit ORing
Nanocoding
Writable Microprogram Memory
Subroutines in Microprogramming