Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
331 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
j start_program # so the address of loop is always fixed | ||
|
||
# =============================================== | ||
# The loop increments counter by 2 each cycle | ||
# a0 = initial counter | ||
# a1 = number of cycles | ||
loop1: | ||
addi $t0, $zero, 0 # internal counter | ||
loop1_int: | ||
addi $a0, $a0, 2 # increment counter | ||
addi $t0, $t0, 1 # count | ||
bne $t0, $a1, loop1_int | ||
j end_loop1 | ||
|
||
# address should be 24 | ||
loop2: | ||
addi $t0, $zero, 0 # internal counter | ||
loop2_int: | ||
addi $a0, $a0, 2 # increment counter | ||
addi $t0, $t0, 1 # count | ||
bne $t0, $a1, loop2_int | ||
j end_loop2 | ||
|
||
# =============================================== | ||
start_program: | ||
|
||
# Store the address of loop in register | ||
# so we can then branch to it | ||
addi $s0, $zero, 4 # 4 is the address of loop1 | ||
|
||
addi $a0, $zero, 0 # counter | ||
addi $a1, $zero, 2 # number of cycles | ||
|
||
addi $t0, $zero, 1 # not zero | ||
brn $s0 # should branch | ||
end_loop1: | ||
|
||
addi $s0, $zero, 24 # 24 is the address of loop2 | ||
addi $a0, $zero, 0 # counter | ||
addi $a1, $zero, 2 # number of cycles | ||
|
||
addi $t0, $zero, 0 # zero | ||
brn $s0 # should not branch | ||
end_loop2: | ||
|
||
|
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,34 @@ | ||
`include "_const.v" | ||
`include "_assert.v" | ||
|
||
module test_brn; | ||
reg error = 0; | ||
processor CPU(); | ||
|
||
initial begin | ||
$readmemb("tests/instructions/brn/brn_imem.dat", CPU.IFU.imemory.storage.bytes); | ||
|
||
repeat(6) @(posedge CPU.clk); | ||
|
||
`assertEq(CPU.registers.registers[`REG_S0], 32'd4) | ||
`assertEq(CPU.registers.registers[`REG_A0], 32'd0) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
`assertEq(CPU.registers.registers[`REG_T0], 32'd1) | ||
|
||
repeat(8) @(posedge CPU.clk); | ||
|
||
`assertEq(CPU.registers.registers[`REG_A0], 32'd4) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
|
||
repeat(9) @(posedge CPU.clk); | ||
|
||
// Should be unchanged since the branch was not taken | ||
`assertEq(CPU.registers.registers[`REG_S0], 32'd24) | ||
`assertEq(CPU.registers.registers[`REG_A0], 32'd0) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
|
||
|
||
`printResults | ||
end | ||
|
||
endmodule |
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,84 @@ | ||
00001011 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00000010 | ||
00000000 | ||
10000100 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100001 | ||
11111101 | ||
11111111 | ||
00000101 | ||
00010101 | ||
00010000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00000010 | ||
00000000 | ||
10000100 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100001 | ||
11111101 | ||
11111111 | ||
00000101 | ||
00010101 | ||
00010101 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000100 | ||
00000000 | ||
00010000 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00000100 | ||
00100000 | ||
00000010 | ||
00000000 | ||
00000101 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00010101 | ||
00000000 | ||
00000000 | ||
00000010 | ||
00011000 | ||
00000000 | ||
00010000 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00000100 | ||
00100000 | ||
00000010 | ||
00000000 | ||
00000101 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00010101 | ||
00000000 | ||
00000000 | ||
00000010 |
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,46 @@ | ||
j start_program # so the address of loop is always fixed | ||
|
||
# =============================================== | ||
# The loop increments counter by 2 each cycle | ||
# a0 = initial counter | ||
# a1 = number of cycles | ||
loop1: | ||
addi $t0, $zero, 0 # internal counter | ||
loop1_int: | ||
addi $a0, $a0, 2 # increment counter | ||
addi $t0, $t0, 1 # count | ||
bne $t0, $a1, loop1_int | ||
j end_loop1 | ||
|
||
# address should be 24 | ||
loop2: | ||
addi $t0, $zero, 0 # internal counter | ||
loop2_int: | ||
addi $a0, $a0, 2 # increment counter | ||
addi $t0, $t0, 1 # count | ||
bne $t0, $a1, loop2_int | ||
j end_loop2 | ||
|
||
# =============================================== | ||
start_program: | ||
|
||
# Store the address of loop in register | ||
# so we can then branch to it | ||
addi $s0, $zero, 4 # 4 is the address of loop1 | ||
|
||
addi $a0, $zero, 0 # counter | ||
addi $a1, $zero, 2 # number of cycles | ||
|
||
addi $t0, $zero, 0 # zero | ||
brz $s0 # should branch | ||
end_loop1: | ||
|
||
addi $s0, $zero, 24 # 24 is the address of loop2 | ||
addi $a0, $zero, 0 # counter | ||
addi $a1, $zero, 2 # number of cycles | ||
|
||
addi $t0, $zero, 1 # not zero | ||
brz $s0 # should not branch | ||
end_loop2: | ||
|
||
|
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,34 @@ | ||
`include "_const.v" | ||
`include "_assert.v" | ||
|
||
module test_brz; | ||
reg error = 0; | ||
processor CPU(); | ||
|
||
initial begin | ||
$readmemb("tests/instructions/brz/brz_imem.dat", CPU.IFU.imemory.storage.bytes); | ||
|
||
repeat(6) @(posedge CPU.clk); | ||
|
||
`assertEq(CPU.registers.registers[`REG_S0], 32'd4) | ||
`assertEq(CPU.registers.registers[`REG_A0], 32'd0) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
`assertEq(CPU.registers.registers[`REG_T0], 32'd0) | ||
|
||
repeat(8) @(posedge CPU.clk); | ||
|
||
`assertEq(CPU.registers.registers[`REG_A0], 32'd4) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
|
||
repeat(9) @(posedge CPU.clk); | ||
|
||
// Should be unchanged since the branch was not taken | ||
`assertEq(CPU.registers.registers[`REG_S0], 32'd24) | ||
`assertEq(CPU.registers.registers[`REG_A0], 32'd0) | ||
`assertEq(CPU.registers.registers[`REG_A1], 32'd2) | ||
|
||
|
||
`printResults | ||
end | ||
|
||
endmodule |
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,84 @@ | ||
00001011 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00000010 | ||
00000000 | ||
10000100 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100001 | ||
11111101 | ||
11111111 | ||
00000101 | ||
00010101 | ||
00010000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00000010 | ||
00000000 | ||
10000100 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100001 | ||
11111101 | ||
11111111 | ||
00000101 | ||
00010101 | ||
00010101 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00000100 | ||
00000000 | ||
00010000 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00000100 | ||
00100000 | ||
00000010 | ||
00000000 | ||
00000101 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00010100 | ||
00000000 | ||
00000000 | ||
00000010 | ||
00011000 | ||
00000000 | ||
00010000 | ||
00100000 | ||
00000000 | ||
00000000 | ||
00000100 | ||
00100000 | ||
00000010 | ||
00000000 | ||
00000101 | ||
00100000 | ||
00000001 | ||
00000000 | ||
00001000 | ||
00100000 | ||
00010100 | ||
00000000 | ||
00000000 | ||
00000010 |
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