Sunday, September 3, 2017

language of computer

chapter objectives:
1. convert a short MIPS assembly code sequence into machine code
2. convert a short MIPS machine code sequence into assembly code
3. implement a pseudo-instruction by a minimum number of real MIPS assembly instructions
4. convert a short C code sequence into MIPS assembly code

5. analyze 4 design principles for ISA
Instruction Set:
nThe repertoire of instructions of a computer
nDifferent computers have different instruction sets
nBut with many aspects in common
nEarly computers had very simple instruction sets
nSimplified implementation

nMany modern computers also have simple instruction sets

The MIPS Instruction Set:

Arithmetic Operations:
nAdd and subtract, three operands
nTwo sources and one destination
  add a, b, c  # a gets b + c
  sub a, b, c  # a gets b - c
nAll arithmetic operations have this form
nDesign Principle 1: Simplicity favours regularity
nRegularity makes implementation simpler

nSimplicity enables higher performance at lower cost

Register Operands:
nArithmetic instructions use register 
operands
nMIPS has a 32 × 32-bit register file
nUse for frequently accessed data
nNumbered 0 to 31
n32-bit data called a “word”
nAssembler names
n$t0, $t1, …, $t9 for temporary values
n$s0, $s1, …, $s7 for saved variables
nDesign Principle 2: Smaller is faster

nc.f. main memory: millions of locations
nC code:
  f = (g + h) - (i + j);
nf, …, j in $s0, …, $s4
nCompiled MIPS code:
  add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1

Memory Operands:
nMain memory used for composite data
nArrays, structures, dynamic data
nTo apply arithmetic operations
nLoad values from memory into registers
nStore result from register to memory
nMemory is byte addressed
nEach address identifies an 8-bit byte
nWords are aligned in memory
nAddress must be a multiple of 4
nMIPS is Big Endian
nMost-significant byte at least address of a word
c.f. Little Endian: least-significant byte at least address

Register vs Memory:
nRegisters are faster to access than memory
nOperating on memory data requires loads and stores
nMore instructions to be executed
nCompiler must use registers for variables as much as 
possible
nOnly spill to memory for less frequently used variables

nRegister optimization is important!

Immediate Operands:
nConstant data specified in an instruction
  addi $s3, $s3, 4
nNo subtract immediate instruction
nJust use a negative constant
  addi $s2, $s1, -1
nDesign Principle 3: Make the common case fast
nSmall constants are common

nImmediate operand avoids a load instruction

The Constant Zero:
nMIPS register 0 ($zero) is the constant 0
nCannot be overwritten
nUseful for common operations
nE.g., move between registers

  add $t2, $s1, $zero

Representing Instructions:
nRepresenting a number using more bits
nPreserve the numeric value
nIn MIPS instruction set
naddi: extend immediate value
nlb, lh: extend loaded byte/halfword
nbeq, bne: extend the displacement
nReplicate the sign bit to the left
nc.f. unsigned values: extend with 0s
nExamples: 8-bit to 16-bit
n+2: 0000 0010 => 0000 0000 0000 0010

n–2: 1111 1110 => 1111 1111 1111 1110

Mips R-format Instructions:

Mips I-format Instructions:


logical Operations:
Conditional Operations:

More condition operations:

concluding remarks:
nDesign principles
1.  Simplicity favors regularity
2.  Smaller is faster
3.  Make the common case fast

4.  Good design demands good compromises



Share:

0 comments:

Post a Comment

Search This Blog

Powered by Blogger.

Blog Archive