Machine Instructions

Download Report

Transcript Machine Instructions

Machine Instructions
Instruction Formats
Machine Instructions
 Internal
Signals in computer have high and low
voltages which represent values 0 and 1 (bits)
 Computer memory will store strings of bits in
some standard length (word size)
 Typically, a machine instruction is represented
as one or more words -- e.g. a string of bits
 Complex computers often have instructions with
different lengths
 RISC computers -- fixed instruction length
Assembly Instructions -- review
 arithmetic
and logical
– use three registers
– e.g. add $s0, $s1, $s2
 Memory
access -- load/store
– use two registers and a constant address
– e.g. sw $s0, 8($s5)
Assembly Instructions -- new
 arithmetic
and logical with constant
– use two registers and constant
– e.g. addi $s0, $t0, 16
 jump
instructions
– use address, should be as long as possible
» on MIPS address can be up to 26 bits
– e.g. j 0x4f00024
Instruction Format -- MIPS
 Instruction
is 32 bits
 Different fields (substrings) of bits
represent different parts of instruction
 What needs to be represented?
•
•
•
•
the operation
registers used
constant values
addresses
opcode
register field
immediate field
address field
Instruction Format -- Principles
 Keep
to as few different formats as possible
 Keep patterns of formats the same -- regular
 Keep corresponding parts of format in the same
location in the bit string when possible
– matches up to hardware more easily
– keeps instructions and register/memory designations
orthogonal -- that is, non-interfering
MIPS Instruction Formats
 R-type
(register)
– instructions which designate three registers
– includes most arithmetic/logical instructions
 I-type
(immediate)
– instructions which use two registers and a constant
– arithmetic/logical with immediate operand
– load and store
 J-type
– jump instructions with a 26 bit address
Exercise -- A 16 bit instruction format
We have a 16 bit word.
We have 16 general purpose registers.
We want to represent three register arithmetic instructions.
We want to represent load/store functions with MIPS format.
We want to represent arith/log instruction with two registers
and immediate operand.
How can we do it? How many bits for registers?
How many bits can be used for immediate operand?
How many bits to indicate operations?
MIPS R-type instruction
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
opcode reg rs
reg rt
reg rd shamt
funct
MIPS I-type instruction
6 bits
5 bits
5 bits
16 bits
opcode reg rs
reg rt
immediate value/addr
MIPS J-type instruction
6 bits
26 bits
opcode
address
Instruction to hardware
The machine instruction is stored in a register as high and low
voltages, which can be switched onto wires to control the operation
of the CPU. For example the values for the ADD instruction are
given below: ADD $16, $12, $13
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
opcode reg rs
reg rt
reg rd shamt
funct
000000 10000
01100
01101
100000
00000