+ All Categories
Home > Documents > BSC COMPUTER ACRCHITECTURE

BSC COMPUTER ACRCHITECTURE

Date post: 07-Apr-2018
Category:
Upload: arslan-muhammad
View: 220 times
Download: 0 times
Share this document with a friend

of 61

Transcript
  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    1/61

    ADVANCED COMPUTER

    ACRCHITECTUREFirst edition

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    2/61

    BSC COMPUTER

    ACRCHITECTUREFirst edition

    Dr J S MIRZAAdvisor

    Department of Computer ScienceCOMSATS Institute of Information Technology

    Lahore, Pakistan

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    3/61

    J S Mirza is advisor in the department of computer science. COMSATS Lahore, Pakistanand is actively engaged in teaching computer architecture course both to theundergraduate and graduate students. He obtained his early education from Matric(equivalent to O level) to Master of Science (MSc) in Physics from Punjab UniversityLahore, Pakistan. Immediately afterwards he served as Senior Research Assistant (SRA)

    in Mangla Dam Pakistan for just about one year and later for more than one year aslecturer in the department of physics, Govt College Gujranwala and then Rahimn YarKhan and lastly at Islamia College Civil Lines Lahore.

    Then he proceeded to the University of Salford, Lancashire, UK and completed M.Sc.(equivalent to MS/ M.Phil) and PhD from the Department of Electrical Engineering. Hesecured M.Sc. degree at his own expenses and for PhD study and obtained scholarshipfrom the university for PhD Study

    On his return form England he joined Physics Department of Punjab University Lahre,Pakistan

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    4/61

    PREFACE

    Progress in the field of architecture is made almost on daily basis. Essentially in theteaching field, the contests of this course should include new inventions mad in the fieldevery semester. The book covers XX chapters covering almost all the important topics.

    Chapter 1 covers XXX.Chapter 2 covers floating point representation of numerical data.Chapter 3 covers assembly language in which a program can be written.Chapter 4 covers data path detailing how data is assembled inside a computer.Chapter 5 covers multicycle implementation.

    Chapter 6 covers definitions of RISC and CISC, their differences, advantage sanddisadvantages of these structuresChapter 7 covers pipelining techniques used in the processor architectureChapter 8 covers performance measurement

    Chapter 9 covers instruction level processingChapter 10 covers memory

    Chapter 11 covers virtual memoryChapter 12 covers cacheChapter 13 covers multilevel processing

    INDEX

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    5/61

    The author, Dr J S Mirza, does not guarantee the 100% accuracy of any informationpublished herein. Also the author does not take any responsibility, whatsoever, of anyerror, omission or any damage resulting from the use of the information contained herein.

    However, the author, to the best of his knowledge, has collected the information from

    various resources which he believes are reliable and updated. The author has longexperience of teaching various subjects in the department of computer science in variouscountries.

    Special thanks go to the students of MS(CS)of COMSATS Institute of InformationTechnology (CIIT) Lahore, who studied subject of advanced computer architecture(Code: ) from the author and showed lot of interest in this publication.

    Copyright: by Dr J S Mirza of COMSATS Institute of Information Technology, Lahore,Pakistan. No parts of this publication may be reproduced or distributed by any means, or

    stored in a database or retrieval system, without the prior written permission of theauthor.

    Dr J S Mirza

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    6/61

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    7/61

    CHAPTER 1

    INTRODUCTION

    1.1 Introduction1. Computer Architecture

    2. Everything inside computer is 1 and 0 with Examples

    3. Bits, Bytes, Word Size, Instructions, Programs

    4. Numbers

    5. Signed numbers

    6. 2s complement

    7. Sign extension

    8. Why MIPS Processor

    9. Speedup

    10. Amdahls law11. Benchmarks

    1.1 COMPUTER ARCHITECTURE

    The word architecture most likely gives impression that we are talking about buildingsdesign. The word computer in computer architecture will clarify the sense that weare talking about computer design.

    A computer most often deals with

    the memory and

    processing units.

    and memory is often divided into a number of categories, which may also be calledmemory units. These categories are: hard disk, maim memory, virtual memory andcache. Each memory category has its characteristic speed and particular placementwith respect to the CPU. The very placement of memory units with respect to processingunit is called computer architecture. Many other factors also have to be considered whenwe talk about computer architecture. These will be dealt with later in Chapters. Thefunctionality, inter- and intra- relationship of each components with other (s) also has to be taken into account when talking about computer architecture. Thus computerarchitecture not only means the placement of different components with respect to the processing unit but also their functionalities and relationship of one another.Traditionally, for a good reason, the cache is the nearest to the CPU, then comes mainmemory; virtual memory is part of the main memory and then hard disk. (see the figure1.1)

    Cache is made of SRAM which is quite expensive; that is why its size is much smaller.DRAM is cheaper than SRAM and therefore the companies can afford to make its sizebigger. The hard disk is very much cheaper and that is the reason it c an be made of a

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    8/61

    bigger size The price and the access times of different memory units are given below forcomparison sake

    Figure 1.1: The placement structure of the processing unit and the different category of

    memory

    Memory

    Type

    Used in Access

    Time

    Access

    TimeRatios (IfSRAM is

    considered asreference)

    Price Price

    Ratio(disk isconsidered areference)

    SRAM Cache 5 ns 1 $ 25/MB 2500

    DRAM Mainmemory

    60 ns 12 times $1 .MB 100

    Disks Harddisk

    7ms 14,000,00times

    $0.01/MB(1cent)

    1

    Fig 1.2 The comparison of prices and access time of different memory units (2008)

    1.2 Every data and instruction inside a computer is represented

    by a long sequence comprising 1 and 0.

    Memory is made of transistors. Each transistor makes one bit and eight transistorstogether will make one byte, A particular terminal of transistor has either a voltage on itor no voltage. If the voltage level on that particular terminal is +3 say we call it 1 and ifthe voltage level on that terminal is 0 we call it 0. Thus if there are 8 transistors in a lineand the voltage levels starting from the first transistor until the last transistor are +3, +3,+3, +3, 0, 0, 0, 0 we can say the data stored is 11110000. When we put the data in acomputer we can at will either put 1 or 0 in a particular transistor. When the computerstarts making calculations then it determines 1 and 0 on transistors on its own. Forconvenience in reading we normally represent the data in sets of 4 bits. That is we put aspace after every set. This way it is easy for us to represent a number. Remember thecomputer does not waste its memory by putting a space inside it. Thus data 11110000will be written for convenience in understanding as 111 0000. Note there is one spacebetween each set of 4 bits

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    9/61

    Fir convenience the data can be represented as witherdecimal orbinary orhexadecimal

    From the prefixes comprising two letters used alongside the data it can be specified howthe data has been written. 0b represents that data is binary. 0x represents that data ishexadecimal

    Examples 1.2

    15 = 0b0000 1111+15 = 0b0000 111115hex = 0xf0+15hex = 0xf0Another way to express the code in which the word is written is to express the code assuffix of LSB in the word as

    0000 11112f0hex

    The bit on the extreme right is always called Least Significant Bit (LSB) and the bit onextreme left is called Most Significant Bit (MSB). Computer understands by reading 0band 0x that the data is inside binary or hexadecimal and accordingly converts it intobinary numbers

    Whether the thing inside the computer is music, picture, text or numbers it will always berepresented by a long sequence comprising 1 an 0. Let me explain how it is possible.Consider word size 16 of the computer which means that the all the data ( andinstructions ) must be represented inside computer as 16 bits.

    We deal with numbers every day. We say this class conations 50 students; this thing hascost us $11; I have 4 children and often we have to add or subtract or multiply or dividethe numbers. Examples of positive numbers are like +5, +64, 5 or 64 etc. The sign + isoptional in this particular case. Numbers are represented in 1 and 0 (digitalrepresentation) in computer word size as follows. Suppose the computer word size is 8,then

    +5 = 0000 0101+64 = 0100 00005 = 0000 010164 = 0100 0000

    Music: when you speak or sing in fort of a microphone its diaphragm vibrates. Its motionon one direction may be called positive and on other direction may be called negative.Thus the diaphragm oscillates between positive and negative values. Figuratively this isrepresented by the following diagram where only one oscillation is shown.

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    10/61

    Figure 1.2: one oscillation of a diaphragm of a microphone where the instantaneousvalues go from positive to negative side

    The analogue waveshape of the music is digitized and the decimal values of the upperdisplacement are: 5,18,28,25,35,40,28,28,10 which are converted by the computer intobinary numbers as:

    05= 0000 010118= 0001 001028= 0001 110025= 0001 100135= 00010 001140= 0010 1000

    28= 0001 001028= 0001 001010= 0000 1010

    These number may be either fed straight into the loud speaker or processed

    Picture: Consider for convenience a black and white picture. Draw horizontal lines on itfrom its top to bottom. Take any line. The pixels (picture elements or grains) on this linestarting from say left to right have some degree of grey on it. There will be extremelygray elements and some elements may be least grey. Let us convert the into decimalnumber as we have done for the music file above. The decimal numbers can again beconverted int binary bits. If these bits are transmitted to a far distance and fed to anothercomputer the same line can be generated over there.

    Text: In ASCII Code (using 8 bits of word size) you know that

    DecimalNumbers

    Equivalent BinaryNumbers

    Equivalent BinaryCapital Letters

    Small caseEnglishLetters

    EquivalentBinary smallCase Letters

    0. 0011 0000(48) A 0100 0001(65) a 0011 0001

    1. 0011 0001(49) B 0100 0010(66) b 0011 0010

    2. 0011 0010(50) C 0100 0011(67) c 0011 0011

    3. 0011 0011(51) D 0100 0100(68) d 0011 0100

    4. 0011 0100(52) E 0100 0101(69) e 0011 01015. 0011 0101(53) F 0100 0110(69) f 0011 0110

    6. 0011 0110(54) G 0100 0111(70) g 0011 0111

    7. 0011 0111(55) H 0100 1000(71) h 0011 1000

    8. 0011 1000(56) I 0100 1001(72) I 0011 1001

    9. 0011 1001(57) J 0100 1010(73) j 0011 1010

    10. 0011 1010(58) K 0100 1011(74) k 0011 1011

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    11/61

    . . . . . .

    . . . . . .

    The figures in the bracket are decimal numbers which we have written for no goodreason. Our concern is directly with binary number as we are explaining that all text can

    also be represented in binary numbers, Let us write Dig. From the above table it willbe:

    Number 2 0000 0000 0000 0010

    Music

    Picture Mona Lisas

    Text Naseem Hijazi novel

    1.3 Bits, Bytes, Word Size, Instructions, ProgramsBit: The easy way is to count the number of 1 and 0 in a word. Say, if a word is10001000 and the question is how many bits are there in it you count and say there are 8bits. Similarly the following word 1111 0000 1111 0000 contains 16 bits.

    Byte: The 8 bits taken together are called byte. Thus 0000 1111 0000 1111 has two bytesin the word. Byte on the low side can be called low end byte and byte at the high side canbe called high end byte.

    Word size: Computer has a word size and it almost always demands that instructions

    and data must be supplied to it in word size. It also makes calculations and provides theresult in the word size unless told to do otherwise. Thus 8-bit computer means that allinstructions and data must always comprise 8-bits. Similarly 16-bit computer means thatall instructions and data must always comprise 16-bits. Now the PC are available werethe word size is 64. One advantage of having bigger word size is that much moreinformation can be packed inside the instructions

    Instructions: Each instruction given to a processing unit is a command given to theprocessing unit to take some action. These actions are called instructions. Fir instance

    Add or subtract or multiply or divide the two given numbers

    Compare the two numbers to fid out whether they are equal or different, and ifdifferent which one is bigger which one is smaller.

    Depending upon comparison to decide whether to take next instruction or takesome other instruction.

    Program: When computer debuted in early 1960 the instructions were fed to thecomputer one by one. Later on Von Neumann a Hungarian scientist suggested that

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    12/61

    instructions can be collected in one place in a computer and the computer can be called totake first instruction and execute it. After it has been executed take the next instructionitself and execute it and then the next instruction and so on. The entire set of instructionswhich are written is caked program,

    1.4 NumbersNumbers (whether positive or negative) are always represented in 2s complement. Inother words you can say all the numbers in a computer are represented in 2scomplement. Suppose you supply any number to the computer it will convert it into 2scomplement and then save it. The number can be written into sign and magnitude formbut computers do not use this form. This is just academic exercise.

    1.5 Sign and magnitude numbersThe MSB (most significant bit) is reserved for the sign of the numbers. If the MSB is 0 itwill represent that word is positive and if it is 1 it will represent the word is negative.This means that if the word size is 8 bits then 7 bits will be used to calculate the value of

    the number

    Example 1.5 / 2.

    1111 0000 represents decimal -700111 0000 represents decimal +70

    1.51 Unsigned numbersThen unsigned numbers are the numbers which do not carry signs as 70, 127 etc. If you

    think hard you will realize that unsigned and positive numbers do not differ; thus 70and +70 mean the same thing. You can say that unsigned number are in fact positivenumbers. Think whether our thinking is true for +0 and 0 or -0.

    1.6 2s complement numbersNow a days computer almost always use 2s complement numbers. The 2s complementwill take care of the sign as well as the value of the number. Let use see some example.

    Take the word size as 4. That is, we must take 4 bits;

    2s complements of numbers are written manually as follows:For positive numbers just write their binary values as you would do for unsigned binary

    numbers. Thus in 4 bits the 2s complement of +1, +3, + 4 etc is 0001, 0011, 0100. Notethat the two complement for 1,3,4 are also the same because + attached numbers andunsigned numbers have the same 2s complments.For negative numbers in 2s complement. (that is, the numbers with which minus sign is

    attached:

    Fist write the magnitude of the number. Say, If you want to take 2s complement of- 6, thenfirst write 6 in 4 bits.

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    13/61

    Invert the number; 0 into 1 and 1 into 0

    Add 1 into it

    This is 2s complement number of the negative number

    Restrictions: for 4-bit word size the maximum positive or unsigned number we can writein 2s complement is : 2n-1 -1 where n= 4 for word size 4. In this case the maximum is 7.

    Similarly, for 8-bit words the maximum positive or unsigned number we can write in2s complement is : 2n-1 -1 where n=8 for word size of 8. In this case the maximum is127.

    Example 1.6 (1) : Write in 4 bit word size, 2s complement of 8, +9, +7, -6

    The magnitude of the number which is to be written in 2s complement must be less

    than 2n-1 -1 where n= word size. That is if the word size is 4 , n=4.

    8 cannot be written in 2s complement in 4 bits word size because its magnitude isgreater that 2n-1 -1.

    Similarly +9 cannot be written in 4 bits word size because the words magnitude, 9 isgreater that 2n-1 -1

    +7 can be written in 2 s complement because its magnitude, 7, is less than 2n-1 -1-6 can be written in 2 s complement because its magnitude, 6, is less than 2n-1 -1

    Number Sign and

    magnitude

    Unsigned

    binary number

    2s complement

    7 -- 0111 0111(look at the MSBit. If it is 1 thenumber is negative, if it is 0 thenumber is positive)

    +7 0111 --- 0111

    -7 1111 --- 1001

    Note that the minimum negative number in 2s complement isIf the word size is 4 bits 24-1 -1If the word size is 8 bits 28-1 -1

    Let us calculate the maximum and minimum number s in 2s complement for 4 diferentword size

    WORD SIZE Decimal value (as though

    the words were unsigned)

    4 Maximum:0111Minimum:1000

    78

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    14/61

    Range: 10000 16

    8 Maximum: 0111 1111Minimum: 1000 0000Range 10000 0000

    127128256

    If you look at the pattern it is the same throughout. Formaximum of the 2a complementput 0 at the left hand side and all other 1. For minimum 1 at the left and side and all other0. For range put extra 1 on left and side and all other 0

    number 2s

    complement

    (in 4 bits)

    Calculation of

    value of the

    number

    7 0111 0+4+2+1=7

    6 0110 0+4+2+0=6

    5 0101 0+4+0+1=5

    4 0100 0+4+2+1=4

    3 0011 0+0+2+1=32 0010 0+0+2+0=2

    1 0001 0+0+0+1=1

    0 0000 0+0+0+0=0

    -1 1110+1=1111 -8+4+2+1=-1 When calculating thevalue the MSbit istaken minus and therest positive

    -2 1101+1=1110 -8+4+2+0=-2 ,, ,, ,,

    ,,, 1100+1=1101 -8+4+0+1=-3 ,, ,, ,,

    -4 1011+1=1100 -8+4+0+0=-4 ,, ,, ,,

    -5 1010+1=1011 -8+0+2+1=-5 ,, ,, ,,

    -6 1001+1=1010 -8+0+2+0=-6 ,, ,, ,,-7 1000+1=1001 -8+0+0+0=-7 ,, ,, ,,

    ,, ,, ,,

    Note1: In the above table all the positive (or unsigned numbers) start with 0or the MSBitis 0, and all the ive numbers start with 1 from the left hand side.

    The most easy way to write the maximum / maximum limit / the maximum value towhich you can rightly go to, and minimum / minimum limit/ the minimum value towhich you can rightly go to in 2s complement is the following.

    If word size is 4 If word size is8

    If word size is 16

    Maximum limit 0111 0111 1111 0111 1111 1111 1111

    Minimum limit 1000 1000 0000 1000 0000 0000 0000

    Range 1111 1111 1111 1111 1111 1111 1111

    Figuratively

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    15/61

    1.7 Sign extensionLet us suppose you have a number in 8 bits and you want to convert it into 16 bits. Themost significant bit is extended till the word size is 16 bits.. You will see in the Data path

    Chapter that we normally deal with the conversion of a 16 bit data into 32 bit data.Diagrammatically it is represented as: The left hand side is the16 bit data input and theright hand side is the 32 but output. This conversion is required because ALU will alwaystake two number each of 32 bits long.

    Fig 1.3: a conversion of the data from 16 bit into32 bits

    Examples

    Suppose the number is 1111 0000 (8 bits). Convert the number into 16 bits.Extend the sign bit: 1111 1111 1111 0000.

    Let us check if the value of the word remains same. Yes it does as shown below

    Word (in 4 bits) Word (in 8 bits)

    obtained through

    sign extension

    Explanation

    0001 0000 0001 Both the word same

    the same valuenamely 1

    1000 1111 1000 -128=+120 =-8SAME

    Suppose another number is 0000 1111 (8 bits). Convert the number into 16 bits16 bit number obtained through sign extension is 0000 0000 0000 1111

    1.8 MIPS PROCESSOR

    First let us have little introduction of MIPS

    MIPS

    MIPS is the name of a microprocessor

    MIPS works on a stored program concept first suggested by VONNEUMANN. That is, a number of instructions are stored inside the computer

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    16/61

    first. Instruction are mere words, like 1001 0101, comprised of many 1s andmany 0s which tell computer what to do; for instance add two numbers, subtracttwo numbers etc. These instructions, taken together, are called a program. Oncethe program is stored inside the computer the computer is then started to work oninstructions itself, without any help from human being, one by one and in the

    same sequence which has been provided. When the instructions are completecomputer stops working.

    100 million of MIPS processors were made in 2002 and they are used in

    ATI TechnologiesBroadcomCiscoNECNintendoSilicon Graphics

    SonyTexas InstrumentsTishiba

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    17/61

    CHAPTER 2

    INSTRUCTION SET

    Register file

    Machine language and its fields

    We are accustomed to writing our computer programs in high level language as C, C++,etc because we learned these languages at the university. The computer converts yourprogram written in high level language into machine level language and then works on

    these machine level language programs. If you look at the machine level programs itconsists of 1 and 0 but these 1and 0 are packed into groups called fields an eachinstruction is composed of number of fields say 5 or 6 etc. Each field conveys a certainfacts to the processor. If the word size of the computer is 32 each instruction contains asmany 1 and 0; that is, there will be 32, 1 and 0 and they are grouped into number offields; each fold conveys certain message to processor and then processor worksaccordingly

    There is another form of program called assembly language program. Because the peoplecan not understand easily machine level language program or take too much time to makesense of instructions written in machine level language, the computer program can also

    be represented in assembly language. The assembly level language is in between highlevel and low level language and can thus be relatively easily understood.

    2.1 Some Assembly Language Instructions

    add $s1, $s2, $s3This instruction means add the contents of register, $s2, into the contents of cashregister, $s3, and place the result of addition into cash register, $s1. Note that $s1, $s2and $s3 indicate the registers numbers and not the contents. The contents will be foundonce the processor has access to these registers. Similarly there are instructions thatsubtract, multiply and divide two numbers. In them the abbreviations sub, mul and

    div is used. Some instructions compare the two numbers. You must note that in almostall the instructions we deal with use two numbers only and specify where the resultshould go into. That is only three numbers are dealt with in each instruction.The first word add is called operation code (add is op code), $s1, $s2 and $s3 are called

    operands. Note in each instruction there is always one op code and almost all three

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    18/61

    operands are given. Why three. Because in ALU three terminals are shown two inputsand one output

    Figure 2.1: Arithmetic Logic Unit (ALU), an important part of the processor, which takestwo numbers applied at its two input terminals and the result of them is provided third

    output terminal

    In the above add instruction:

    add is called operation. To be more specific, we call it the mathematicaloperation.

    The contents of the registers, $s1, $s2, $s3 are called operands

    There are three operands in each operation. Sticking to this requirement thatevery instruction must have three operands has a lot of advantages. Oneadvantage is this will keep the hardware simple than if some instructions tookmore than three or less than three operands. It will be told later that some

    instruction require two operands

    The Register file of the MIPS contains 32 registers. $ is put before register name. Some

    registers are called $t; t stands for temporary, some registers are designated $s. Thewords after # mark (sharp mark) are called comments. These comments are for the program writer or other readers to understand what the instructions mean, becausesometime you write instruction and you forget why it was written in such a way.

    The 32 registers in the register file are named and numbered as follows. The register # 1,26 and 27 have not been shown in the table. Register No. 1 called $at is reserved forassembler and register Nos. 26 an 27, called $k0 and $k1, are used by the operating

    system alone

    Table XX: registers names and numbers

    Register

    names

    Register

    number (s)

    Can the user

    write the

    register

    $zero 0 No the value isalways zero.

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    19/61

    this registercannot bewritten

    $at 1

    $v0 -$v1 2-3 No v stands for

    value$a0 - $a3 4-7 No

    $ t0 - $t7 8-15 Yes t stands for

    temporary

    $ s0-$s7 16-23 Yes s stands for

    saving

    $t8-$t9 24-25 Yes t stands fortemporary

    $k0 26 Used byoperatingsystem

    $k1 27 Used byoperatingsystem

    $gp 28 Yes global pointer

    $sp 29 Yes stack pointer

    $fp 30 Yes floating point

    $ra 31 Yes r a stands forreturn address

    In assembly language most computer instructions seem to have four fields as shownbelow

    Add $s1 $s2 $s3

    But when this instruction is converted onto machine language, the language whichcomputer understands, then this instruction will convert into 6 fields. Note someassembly language instructions convert into 6 fields and some in 4 fields as shown below

    add instruction in terms ofmachine language fields would look like this

    (6 bits)op

    (5 bits)rs

    (5 bits)rt

    (5 bits)rd

    (5 bits)shamt

    (6 bits)funct

    opcode sourceoperand, rs

    sourceoperand, rt

    destinationoperand, rd

    shiftamount

    (shamt)

    functioncode

    The first 6 bits in the first field would tell the machine about the operation

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    20/61

    The next 5 bits in the 2nd field denote the register number which contains the data.This is called source operand and is denoted by rs. The subscript S stands for resourceregister.

    The next 5 bits, in the 3

    rd

    field, denote the register number which contains the seconddata and is denoted by rt. The subscript t stands for temporary register.

    The next 5 bits denote the register number where the result should go in and isdenoted by rd. The subscript d stands for destination register.

    The next 5 bits, in the 4th field, indicate shift amount if any. Since it is not concernedby the instruction add, it is ignored by the computer; in fact foradd operation thisfield will be 00000 meaning this field is not concerned.

    Function code in the last filed elaborates op- code.

    Note that two fields, the first one and the last one, tell specifically about the operation.

    Example 2.1 (1)If the machine language instruction is as shown below what registers have been used forthe instruction?

    000000two 10001 two 10010 two 01000 two 00000 two 100000 two

    The word two at the right hand side of the binary numbers shown above indicate and thatthe word which follows has been written in Radix two, Note that you can write anynumber into three forms called radix.

    Radix two ( Binary)Radix eight (Octal)Radix ten ( Decimal)Radix sixteen (also called hex)

    Radix two means that word is written into binary formRadix eight means word is written into octal formRadix ten means the word is written in decimal formRadix sixteen means that word is written into hex form

    In the case of MIPS for each instruction we ensure that the first field and the last fieldcomprise 6 bits and the rest of the fields comprise 5 bits. In the six fields of machineinstruction we have given decimal numbers as is the tradition. This makes it easy for usto understand which register is source and which is temporary and destination register.Thus we can easily tell, looking at the machine instruction, that register number 17 in the

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    21/61

    register file is used for first source operand, rs; the register number 18 has been used forthe second operand, rt, and finally register number 8 has been used for the result ofaddition. The operation field and the function field both together tell the computer whatexactly has to be done with the two numbers

    Operation

    (decimal

    value)

    Rs

    (decimal

    value)

    Rt

    (decimal

    value)

    Rd

    (decimal value)

    Shamt

    (decimal value)

    Function

    (decimal value)

    0 17 18 8 0 32

    Machine language instruction has been shown to contain 6 fields: 6-field instructionmachine language is called R-type.

    There are 4 field-instructions as well in machine language. These are called I-typeinstruction

    In the R type instruction, the three registers must be mentioned.The exact operation is determined by the contents of 1st field and the 6th field

    In the table we have shown this instruction and in the last column of the table we indicatewhether there is overflow. Let us discus what is overflow.

    The Word Size and OverflowThe MIPS processor word size is 32 bits. It means that all of its words whether they areinstructions or data are stored in the computer memory as 32 bits long; that is when

    calculations are made each of the operands must contain exactly 32 bits and the resultmust also be 32 words. If the first bit on right hand side is counted as bit number 0, thenthe last bit would be bit number 31. Also remember that almost always the words arerepresented in twos complement.

    For quick calculation, remember if a word is 10 bits long and the word is unsigned, itmaximum value is 1K, for 20 bits, the max value is 1M, and for 30 bits the maximum is1G. Thus if you are given unsigned word which is 32 bits long; you can immediately saythat 30 bits mean 1G, so 31 would mean 2G and 32 bits would mean 4G.

    Word size Rough maximum

    value

    Exact maximum

    value

    range

    10 bits 1K (1 Kilo) 1,023 0 to 1,023

    20 bits 1M (1 Mega) 1,048,575 0 to 1,048,575

    30 bits 1G (1 Giga) 1,073,741,823 0 to 1,073,741,823

    Remember that computer words are always represented in the memory in 2s complementform. For the positive words its twos complement is exactly the same as is the unsignedbinary word. For negative numbers to be represented into 2s complement, conversion

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    22/61

    has to be made. Below are shown some number and their complements. For conveniencethe word size has been taken as 8, not 32.

    Remember restrictions when converting a number into 2s complement? Theserestriction are again shown below.

    Restrictions: for 4-bit word size the maximum positive (or unsigned number) we canwrite in 2s complement is : 2n-1 -1 where n= 4 for word size 4.

    In this case the maximum is 7. another way of quickly telling the maximum numberwhich can be converted into 2s complement is . . . . ( 1000)

    Similarly : for 8-bit words the maximum positive or unsigned number we can write in 2scomplement is : 2n-1 -1 where n=8 for word size of 8. In this case the maximum is 127.

    Some examples of converting decimal number into 2s complement are given below.

    Note that:

    Word size has been mentioned as 8

    All the words given in the table below are within limits . That is the words are less

    than +127 and -128 and they conform to the restrictions

    Word (in

    decimal) or

    radix 10

    Binary representation in 8

    bits

    2s complement

    +5 0000 0101 0000 0101

    -5 +5 = 0000 0101Invert = 1111 1010Add 1 = 1111 1011So -5 = 1111 1011

    1111 1011

    +7 0000 0111 0000 0111-7 +7 = 0000 0111

    Invert= 1111 1000Add 1= 1111 1001So -7 is 1111 1001

    1111 1001

    +127 0111 1111 0111 1111

    -127 +127 = 0111 1111Invert= 1000 0000Add1= 10000 0001

    10000 0001

    +128 Beyond the limit ----128 --- 1000 0000

    2.2. Sub $s1, $s2, $s3It means subtract the contents of $s3 from $s2 and place the result in $s1. Overflow willbe detected by the computer itself, if any. You do not have to do anything. In the machinelanguage this instruction would be represented as

    000000 10001 10010 01000 00000 100000

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    23/61

    operation

    (decimal

    value)

    rs

    (decimal

    value)

    rt

    (decimal

    value)

    rd

    (decimal value)

    shamt

    (decimal value)

    function

    (decimal value)

    0 17 18 8 0 34

    Note the 1st

    and 6th

    fields for add are 0 and 32. These fields are 0 and 34 forsub

    2.2. lw $to, 32 ($s3)

    Load means transfer a data from one location in the main memory to one of theregisters in register file. This above instruction means load 8th word (starting from 32 nd

    byte in memory) from the array whose base address is given in $s3 and put it in $t0.

    Often you deal with arrays which have thousands of elements in them and we have toprocess each element. You might think, you would save time in calculation if the entirearray were stored in cache, and then assembly language is written. But you would realize

    that there are only 32 registers in register file and it is not possible to store the thousandsof elements of array in cache registers. The array has to be stored in memory; memoryhas millions and millions of locations. But since the ALU would perform calculationsonly on the contents of registers we have to load the array data into the register file first.

    The instruction means

    add 32 into the contents of register $s3

    reach the memory location whose address has been calculated above

    and transfer the contents of that location into $t0

    $s3 contains the base address of the array. The base address means the starting address of

    the array. The register which contains the base address is also called index register; thatis the address where the array starts or its first element is stored. An offset is added into itwhich for the 8th word of the array is 32. (note that data word consists of 4 bytes)

    2.3sw $t0, 48 ($s3)

    sw stands for the store word and it is the reverse of the load operation. It means transfera data from one of the file registers to the memory. sw $t0, 48 ($s3) means store theword from register t0 into memory at the address which is obtained by adding thecontents of $s3 and 48.

    The lw and sw operations are called data transfer instruction. lw and swinstructions transfer one data from memory to register or vice versa.If your variables aremany more and you feel that 32 registers of cache will not be enough then the frequentlyused data is kept inside the register file and the less frequently used data is placed inmemory. This scheme is called register spillover.

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    24/61

    I said there may be thousand of data words in the array which need processing. Supposeat some stage you require to put the word whose address is 1023 from the base into theregister $s1. Base of the array is given in $s0.The instruction should be

    lw $s1, 1023($s0). Obviously you cannot write this instruction, because 1023 (11 11111111) cannot be written in 5 bits. Such instructions as lw and sw compel us to use morebits to write figures like 1023 etc. So we combine last three fields which will give usnow 16 bits and 16 bits will give us 216 ( 64k-1)Thus R-type instruction is

    (6 bits)op

    (5 bits)rs

    (5 bits)rt

    (5 bits)rd

    (5 bits)shamt

    (6 bits)funct

    6 bits

    Op

    5 bits

    rs

    5 bits

    rt

    16 bits

    Constant address

    This tyo ofninstruction is called I type. I-type instruction is used for lw and swoperations. The table below shows few instructions detail

    Instruction Format Rs Rt rd Shamt funct address

    add R 0 Reg Reg

    subtract R 0 Reg Reg

    addimmediate

    I 8ten Reg Reg

    lw I 35ten Reg Reg

    sw I 43ten reg reg

    Category ARITHMETIC instructions: there are 7 instructions code available in thiscategory. In the column of registers the leftmost register $s1 is the the destinationregister. The immediate word in some instruction indicates that one of the words in theequation is the constant.

    code Registers explanationadd add $s1, $s2, $s3 $s1=$s2+$s3 3 operands;

    overflowdetected

    subtract sub $s1, $s2, $s3 $s1=$s2-$s3 3 operands;overflowdetected

    add immediate addi $s1, $s2, 100 $s1=$s2+100 + constant;overflowdetected

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    25/61

    add unsigned addu $s1, $s2, $s3 $s1=$s2+$s3 3 operands;overflowdetected

    subtract unsigned subu $s1, $s2, $s3 $s1=$s2-$s3 3 operands;overflowdetected

    add immediate

    unsigned

    add iu $s1, $s2, 100 $s1=$s2+100 + constant;

    overflowdetected

    move fromcoprocessor register

    mfc0 $s1, $epc $s1= $epc Copy exceptionPC + Specialregs

    DATA TRANSFER: data transfer means data is either going from memory to register orvice versa. Load always means data is going from memory to register and store alwaysmeans data is going from register to memory. The immediate means that we are dealingwith a constant. In data transfer we either deal with full word or half word or byte

    code Registers explanationload word lw $s1, 100($s2) $s1=Memory[$s2+100] Word from

    memory toregister

    store word sw $s1, 100($s2) Memory[$s2+100]=$s1 Word fromregister tomemory

    load half unsigned lhu $s1, 100($s2) $s1=Memory[$s2+100] Half word frommemory toregister

    store half sh $s1, 100($s2) Memory[$s2+100]=$s1 Half word fromregister tomemory

    load byte unsigned lbu $s1, 100($s2) $s1=Memory[$s2+100] Byte frommemory toregister

    store byte sb $s1, 100($s2) Memory[$s2+100]=$s1 Byte fromregister tomemory

    load byte immediate lui $s1, 100 $s1=100*216 Load constant inupper 16 bits

    LOGICAL

    and and $s1,$s2,$s3 $s1=$s2 & $s3

    or or $s1,$s2,$s3 $s1=$s2 ! $s3

    nor nor $s1,$s2,$s3 $s1= ~($s2 ! $s3)and immediate andi $s1,$s2,100 $s1=$s2 & 100

    or immediate ori $s1,$s2,100 $s1=$s2 ! 100

    shift left logical sll $s1,$s2,10 $s1=$s2 > 10

    In each instruction $s1, $s2 and $s3 or constant are mentioned . In immediateinstruction the constant value is given instead of $s3. AND and OR is conducted on ($s2

  • 8/3/2019 BSC COMPUTER ACRCHITECTURE

    26/61

    and $s3) or ($s2 and constant) which is 100 in these examples. sll and srl perform shiftingoperation on register $s2 and save the result on $s1.

    CONDITIONAL BRANCH. There are 6 instructions in this category which are given

    below in the tabular form.There is always a condition given in the branching instruction.This condition is given in the bracket on explanation side. If the condition is satisfied,that is it is true, then the operation will be performed otherwise no operation isperformed. In case the operation is not performed the processor will go on its normalroute,

    branch on equal beq $s1,$s2, 25 if ($s1= =$s2) gotoPC+4+100.

    Note 25translates to25*4=100

    branch on not equal bne $s1,$s2, 25 if ($s1 != $s2) gotoPC+4+100.

    ,, ,, ,,

    ste on less than slt $s1,$s2,$s3 set $s1 to 1 if ($s2


Recommended