William Stallings William Stallings Computer Organization
d A hit tand Architecture
Chapter 9Instruction Sets:Instruction Sets:Characteristicsand Functionsand Functions
What is an instruction set?What is an instruction set?
aThe complete collection of instructions that are understood by a CPUaMachine CodeaBinaryaUsually represented by assembly codes
Elements of an InstructionElements of an Instruction
aOperation code (Op code)`Do this
aSource Operand reference`To this
l d faResult Operand reference`Put the answer here
aN t I t ti R faNext Instruction Reference`When you have done that, do this...
Where have all the Operands gone?gone?
aLong time passing.a(If you dont understand, youre too young!)aMain memory (or virtual memory or cache)aCPU registeraI/O device
Instruction RepresentationInstruction Representation
aIn machine code each instruction has a unique bit patternaFor human consumption (well, programmers
anyway) a symbolic representation is used` ADD SUB LOAD`e.g. ADD, SUB, LOAD
aOperands can also be represented in this way`ADD A B`ADD A,B
Instruction TypesInstruction Types
aData processingaData storage (main memory)aData movement (I/O)aProgram flow control
Number of Addresses (a)Number of Addresses (a)
a3 addresses`Operand 1, Operand 2, Result`a = b + c;`May be a forth - next instruction (usually implicit)`Not common`Not common`Needs very long words to hold everything
Number of Addresses (b)Number of Addresses (b)
a2 addresses`One address doubles as operand and result`a = a + b`Reduces length of instruction`Requires some extra work`Requires some extra workTemporary storage to hold some results
Number of Addresses (c)Number of Addresses (c)
a1 address`Implicit second address`Usually a register (accumulator)`Common on early machines
Number of Addresses (d)Number of Addresses (d)
a0 (zero) addresses`All addresses implicit`Uses a stack`e.g. push a` push b` push b` add` pop c` pop c
`c = a + b
How Many AddressesHow Many Addresses
aMore addresses`More complex (powerful?) instructions`More registersInter-register operations are quicker
`Fewer instructions per program`Fewer instructions per programaFewer addresses`Less complex (powerful?) instructions`Less complex (powerful?) instructions`More instructions per program`Faster fetch/execution of instructions
Design Decisions (1)Design Decisions (1)
aOperation repertoire`How many ops?`What can they do?`How complex are they?
aData t pesaData typesaInstruction formats`L th f d fi ld`Length of op code field`Number of addresses
Design Decisions (2)Design Decisions (2)
aRegisters`Number of CPU registers available`Which operations can be performed on which
registers?
aAddressing modes (later )aAddressing modes (later)
aRISC v CISCaRISC v CISC
Types of OperandTypes of Operand
aAddressesaNumbers`Integer/floating point
aCharacters`ASCII etc.
aLogical Data`Bits or flags
a (Aside: Is there any difference between numbers and characters? Ask a C programmer!)p g )
Pentium Data TypesPentium Data Types
a8 bit Bytea16 bit worda32 bit double worda64 bit quad wordaAddressing is by 8 bit unitaA 32 bit double word is read at addresses
divisible by 4
Specific Data TypesSpecific Data Types
a General - arbitrary binary contentsa Integer - single binary valuea O di l i d i ta Ordinal - unsigned integera Unpacked BCD - One digit per bytea Packed BCD - 2 BCD digits per bytea Packed BCD 2 BCD digits per bytea Near Pointer - 32 bit offset within segmenta Bit fielda Byte Stringa Floating Point
Pentium Floating Point Data TypesTypes
aSee Stallings p324
Types of OperationTypes of Operation
aData TransferaArithmeticaLogicalaConversionaI/OaSystem ControlyaTransfer of Control
Data TransferData Transfer
aSpecify`Source`Destination`Amount of data
aMa be diffe ent inst ctions fo diffe entaMay be different instructions for different movements`e g IBM 370`e.g. IBM 370
aOr one instruction and different addresses`e g VAX`e.g. VAX
ArithmeticArithmetic
aAdd, Subtract, Multiply, DivideaSigned IntegeraFloating point ?aMay include`Increment (a++)`Decrement (a--)`Negate (-a)
LogicalLogical
aBitwise operationsaAND, OR, NOT
ConversionConversion
aE.g. Binary to Decimal
Input/OutputInput/Output
aMay be specific instructionsaMay be done using data movement instructions
(memory mapped)aMay be done by a separate controller (DMA)
Systems ControlSystems Control
aPrivileged instructionsaCPU needs to be in specific state `Ring 0 on 80386+`Kernel mode
aFor operating systems use
Transfer of ControlTransfer of Control
aBranch`e.g. branch to x if result is zero
aSkip`e.g. increment and skip if zero`ISZ R i t 1`ISZ Register1`Branch xxxx`ADD A`ADD A
aSubroutine call`c f interrupt call`c.f. interrupt call
Foreground ReadingForeground Reading
aPentium and PowerPC operation typesaStallings p338 et. Seq.
Byte Order(A portion of chips?)(A portion of chips?)
aWhat order do we read numbers that occupy more than one byteae.g. (numbers in hex to make it easy to read)a12345678 can be stored in 4x8bit locations as
f llfollowsa
Byte Order (example)Byte Order (example)
aAddress Value (1) Value(2)a184 12 78a185 34 56a186 56 34a186 78 12
a i.e. read top down or bottom up?
Byte Order NamesByte Order Names
aThe problem is called EndianaThe system on the left has the least significant
byte in the lowest addressaThis is called big-endianaThe system on the right has the least
significant byte in the highest addressaThis is called little-endian
Standard What Standard?StandardWhat Standard?
aPentium (80x86), VAX are little-endianaIBM 370, Moterola 680x0 (Mac), and most RISC
are big-endianaInternet is big-endian`Makes writing Internet programs on PC more
awkward!`WinSock provides htoi and itoh (Host to Internet &`WinSock provides htoi and itoh (Host to Internet &
Internet to Host) functions to convert