COMP2611 Computer Organisation MISP
Registers:
Name | Register number | Usage | Preserver on call? |
---|---|---|---|
$zero | 0 | Constant Value 0 | N/A |
$at | 1 | Reserved for assembler | N/A |
$v0 - $v1 | 2 - 3 | Values for results and expression evaluation | No |
$a0 - $a3 | 4 - 7 | Arguments | No |
$t0 - $t7 | 8 - 15 | Temporares (Temp variable) | No |
$s0 - $s7 | 16 - 23 | Saved tempraries (Important data) | Yes |
$t8 - $t9 | 24 - 25 | More temporaries | No |
$k0 - $k1 | 26 - 27 | Reserved for operating system kernel | N/A |
$gp | 28 | Pointer to global area | Yes |
$sp | 29 | Stack pointer | Yes |
$fp | 30 | Frame pointer | Yes |
$ra | 31 | Return address | Yes |
Some technics to preserve the register:
- push the data of into the stack
- using a temp register to store the data
Signed vs Unsigned vs Extension
Signed | Unsigned | Extension | |
---|---|---|---|
add $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
sub $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
addu $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
subu $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
addi $rt, $rs, immd | V | Sign-Extn | |
addiu $rt, $rs, immd | V | Sign-Extn | |
addu can ignore the overflow | |||
slt $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
sltu $rd, $rs, $rt | V | X, both $rs, $rt 32bits | |
slti $rt, $rs, immd | V | Sign-Extn | |
sltiu $rt, $rs, immd | V | Sign-Extn before Unsign comparison | |
lb $rt, immd($rs) | V | address Sign-Extn | |
lbu $rt, immd($rs) | V | 0-Extn | |
and $rd, $rs, $rt | N/A | N/A | X |
andi $rt, $rs, immd | N/A | N/A | 0-Extn |
Caller & Callee:
Function {Procedure} Call
Caller (Who called the procedure) | Callee (Procedure being called) |
---|---|
Setup $a | Preserve $ra |
Preserve anything else | Preserve $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 Block | Content | Address Fomate |
---|---|---|
.extern | Global Static | 0x1000xxxx |
.data | Local Static | 0x1001xxxx |
.heap | Dynamic | 0x1004xxxx |
$sp | Stack Pointer | 0x7fffxxxx |
.text | Instruction R/I/J Format | 0x0040xxxx |
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 Name | Deasserted (0) | Asserted (1) |
---|---|---|
RegDst | Write to address contain in $rt (bits [20-16]) | Write to address contain in $rd (bits [15-11]) |
RegWrite | Close the Data Write | Allow Data Write to Register {$rt/$rd} |
ALUSrc | Value read from register | Value from bits [15-0] |
PCSrc | PC = PC + 4 | PC = PC + Jump |
MemRead | Not Allow Memory Read | Allow Memory Read |
MemWrite | Not Allow Memory Write | Allow Memory Write |
MemtoReg | Write value from memory read to register | Write value from ALU result to register |
Branch | Don’t Jump | Jump! |
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.