-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added non-jal subroutine call detection in SV.
Until now only jal instructions were used to detect subroutine calls. From now on, $ra updates and subsequent jump instructions will also be detected as subroutine calls.
- Loading branch information
Showing
2 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Calculate the product of data elements of a list | ||
# for MYΥ-505 - Computer Architecture | ||
# Department of Computer Engineering, University of Ioannina | ||
# Aris Efthymiou | ||
|
||
# Same as lab03_solution-gzz.asm but jal instructions are replaced by la and j. | ||
|
||
.globl mulproc, listProd # declare the label main as global. | ||
|
||
############################################################################### | ||
# Data input. | ||
############################################################################### | ||
.data | ||
# Leaving a 2 word (= 1 list node) offset so that the address of n1_d isn't 0x0 (null pointer) | ||
# in "Compact, Data at Address 0" memory configuration. | ||
offset_d: .word 0x7777 | ||
offset_n: .word 0x7777 | ||
|
||
# 1st item - head of the list! | ||
n1_d: .word 1 | ||
n1_n: .word n2_d # point to (beginning of) n2 | ||
|
||
# 3rd item | ||
n3_d: .word 3 | ||
n3_n: .word n4_d | ||
|
||
# 2nd item | ||
n2_d: .word 2 | ||
n2_n: .word n3_d | ||
|
||
# 5th item | ||
n5_d: .word 5 | ||
n5_n: .word 0 # This is the last iterm in the list | ||
|
||
# 4th item | ||
n4_d: .word 4 | ||
n4_n: .word n5_d | ||
|
||
# Alternative head of list. Value 0 to test mult by 0 | ||
na_d: .word 0 | ||
na_n: .word n2_d # point to (beginning of) n2 | ||
|
||
.text | ||
# These are for providing input and testing, don't change in your | ||
# final submission | ||
la $a0, n1_d | ||
la $ra, t1 | ||
j listProd | ||
t1: | ||
addu $s0, $v0, $zero # Move the result to s0 | ||
# Try it with a null pointer | ||
addu $a0, $zero, $zero | ||
la $ra, t2 | ||
j listProd | ||
t2: | ||
addu $s1, $v0, $zero # Move the result to s1 | ||
# Try it with 1 item list | ||
la $a0, n5_d | ||
la $ra, t3 | ||
j listProd | ||
t3: | ||
addu $s2, $v0, $zero # Move the result to s2 | ||
# ----- Try mult by 0 | ||
la $a0, na_d | ||
la $ra, t4 | ||
j listProd | ||
t4: | ||
addu $s3, $v0, $zero # Move the result to s3 | ||
|
||
|
||
addiu $v0, $zero, 10 # system service 10 is exit | ||
syscall # we are outta here. | ||
######################################################################## | ||
# Write your code here. Leave main as is. | ||
######################################################################## | ||
|
||
# Only works for unsigned numbers | ||
mulproc: | ||
addiu $sp, $sp, -12 | ||
sw $ra, 0x8($sp) | ||
sw $a0, 0x4($sp) | ||
sw $a1, 0x0($sp) | ||
addu $v0, $zero, $zero # result = 0 | ||
sltu $t0, $a0, $a1 | ||
bne $t0, $zero, loop_mult | ||
# swap by xor | ||
xor $a0, $a0, $a1 | ||
xor $a1, $a1, $a0 | ||
xor $a0, $a0, $a1 | ||
# now a0 < a1 | ||
loop_mult: | ||
beq $a0, $zero, leave_mult | ||
addu $v0, $v0, $a1 | ||
addiu $a0, $a0, -1 | ||
j loop_mult | ||
leave_mult: | ||
lw $a1, 0x0($sp) | ||
lw $a0, 0x4($sp) | ||
lw $ra, 0x8($sp) | ||
addiu $sp, $sp, 12 | ||
jr $ra # return | ||
|
||
|
||
listProd: | ||
addiu $sp, $sp, -8 | ||
sw $ra, 0x4($sp) | ||
sw $a0, 0x0($sp) | ||
addiu $v0, $zero, 1 | ||
beq $a0, $zero, leave_listProd | ||
lw $a0, 4($a0) # get next address | ||
la $ra, t5 | ||
j listProd | ||
t5: | ||
addu $a1, $v0, $zero # move result into a1 | ||
lw $a0, 0x0($sp) # get my original parameter | ||
lw $a0, 0($a0) # get data | ||
la $ra, leave_listProd | ||
j mulproc | ||
leave_listProd: | ||
lw $ra, 0x4($sp) | ||
addiu $sp, $sp, 8 | ||
jr $ra | ||
|
||
|