Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
dba9873
Create work plan
arianaolson419 Nov 6, 2017
c8c8083
Createe work plan with correct file name
arianaolson419 Nov 6, 2017
fc81680
Create module encompassing ALU, RegFile, and Memory
arianaolson419 Nov 8, 2017
2cb2fb0
Create makefile to build modules
arianaolson419 Nov 8, 2017
74292b0
Ignore compiled binaries and gtkwave files
arianaolson419 Nov 8, 2017
79cde4c
Create test bench for core module
arianaolson419 Nov 8, 2017
1cff180
Add alu files
arianaolson419 Nov 8, 2017
0e9e79f
Add inputs and outputs to module definition
arianaolson419 Nov 8, 2017
cae0a5b
Merge branch 'master' of https://github.com/arianaolson419/Lab3 into …
arianaolson419 Nov 8, 2017
26b8f1d
Build core testbenches
arianaolson419 Nov 8, 2017
3883fa8
Add register file related modules
arianaolson419 Nov 8, 2017
c81349d
Add build rules for regfile modules
arianaolson419 Nov 8, 2017
a7e4eeb
Add memory files
arianaolson419 Nov 8, 2017
ae05540
Add build rules for memory
arianaolson419 Nov 8, 2017
ea4c132
Add module for 4 input mux
arianaolson419 Nov 8, 2017
bbb2399
Add tests for 4 input module
arianaolson419 Nov 8, 2017
1375826
Add new module for four input multiplexer
arianaolson419 Nov 8, 2017
37e0474
Parametize 4 input mux for code reuse
arianaolson419 Nov 8, 2017
d0991be
modified gitignore to ignore extra output files
Joboman555 Nov 8, 2017
b6fbcd3
Added definition of Core module
Joboman555 Nov 8, 2017
efcc999
Add Instruction Parser Shell
Joboman555 Nov 8, 2017
2bb1396
Added PC_Calc
Joboman555 Nov 8, 2017
410bc2a
Top-level module is done.
Joboman555 Nov 9, 2017
e1f828a
Add zero flag
arianaolson419 Nov 9, 2017
80343e8
Add new modules
arianaolson419 Nov 9, 2017
10ff9b9
Change address size
arianaolson419 Nov 9, 2017
0c356cf
Add signextend module
arianaolson419 Nov 9, 2017
c902bef
Change mem and addr size
arianaolson419 Nov 9, 2017
43fb3ac
Change address size
arianaolson419 Nov 9, 2017
98c4dbc
Add initial Instruction_Parser parts, no tests
Joboman555 Nov 9, 2017
f458d8e
work on pc calculator
apan64 Nov 9, 2017
82192b8
Change width of regfile addresses
arianaolson419 Nov 9, 2017
3bafadb
Tests passing
Joboman555 Nov 9, 2017
1736bd3
Increase spacing from 2 to 4
Joboman555 Nov 9, 2017
52dd89f
Add controller
Joboman555 Nov 9, 2017
60a1ede
Add alu control outs
Joboman555 Nov 9, 2017
1a7a36c
Move core module files to subfolder
arianaolson419 Nov 9, 2017
fae67a3
Initialize memory
arianaolson419 Nov 10, 2017
e08bfe0
Add test cases
arianaolson419 Nov 10, 2017
e5df628
Create file of initialized memory
arianaolson419 Nov 10, 2017
217e071
Connect Da wire
arianaolson419 Nov 10, 2017
7a4587c
Implement tests for addi, lw, sw
arianaolson419 Nov 10, 2017
f69ea41
Update module references
arianaolson419 Nov 10, 2017
98ab8f7
update file paths
arianaolson419 Nov 10, 2017
a04ebb6
Update file paths
arianaolson419 Nov 10, 2017
849f316
Move files to subfolder
arianaolson419 Nov 10, 2017
56fa176
Merge branch 'master' of https://github.com/arianaolson419/Lab3 into …
arianaolson419 Nov 10, 2017
e81590e
Implement module
arianaolson419 Nov 11, 2017
a9e1ce5
Update Core instantiation
arianaolson419 Nov 11, 2017
3a0bf3c
Update file references
arianaolson419 Nov 11, 2017
4fa129f
Remove old files that have been replaced
arianaolson419 Nov 11, 2017
9116483
Change address size in test
arianaolson419 Nov 12, 2017
88c839b
Change size of 2d array to correct width
arianaolson419 Nov 12, 2017
d15b6aa
Add build rules for new modules
arianaolson419 Nov 12, 2017
8be9889
Add remaining tests
arianaolson419 Nov 12, 2017
07e7375
Instruction_Parser now compiles
Joboman555 Nov 12, 2017
2c51318
Change AddCtrl to be 1 bit because of difference in JAL
Joboman555 Nov 12, 2017
93debdd
Added initial tests, found bug in jump
Joboman555 Nov 12, 2017
859087d
Finish Tests, update Controller xs to be full # of bits
Joboman555 Nov 12, 2017
ec03d24
Add program runner, add barebones for testing memory
Joboman555 Nov 12, 2017
65544d5
Instruction Parser only runs when it is executed from right directory…
Joboman555 Nov 12, 2017
3e98160
First memory test runs
Joboman555 Nov 12, 2017
e9ded79
Finish memory Tests
Joboman555 Nov 12, 2017
9f0ede7
Add InstructionParser test
Joboman555 Nov 12, 2017
5d88194
Create module encompassing ALU, RegFile, and Memory
arianaolson419 Nov 8, 2017
d69f56c
Create makefile to build modules
arianaolson419 Nov 8, 2017
fc38651
Create test bench for core module
arianaolson419 Nov 8, 2017
f83bd5a
Add alu files
arianaolson419 Nov 8, 2017
9461de9
Add inputs and outputs to module definition
arianaolson419 Nov 8, 2017
ed5486c
Build core testbenches
arianaolson419 Nov 8, 2017
1c69c4e
Add register file related modules
arianaolson419 Nov 8, 2017
55b480a
Add build rules for regfile modules
arianaolson419 Nov 8, 2017
6bdb2e3
Add memory files
arianaolson419 Nov 8, 2017
c5a29b6
Add build rules for memory
arianaolson419 Nov 8, 2017
dff2583
Add module for 4 input mux
arianaolson419 Nov 8, 2017
8f3e391
Add tests for 4 input module
arianaolson419 Nov 8, 2017
fa6048c
Add new module for four input multiplexer
arianaolson419 Nov 8, 2017
e7ae586
Parametize 4 input mux for code reuse
arianaolson419 Nov 8, 2017
02f0983
Add zero flag
arianaolson419 Nov 9, 2017
e7cd21f
Add new modules
arianaolson419 Nov 9, 2017
fdae91f
Change address size
arianaolson419 Nov 9, 2017
9a7420b
Add signextend module
arianaolson419 Nov 9, 2017
18a87f2
Change mem and addr size
arianaolson419 Nov 9, 2017
bebf55b
Change address size
arianaolson419 Nov 9, 2017
ccd5b91
Change width of regfile addresses
arianaolson419 Nov 9, 2017
753b8b9
Move core module files to subfolder
arianaolson419 Nov 9, 2017
c40951b
Initialize memory
arianaolson419 Nov 10, 2017
1a51e26
Add test cases
arianaolson419 Nov 10, 2017
3faa596
Create file of initialized memory
arianaolson419 Nov 10, 2017
17c141a
Connect Da wire
arianaolson419 Nov 10, 2017
8d1c6ea
Implement tests for addi, lw, sw
arianaolson419 Nov 10, 2017
e8d8325
Update module references
arianaolson419 Nov 10, 2017
76a4b82
update file paths
arianaolson419 Nov 10, 2017
f3d270f
Update file paths
arianaolson419 Nov 10, 2017
1425420
Move files to subfolder
arianaolson419 Nov 10, 2017
ae079f4
work on pc calculator
apan64 Nov 9, 2017
a274de0
Implement module
arianaolson419 Nov 11, 2017
5089cb6
Update Core instantiation
arianaolson419 Nov 11, 2017
2844250
Update file references
arianaolson419 Nov 11, 2017
2a1963a
Remove old files that have been replaced
arianaolson419 Nov 11, 2017
fa00d5b
Change address size in test
arianaolson419 Nov 12, 2017
f1a4d56
Change size of 2d array to correct width
arianaolson419 Nov 12, 2017
3b91494
Add build rules for new modules
arianaolson419 Nov 12, 2017
8947a7f
Add remaining tests
arianaolson419 Nov 12, 2017
97cfde6
Merge branch 'Instruction_Parser' of https://github.com/arianaolson41…
arianaolson419 Nov 12, 2017
9045aca
Add absolute position of modules
Joboman555 Nov 12, 2017
d91c261
Merge branch 'master' of github.com:arianaolson419/Lab3
Joboman555 Nov 12, 2017
a6570d4
Merge branch 'master' of github.com:arianaolson419/Lab3
Joboman555 Nov 12, 2017
ae62c42
Merge branch 'master' of github.com:arianaolson419/Lab3
Joboman555 Nov 12, 2017
ac5ec57
Make it so mem does not reference backwards
Joboman555 Nov 12, 2017
94d7a19
Make top level directory run (sort of)
Joboman555 Nov 13, 2017
9e88935
pc calc and test
apan64 Nov 13, 2017
c457870
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 13, 2017
7b0b78f
removed merge heads
apan64 Nov 13, 2017
8996686
moved mux to submodules
apan64 Nov 13, 2017
6c90c51
fixed mux overlap
apan64 Nov 13, 2017
b8e0478
Register no longer give warning
Joboman555 Nov 13, 2017
24d1c33
Add fibonacci program
arianaolson419 Nov 13, 2017
6297e26
Update with new modules
arianaolson419 Nov 13, 2017
652dcc9
Add test module
arianaolson419 Nov 13, 2017
3cb495c
Fix typo
arianaolson419 Nov 13, 2017
91b3edf
Connect missing registers
arianaolson419 Nov 13, 2017
7ce4790
Start writing testbench
arianaolson419 Nov 13, 2017
e23c325
Add missing ports to Core instantiation
arianaolson419 Nov 13, 2017
9809fa2
Move all wires to top of module
arianaolson419 Nov 13, 2017
caa2954
Change reference memory file
arianaolson419 Nov 13, 2017
297d129
add CPU build target to all target
arianaolson419 Nov 13, 2017
a635a72
Move to more local location for Core use only
arianaolson419 Nov 13, 2017
6d98b24
Ignore mem.dat
arianaolson419 Nov 13, 2017
de9792c
Write assmebly to use as test expressions
arianaolson419 Nov 13, 2017
d4b5112
Instantiate instruction memory
arianaolson419 Nov 13, 2017
91ba871
make stuff compile
Joboman555 Nov 14, 2017
9ffa298
Make gtkwave file
arianaolson419 Nov 14, 2017
92f769e
switch inputs to DFF
arianaolson419 Nov 14, 2017
af019e9
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 14, 2017
b9844a9
got 0s at first
Joboman555 Nov 14, 2017
0eb5c19
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 14, 2017
17c8bf0
Remove debugging statement
Joboman555 Nov 14, 2017
4a20766
Change PC to be divided by 4
Joboman555 Nov 14, 2017
cd79cc2
Fix error where PC was updating after one timestep
Joboman555 Nov 14, 2017
2460bab
Run tests without ./run_program
Joboman555 Nov 14, 2017
a66e041
Specify dump vars
arianaolson419 Nov 14, 2017
9e61113
Add longer enable delay
arianaolson419 Nov 14, 2017
57662c4
Remove print statement
arianaolson419 Nov 14, 2017
39c9df2
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 14, 2017
9fd6005
removed some output wires that I forgot about
apan64 Nov 14, 2017
9e2369b
Add first unit tests
Joboman555 Nov 14, 2017
e26c0ab
Merge branch 'master' of github.com:arianaolson419/Lab3
Joboman555 Nov 14, 2017
caf925e
Change immediate for easier differentiation
arianaolson419 Nov 14, 2017
fbc482c
fixed the wiring for core and pc_calc
apan64 Nov 15, 2017
b43acbc
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 15, 2017
eec285f
Make tests work
Joboman555 Nov 15, 2017
5d5bd8a
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 15, 2017
7f3e283
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 15, 2017
9be9a5f
Merge branch 'master' of github.com:arianaolson419/Lab3
Joboman555 Nov 15, 2017
6da68cf
Add another test
Joboman555 Nov 15, 2017
bce1b2d
Fix bug where PC would be xs after LW/SW
Joboman555 Nov 15, 2017
f4d10b9
Change test instructions for diagnostics
arianaolson419 Nov 15, 2017
9f882b6
Diasble memory overwrite and add clock cycles
arianaolson419 Nov 15, 2017
282c12a
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 15, 2017
fca980a
created xori test
apan64 Nov 15, 2017
6776bdc
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 15, 2017
a2517b6
Fix the slt command number
arianaolson419 Nov 16, 2017
b9d425a
Correct the size of the 4input mux
arianaolson419 Nov 16, 2017
990c21b
Run the 4input mux test with the test harness
arianaolson419 Nov 16, 2017
e00a6cf
run tests from memory dumped from assembly program
arianaolson419 Nov 16, 2017
13143af
Dump new progeam from assembly
arianaolson419 Nov 16, 2017
4c7baf7
Remove unused file
arianaolson419 Nov 16, 2017
ded7550
Create small unit test programs in assembly
arianaolson419 Nov 16, 2017
4bbbc22
Create memory file to write to mem.dat
arianaolson419 Nov 16, 2017
e60a622
Modify test strategy
arianaolson419 Nov 16, 2017
6eedb46
Finish running through unit tests
arianaolson419 Nov 16, 2017
6edc04f
Partway done with README.md
Joboman555 Nov 16, 2017
efd0912
fixed load word timing issue
apan64 Nov 16, 2017
a0f6b2f
Add clock cycles to run to program end
arianaolson419 Nov 16, 2017
24a9525
set CPU.t.v back to unit tests
apan64 Nov 16, 2017
f13f0aa
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 16, 2017
a4244e9
Start adding lw tests
arianaolson419 Nov 16, 2017
168f4b1
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 16, 2017
7fb5c61
Add Control Signal Table to Readme
Joboman555 Nov 16, 2017
25a6aff
added cpu fib test
apan64 Nov 17, 2017
64837ba
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 17, 2017
fa10da0
Finish unit tests
arianaolson419 Nov 17, 2017
da14659
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 17, 2017
f48258d
Uncomment and unhardcode reg29
arianaolson419 Nov 17, 2017
08422fc
added a fib test to make
apan64 Nov 17, 2017
8288225
Change size of memory
arianaolson419 Nov 17, 2017
6368ed2
Initialize smaller sp
arianaolson419 Nov 17, 2017
fdfb750
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 17, 2017
3612a7e
Add static images
Joboman555 Nov 17, 2017
554df32
Add images to README
Joboman555 Nov 17, 2017
1b194d1
added to design section
apan64 Nov 17, 2017
ab66134
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 17, 2017
eec21d1
added to testing section
apan64 Nov 17, 2017
29c1293
added work plan section
apan64 Nov 17, 2017
6adab28
Delete extra stuff in README
Joboman555 Nov 17, 2017
766a93c
reused components section added to design
apan64 Nov 17, 2017
5fcb768
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 17, 2017
81ec16d
added commands for tests
apan64 Nov 17, 2017
fcafe0f
Modify for CPU constraints
arianaolson419 Nov 17, 2017
79d3af6
hopefully fixed md formatting
apan64 Nov 17, 2017
0001e9b
Split file into several testbenches
arianaolson419 Nov 17, 2017
1860542
typo
apan64 Nov 17, 2017
e787bdc
Create testbench for each program
arianaolson419 Nov 17, 2017
b2cad1b
Update build targets
arianaolson419 Nov 17, 2017
1fcb2d7
Initialize entire memory with 0s
arianaolson419 Nov 17, 2017
1c355ad
Remove automatically generated file
arianaolson419 Nov 17, 2017
101fdde
Create bash script to run tests
arianaolson419 Nov 17, 2017
73a89e9
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 17, 2017
80e952f
Add sentence to beginning of readme
Joboman555 Nov 17, 2017
821584c
Fix broken test
arianaolson419 Nov 17, 2017
5ba9371
Dump memory to core tests
arianaolson419 Nov 17, 2017
f4e0bec
Merge branch 'master' of https://github.com/arianaolson419/Lab3
arianaolson419 Nov 17, 2017
48319d5
Fix file ref
arianaolson419 Nov 17, 2017
0072f21
Fix test
arianaolson419 Nov 17, 2017
1ee2cac
test case only displays on fail
apan64 Nov 17, 2017
f37daef
Merge branch 'master' of https://github.com/arianaolson419/Lab3
apan64 Nov 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore compiled binaries
*
!/**/
!*.*
!makefile
*.out

# Ignore gtkwave files
*.vcd

# Ignore temporary memory file
mem.dat
17 changes: 17 additions & 0 deletions AssemblyPrograms/bne_unit_test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
main:
addi $t3, $zero, 0
addi $t4, $zero, 4

whileloop:
bne $t3, $t4, branchtaken

saveres:
addi $t5, $t3, 0
j end

branchtaken:
addi $t3, $t3, 1
j whileloop

end:
j end
96 changes: 96 additions & 0 deletions AssemblyPrograms/combined_unit_tests.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Test the addi command
additest:
addi $t0, $zero, 5 # $t0 = 5
addi $t1, $t0, 125 # $t1 = 130
addi $t0, $t0, 4 # $t0 = 9

# Test the xori command
xoritest:
# Reset the designated result register
addi $t0, $zero, 0

addi $t1, $zero, 2
addi $t2, $zero, 11

xori $t0, $t1, 7 # $t0 = 5
xori $t0, $t2, 11 # $t0 = 0

# Test the add command
addtest:
# Reset the designated result register
addi $t0, $zero, 0

# Two positive numbers
addi $t1, $zero, 6
addi $t2, $zero, 57

# One positive and one negative number
addi $t3, $zero, -9
addi $t4, $zero, 20

# Two negative numbers
addi $t5, $zero, -5
addi $t6, $zero, -11

add $t0, $t1, $t2 # $t0 = 57 + 6 = 63
add $t0, $t3, $t4 # $t0 = -9 + 20 = 11
add $t0, $t5, $t6 # $t0 = -5 + -11 = -16

# Test the sub command
subtest:
# Reset the designated result register
addi $t0, $zero, 0

sub $t0, $t1, $t2 # $t0 = 6 - 57 = -51
sub $t0, $t3, $t4 # $t0 = -9 - 20 = -29
sub $t0, $t5, $t6 # $t0 = -5 - -11 = 6

# Test the slt command
slttest:
# Reset the designated result register
addi $t0, $zero, 0

slt $t0, $t1, $t2 # $t0 = 57 < 6 = 1
slt $t0, $t3, $t4 # $t0 = -9 < 20 = 1
slt $t0, $t5, $t6 # $t0 = -5 < 11 = 0

# Test the bne command
breginit:
addi $t3, $zero, 0
addi $t4, $zero, 4

whileloop:
bne $t3, $t4, branchtaken

saveres:
addi $t5, $t3, 0 # $t5 = 4
j swtest

branchtaken:
addi $t3, $t3, 1
j whileloop

swtest:
addi $sp, $zero, 64
addi $t1, $zero, 2
addi $t2, $zero, 169

sw $t1, 0($sp)
sw $t2, -4($sp)

lwtest:
lw $t3, 0($sp) # $t3 = $t1 = 2
lw $t4, -4($sp) # $t4 = $t2 = 169

jaltest:
addi $t1, $zero 100 # $t1 = 100
jal jrtest
addi $t1, $t1, 1 # $t1 = 102
j end

jrtest:
addi $t1, $t1, 1 # $t1 = 101
jr $ra

end:
j end
134 changes: 134 additions & 0 deletions AssemblyPrograms/fibonacci.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

# Function call example: recursive Fibonacci

main:

addi $sp, $zero, 64
# Set up arguments for call to fib_test
addi $a0, $zero, 7 # arg0 = 4
addi $a1, $zero, 3 # arg1 = 10
jal fib_test

# Print result
add $a0, $zero, $v0 # Copy result into argument register a0

# Jump to "exit", rather than falling through to subroutines
j program_end

#------------------------------------------------------------------------------
# Fibonacci test function. Equivalent C code:
# int fib_test(arg0, arg1) {
# return Fibonacci(arg0) + Fibonacci(arg1);
# }
# By MIPS calling convention, expects arguments in
# registers a0 and a1, and returns result in register v0.
fib_test:
# We will use s0 and s1 registers in this function, plus the ra register
# to return at the end. Save them to stack in case caller was using them.
addi $sp, $sp, -12 # Allocate three words on stack at once for three pushes
sw $ra, 8($sp) # Push ra on the stack (will be overwritten by Fib function calls)
sw $s0, 4($sp) # Push s0 onto stack
sw $s1, 0($sp) # Push s1 onto stack

# a1 may be overwritten by called functions, so save it to s1 (saved temporary),
# which called function won't change, so we can use it later for the second fib call
add $s1, $zero, $a1

# Call Fib(arg0), save result in s0
# arg0 is already in register a0, placed there by caller of fib_test
jal fib # Call fib(4), returns in register v0
add $s0, $zero, $v0 # Move result to s0 so we can call fib again without overwriting

# Call Fib(arg1), save result in s1
add $a0, $zero, $s1 # Move original arg1 into register a0 for function call
jal fib
add $s1, $zero, $v0 # Move result to s1

# Add Fib(arg0) and Fib(arg1) into v0 (return value for fib_test)
add $v0, $s0, $s1

# Restore original values to s0 and s1 registers from stack before returning
lw $s1, 0($sp) # Pop s1 from stack
lw $s0, 4($sp) # Pop s0 from stack
lw $ra, 8($sp) # Pop ra from the stack so we can return to caller
addi $sp, $sp, 12 # Adjust stack pointer to reflect pops

jr $ra # Return to caller

#------------------------------------------------------------------------------
# Recursive Fibonacci function. Equivalent C code:
#
# int Fibonacci(int n) {
# if (n == 0) return 0; // Base case
# if (n == 1) return 1; // Base case
# int fib_1 = Fibonacci(n - 1);
# int fib_2 = Fibonacci(n - 2);
# return fib_1+fib_2;
# }
fib:
# Test base cases. If we're in a base case, return directly (no need to use stack)
bne $a0, 0, testone
add $v0, $zero, $zero # a0 == 0 -> return 0
jr $ra
testone:
bne $a0, 1, fib_body
add $v0, $zero, $a0 # a0 == 1 -> return 1
jr $ra

fib_body:
# Create stack frame for fib: push ra and s0
addi $sp, $sp, -8 # Allocate two words on stack at once for two pushes
sw $ra, 4($sp) # Push ra on the stack (will be overwritten by recursive function calls)
sw $s0, 0($sp) # Push s0 onto stack

# Call Fib(n-1), save result in s0
add $s0, $zero, $a0 # Save a0 argument (n) in register s0
addi $a0, $a0, -1 # a0 = n-1
jal fib
add $a0, $s0, -2 # a0 = n-2
add $s0, $zero, $v0 # s0 = Fib(n-1)

# Call Fib(n-2), compute final result
jal fib
add $v0, $v0, $s0 # v0 = Fib(n-2) + Fib(n-1)

# Restore registers and pop stack frame
lw $ra, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, 8

jr $ra # Return to caller

#------------------------------------------------------------------------------
# Utility function to print results
print_result:
# Create stack frame for ra and s0
addi $sp, $sp, -8
sw $ra, 4($sp)
sw $s0, 0($sp)

add $s0, $zero, $a0 # Save argument (integer to print) to s0

addi $v0, $zero, 4 # Service code to print string
la $a0, result_str # Argument is memory address of string to print
syscall

addi $v0, $zero, 1 # Service code to print integer
add $a0, $zero, $s0 # Argument is integer to print
syscall

# Restore registers and pop stack frame
lw $ra, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, 8

#------------------------------------------------------------------------------
# Jump loop to end execution, so we don't fall through to .data section
program_end:
j program_end


#------------------------------------------------------------------------------
.data
# Null-terminated string to print as part of result
result_str: .asciiz "\nFib(4)+Fib(10) = "
18 changes: 18 additions & 0 deletions AssemblyPrograms/slt_unit_test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Set Less Than unit tests
main:
addi $t1, $zero, 6
addi $t2, $zero 57

addi $t3, $zero, -9
addi $t4, $zero, 20

addi $t5, $zero, -5
addi $t6, $zero, -11

slt $t0, $t1, $t2
slt $t0, $t3, $t4
slt $t0, $t5, $t6
j end

end:
j end
18 changes: 18 additions & 0 deletions AssemblyPrograms/sub_unit_test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Subtraction unit tests
main:
addi $t1, $zero, 6
addi $t2, $zero 57

addi $t3, $zero, -9
addi $t4, $zero, 20

addi $t5, $zero, -5
addi $t6, $zero, -11

sub $t0, $t1, $t2
sub $t0, $t3, $t4
sub $t0, $t5, $t6
j end

end:
j end
17 changes: 17 additions & 0 deletions AssemblyPrograms/testCPU.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
main:
addi $t3, $zero, 0
addi $t4, $zero, 4

whileloop:
bne $t3, $t4, branchtaken

saveres:
addi $t5, $t3, 0
j end

branchtaken:
addi $t3, $t3, 1
j whileloop

end:
j end
56 changes: 56 additions & 0 deletions CPU.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 32 Bit CPU
// Ariana Olson, Andrew Pan, Jonah Spear

`include "Instruction_Parser/Instruction_Parser.v"
`include "Core/Core.v"
`include "PC_Calc/PC_Calc.v"
`include "DFF.v"

module CPU
(
input CLK
);
// PC is the current program counter, new_PC is what it's next value will be.
wire[31:0] PC, new_PC;
reg en;

initial begin
en = 0; #1000;
en = 1;
end

DFF #(32) pc(.trigger(CLK), .enable(en), .out(PC), .in(new_PC));

wire[4:0] Rs, Rd, Rt;
wire[15:0] imm;
wire[25:0] addr;
wire[2:0] ALUCtrl;
wire[1:0] MemToReg, RegDst, PCSel;
wire MemWr, ALUSrc, RegWr, AddSel;
InstructionParser ip(
.PC(PC),
.Rs(Rs), .Rd(Rd), .Rt(Rt),
.imm(imm), .addr(addr),
.ALUCtrl(ALUCtrl), .MemToReg(MemToReg),
.MemWr(MemWr), .ALUSrc(ALUSrc), .PCSel(PCSel),
.RegDst(RegDst), .RegWr(RegWr), .AddSel(AddSel)
);


wire[31:0] Da;
wire isZero;
wire[31:0] added_PC;
Core c(
.CLK(CLK), .Rd(Rd), .Rt(Rt), .Rs(Rs), .imm(imm), .addedPC(added_PC),
.RegDst(RegDst), .RegWr(RegWr), .MemWr(MemWr),
.ALUSrc(ALUSrc), .MemToReg(MemToReg), .ALUCntrl(ALUCtrl),
.Da(Da), .isZero(isZero)
);

PC_Calc pc_calc(
.old_PC(PC), .isZero(isZero), .PCSel(PCSel), .AddSel(AddSel),
.Da(Da), .addr(addr), .imm(imm), .added_PC(added_PC), .new_PC(new_PC)
);


endmodule
Loading