contents: 0-1. CA Intro
The assembly language that has been studied so far is not a form that the processor can understand.
Therefore, we need to encode instructions and data in well-formed binary.
Data representation
numbers
- Numbers are kept in computer hardware as a series of 1 and 0
- They are considered base 2 numbers (binary numbers)
- Binary numbers are stored in words
- In MIPS, the words are 34 bits (4 bytes) long + MIPS is big endian
unsigned numbers
- By using n bits, we can represent unsigned numbers from 0 to
signed numbers
Signed Magnitude
- first bit determines mathematical symbols
- 0 is plus (+)
- 1 is minus (-)
- others are bit size
- but, 000 = 100 = 0
One's complement
- first bit determines mathematical symbols
- 0 is plus (+)
- 1 is minus (-)
- if first bit is 0
- read it as it is
- if first bit is 1
- flip 1 to 0, 0 to 1
- ex) 100 = -3
- but, 000 = 111 = 0
Two's complement
- first bit determines mathematical symbols
- 0 is plus (+)
- 1 is minus (-)
- if first bit is 0
- read it as it is
- if first bit is 1
- flip 1 to 0, 0 to 1
- plus 1
- ex) 100 = -4
- the number of zero is 1
Answer
two's complement
- we can get the computation result by just doing given arithmetic operations
- 000 - 001 = 111 ( 0 - 1 = -1) - 010 + 111 = 001 (2 + (-1) = 1)
- the number of zero is only 1.
- by using n bits, we can represent signed numbers from to
Signed extension
Sometimes, we need to represent n-bit numbers by using more than n bits
- 16-bit immediate should be converted to 32 bits for arithmetic
- Instructions
lb/lh
loads byte/halfword from memory space and store it into 32-bit registers - Replicate the sign bit to the left
Instruction representation
Like data, instructions are also encoded/represented in binary We call the encoded instructions as machine instructions
For representing instructions, ISA defines instruction format Issue: to represent all kinds of instructions, we might need many instrucion formants
Design principle 4
Good design demands good compromise
Based on this, MIPS keeps formats as similar as possible (regularity)
R-format
For the instructions that use only Register operands
op
(opcode): basic operation of the instruction (what the instruction does)rs
: the first source register operandrt
: the second source register operandrd
: the destination register operandshamt
: shift amount (used for shift operations)funct
: function code (the specific variant of the operation)
Q. why are the rs, rt, rd 5 bits?
A. registers are 32, which means 5 bits are enough to express each register
I-format
For the instructions that use Immediate operands
op
(opcode): basic operation of the instruction (what the instruction does)rs
: the first source register operandrt
: the second source register operandConstant or address
Summary
Key underlying design principles
Design Principle 1
Simplicity favors regularity
All MIPS arithmetic instructions include a single operation & three operands
- Lower clock period or CPI
Design Principle 2
Smaller is faster
Operands of MIPS arithmetic instructions must be chosen in a small number of registers. MIPS keeps more complex data in memory and supports data transfer between memory and registers.
- Lower clock period or CPI
Design Principle 3
Make the common case fast
Support 16-bit immediate operands for handling small constants + $zero
- Lower Instruction count
Design Principle 4
Good design demands goog compromise
Keep all instructions the same length + keep instruction formats similar as possible. Data (numbers) are also represented in binary based on two's complement rules.
- Lower clock period or CPI