summaryrefslogtreecommitdiff
path: root/Homework/cs5300/hw-MIPS
diff options
context:
space:
mode:
Diffstat (limited to 'Homework/cs5300/hw-MIPS')
-rw-r--r--Homework/cs5300/hw-MIPS/Mars4_5.jarbin0 -> 4169142 bytes
-rw-r--r--Homework/cs5300/hw-MIPS/code/add.asm12
-rw-r--r--Homework/cs5300/hw-MIPS/code/array.asm64
-rw-r--r--Homework/cs5300/hw-MIPS/code/fee.asm44
-rw-r--r--Homework/cs5300/hw-MIPS/hw-MIPS.pdfbin0 -> 71918 bytes
5 files changed, 120 insertions, 0 deletions
diff --git a/Homework/cs5300/hw-MIPS/Mars4_5.jar b/Homework/cs5300/hw-MIPS/Mars4_5.jar
new file mode 100644
index 0000000..0021281
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/Mars4_5.jar
Binary files differ
diff --git a/Homework/cs5300/hw-MIPS/code/add.asm b/Homework/cs5300/hw-MIPS/code/add.asm
new file mode 100644
index 0000000..7f9ff9d
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/code/add.asm
@@ -0,0 +1,12 @@
+.data
+
+.text
+main:
+ li $s0, 3
+ li $s1, 4
+ add $a0, $s0, $s1
+ li $v0, 1
+ syscall
+
+ li $v0,10
+ syscall
diff --git a/Homework/cs5300/hw-MIPS/code/array.asm b/Homework/cs5300/hw-MIPS/code/array.asm
new file mode 100644
index 0000000..f802ec6
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/code/array.asm
@@ -0,0 +1,64 @@
+.text
+
+.globl main
+
+main:
+ subi $sp, $sp, 4
+ sw $ra, 0($sp) # Put return address on the bottom of the stack
+
+ subi $sp, $sp, 12 # 3 elements on the stack
+ la $t0, 0($sp) # Part of the dope vector - address of the array
+ li $t1, 3 # Might as well put the array length here too
+ li $s0, 1 # Put in registers...
+ li $s1, 3
+ li $s2, 5
+ sw $s0, 0($sp) # Push on stack...
+ sw $s1, 4($sp)
+ sw $s2, 8($sp)
+
+ subi $sp, $sp, 8 # Dope vector two words: <address> <length>
+ sw $t0, 0($sp)
+ sw $t1, 4($sp)
+
+ jal fee
+
+ lw $a0, 0($sp)
+ addi $sp, $sp, 4
+
+ li $v0, 1
+ syscall
+
+ li $v0, 10
+ syscall
+
+fee:
+ li $t0, 0 # i
+ li $t1, 0 # sum
+ lw $t2, 4($sp) # n
+ lw $t3, 0($sp) # address
+ addi $sp, $sp, 16
+
+ b loop
+
+loop:
+ li $t4, 4 # sizeof(int)
+
+ mult $t0, $t4
+ mflo $t6
+ add $t5, $t3, $t6
+ lw $t7, ($t5) # element = address + i * 4
+
+ add $t1, $t1, $t7 # sum = sum + element
+ addi $t0, $t0, 1 # i = i + 1
+
+ bne $t0, $t2, loop
+
+ # return sum
+ subi $sp, $sp, 4
+ sw $t1, 0($sp)
+
+ jr $ra
+
+# Start .data segment (data!)
+.data
+
diff --git a/Homework/cs5300/hw-MIPS/code/fee.asm b/Homework/cs5300/hw-MIPS/code/fee.asm
new file mode 100644
index 0000000..c38b5d6
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/code/fee.asm
@@ -0,0 +1,44 @@
+.text
+
+.globl main
+main:
+ # put 3 and 4 on the stack using the register $sp
+ subi $sp, $sp, 8
+ li $s0, 3
+ li $s1, 4
+
+ sw $s0, 0($sp)
+ sw $s1, 4($sp)
+
+ # call fee. You'll probably want to use the jal instruction to
+ # store the current address in $ra
+
+ jal fee
+
+ # load results from stack to registers
+ lw $a0, 0($sp)
+ addi $sp, $sp, 4
+ # print result
+ li $v0, 1
+ syscall
+
+ # exit
+ li $v0, 10
+ syscall
+fee:
+ # copy a and b from stack to local registers
+ lw $s1, 4($sp)
+ lw $s0, 0($sp)
+
+ # add a and b
+ add $t0, $s1, $s0
+
+ # place result on stack
+ addi $sp, $sp, 4 # No need to keep $sp allocated for two words when we're just returning a result
+ sw $t0, 0($sp)
+
+ # return using jr instruction
+ jr $ra
+
+# Start .data segment (data!)
+.data
diff --git a/Homework/cs5300/hw-MIPS/hw-MIPS.pdf b/Homework/cs5300/hw-MIPS/hw-MIPS.pdf
new file mode 100644
index 0000000..c8bf507
--- /dev/null
+++ b/Homework/cs5300/hw-MIPS/hw-MIPS.pdf
Binary files differ