This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub $t0, $s3, $s4 # calc i-j | |
sll $t0, $t0, 2 # calc (i-j)*4 | |
lw $t0, $t0($s6) # assign A[i-j] to temp regiseter $t0 | |
sw $t0, 32($s7) # send $t0 value to B[8] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B[g] = A[f] + A[f+1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sll $t0, $s0, 2 # $t0 = f * 4 | |
add $t0, $s6, $t0 # $t0 = &A[f] | |
sll $t1, $s1, 2 # $t1 = g * 4 | |
add $t1, $s7, $t1 # $t1 = &B[g] | |
lw $s0, 0($t0) # f = A[f] | |
lw $t0, 4($t0) # $t0 = A[f + 1] | |
add $t0, $t0, $s0 # $t0 = A[f] + A[f + 1] | |
sw $t0, 0($t1) # B[g] = $t0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Array[5]; | |
int temp1, temp2; | |
Array[0] = 2; // adress 24 | |
Array[1] = 4; // adress 28 | |
Array[2] = 3; // adress 32 | |
Array[3] = 6; // adress 36 | |
Array[4] = 1; // adress 40 | |
temp1 = Array[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lw $t0, 0($s6) # temp1 = Array[0] | |
lw $t1, 4($s6) # temp2 = Array[1] | |
lw $t2, 16($s6) # $t2 = Array[4] | |
sw $t2, 0($s6) # Array[0] = $t2 | |
sw $t0, 4($s6) # Array[1] = $t0 | |
lw $t3, 12($s6) # $t3 = Array[3] | |
sw $t3, 16($s6) # Array[4] = $t3 | |
sw $t1, 12($s6) # Array[3] = $t1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nor $t1, $t2, $zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lw $t2, 0($s1) # $t2 = C[0] | |
sll $t1, $2, 4 # $t1 = $t2 << 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add $t0, $zero, $zero # $t0 = (i = 0) | |
Loop1: slt $t2, $t0, $s0 # $t2 = if(i < a) then 1 else 0 | |
beq $t2, $zero, Exit # if($t2 == 0) then jump to Exit | |
add $t1, $zero, $zero # $t1 = (j = 0) | |
Loop2: slt $t2, $t1, $s1 # $t2 = if(j < b) then 1 else 0 | |
beq $t2, $zero, Loop3 # if($t2 == 0) then jump to Loop3 | |
add $t2, $t0, $t1 # $t2 = i + j | |
sll $t3, $t1, 4 # $t3 = (j << 2) << 2 = (4 * j) * 4 (for word range) | |
add $t4, $t3, $s2 # $t4 = $t3 + &D[0] | |
sw $t2, 0($t4) # D[4*j] = i + j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib: | |
addi $sp, $sp, -12 # create stack space | |
sw $a0, 8($sp) # push $a0 to stack | |
sw $ra, 4($sp) # push $ra to stack | |
sw $s0, 0($sp) # push $s0 to stack | |
slti $t0, $a0, 2 # if $a0 < 2 then $t0 = 1 else $t0 = 0 | |
beq $t0, $zero, ELSE # if $t0 == 0 goto ELSE | |
addi $v0, $a0, $zero # $v0 = $a0 + 0 | |
j EXIT # jump to EXIT | |
ELSE: addi $a0, $a0, -1 # $a0 = n - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib(5): | |
# fib(5) | |
addi $sp, $sp, -12 # create stack space | |
sw $a0, 8($sp) # push $a0(5) to stack | |
sw $ra, 4($sp) # push $ra to stack | |
sw $s0, 0($sp) # push $s0 to stack | |
addi $a0, $a0, -1 # $a0 = n = 4 | |
# fib(5) -> fib(4) | |
addi $sp, $sp, -4 # create stack space | |
sw $a0, 0($sp) # push $a0(4) to stack |
OlderNewer