Post

COMP2611 Computer Organisation MISP

Registers:

NameRegister numberUsagePreserver on call?
$zero0Constant Value 0N/A
$at1Reserved for assemblerN/A
$v0 - $v12 - 3Values for results and expression evaluationNo
$a0 - $a34 - 7ArgumentsNo
$t0 - $t78 - 15Temporares (Temp variable)No
$s0 - $s716 - 23Saved tempraries (Important data)Yes
$t8 - $t924 - 25More temporariesNo
$k0 - $k126 - 27Reserved for operating system kernelN/A
$gp28Pointer to global areaYes
$sp29Stack pointerYes
$fp30Frame pointerYes
$ra31Return addressYes

Some technics to preserve the register:

  1. push the data of into the stack
  2. using a temp register to store the data

Signed vs Unsigned vs Extension

 SignedUnsignedExtension
add $rd, $rs, $rtV X, both $rs, $rt 32bits
sub $rd, $rs, $rtV X, both $rs, $rt 32bits
addu $rd, $rs, $rtV X, both $rs, $rt 32bits
subu $rd, $rs, $rtV X, both $rs, $rt 32bits
addi $rt, $rs, immdV Sign-Extn
addiu $rt, $rs, immdV Sign-Extn
addu can ignore the overflow   
slt $rd, $rs, $rtV X, both $rs, $rt 32bits
sltu $rd, $rs, $rt VX, both $rs, $rt 32bits
slti $rt, $rs, immdV Sign-Extn
sltiu $rt, $rs, immd VSign-Extn before Unsign comparison
    
lb $rt, immd($rs)V address Sign-Extn
lbu $rt, immd($rs)V 0-Extn
    
and $rd, $rs, $rtN/AN/AX
andi $rt, $rs, immdN/AN/A0-Extn

Caller & Callee:

Function {Procedure} Call

Caller (Who called the procedure)Callee (Procedure being called)
Setup $aPreserve $ra
Preserve anything elsePreserve $s
 Setup $v

The way to preserve register is shown below by using push and pop procedure

Procedure:

la:

Load Address of the

la reg, targetAddress

Can be written as:

lui reg, constant
ori reg, reg, constant 
Memory BlockContentAddress Fomate
.externGlobal Static0x1000xxxx
.dataLocal Static0x1001xxxx
.heapDynamic0x1004xxxx
$spStack Pointer0x7fffxxxx
.textInstruction R/I/J Format0x0040xxxx

for example:

1
la $s0, 0x003d0900 #(0000 0000 0011 1101 0000 1001 0000 0000)

Can be written as:

1
2
lui $s0, 0x003d #(0000 0000 0011 1101)
ori $s0, $s0, 0x0900 #(0000 1001 0000 0000)

push:

pushing the memory address to the stack

1
2
  addi $sp, $sp, -4  
  sw   $ra, 0($sp)

pop:

poping the memory address from the stack

1
2
  lw    $ra, 0($sp)
  addi  $sp, $sp, 4

How to Preserve register?

Untilizing the Stack with push and pop

1
2
3
4
5
6
7
8
  addi  $sp, $sp, -8    # the immd is 4n where n = no. of register need to be preserved
  sw    $ra, 0($sp)     # the immd here is 4x where x = order of register being pushed 
  sw    $s1, 4($sp)
  
  
  lw    $s1, 4($sp) 	 # same as above
  lw    $ra, 0($sp)  	 # Last-In-First-Out
  addi  $sp, $sp, 8    # move the pointer back to the top 

MIPS Processor Datapath:

Control Signals

Signal NameDeasserted (0)Asserted (1)
RegDstWrite to address contain in $rt (bits [20-16])Write to address contain in $rd (bits [15-11])
RegWriteClose the Data WriteAllow Data Write to Register {$rt/$rd}
ALUSrcValue read from registerValue from bits [15-0]
PCSrcPC = PC + 4PC = PC + Jump
MemReadNot Allow Memory ReadAllow Memory Read
MemWriteNot Allow Memory WriteAllow Memory Write
MemtoRegWrite value from memory read to registerWrite value from ALU result to register
BranchDon’t JumpJump!

PCSrc = Branch $\and$ ALUZero

係beq 入面 branch 會 跟住 ALU Zero flag 哩睇 jump 唔 jump

ALU_Zero = 1 -> a = b, JUMP

ALU_Zero = 0 -> a ≠ b, Dont JUMP!!!!

This post is licensed under CC BY 4.0 by the author.

Trending Tags