Instruction sets

MIPS -> pipelining

The immediate specified in an instruction is a 16-bit two's complement number in the range [-32768, 32767]

  • addi: sign extend immediate value

  • lb, lh, : sign extenloaded byte/halfword

  • beq, bne: sign extend the displacement

  • 4 bits == 1 hex digits (0 ~ 15)


I-format instruction: only two registers needed

immediate arithmetic and load/store instruction

  • op (6)
  • rs (5)
  • rt (5) : destination or source register number
  • constant / address (16) : 2's complement constant / offset(2's complement) added to base address in rs -> [-2**15, -2**15-1]

J-format (jumps)

How the program is stored in the computer (memory)a

  • Instructions and data are stored in memory
  • programs can operate on programs
  • Binary compatibility: requires standardized ISAs

movement of data between processor and memory can be a bottleneck

R: op | rs | rt | rd | shamt | funct

Shift operations (R)

  • shamt: how many positions ()
  • rs is not used: set to 0
  • shift left logical (sll) -> fill right bits with 0
  • sfhit right logical (srl) -> fill left bits with 0 : only for unsigned no.

And operations (R)

  • R[rd] = R[rs] & R[rt]

Not operation : implemented by NOR

  • a NOR b = NOT (a or b) nor $t0, $t1, $zero //

Conditional operations (I)

  • beq rs, rt, a: jump a(offset) if rs == rt
  • bne rs, rt, a: jump a(offset) if rs != rt

Jump operations (J)

  • j L1: jump to L1

Basic block

  • no embedded branch (except at end)
  • no branch target (except at beginning)

-> no changes in control flow (assured sequential)

compiler can optimize (accelerate execution of basic blocks)

conditional operations

  • slt rd, rs, rt: rd = 1 if (rs<rt) else 0;
    • sgn(rt- rs)
  • slti rd, rs, constant : rd = 1 if (rs<constant) else 0;
    • sng(constant-rs)
  • e.g.
    • $s0 = -1 (1111...1) and $s1 = 1 (0000..1)
    • slt $t0, $s0, $s1 // $t0 = 1
    • sltu $t0, $s0, $s1 // $t0 = 0

procedure calling

  • place paramters in registers

  • transfer control to procedure

  • acquire storage for procedure

  • preform procedures' operation

  • place result in register for caller

  • return to place that called the procedure

  • jal ProcedureLabel: procedure call(jump and link)

  • jr $ra($31): procedure return(jump return)

Registers that must be saved/restored by callee $s0-$s7($16-$23): saved register $gp($28): global pointer $sp($29): stack pointer $fp($30): frame pointer $ra($31): return address

  • store order in memory

-> (bottom) -> local variable -> empty(4 bytes) -> $ra -> saved register -> function arguments -> (top) -> stack grows

Leaf procedure (not calling other procedure)

int leaf_ex(int g, h, i, j) {
  int f;
  f = (g + h) - (i + j);
  return f;
}

f in $s0, result in $v0