Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ef2aeeb48
|
||
|
|
5cb48095ce
|
||
|
|
aab18425f9
|
No files matched your search
@@ -0,0 +1,51 @@
|
|||||||
|
// $File: NewcastleUniversity/ELEC4720/2026s2/src/Code/Assignment/Ass-02-Demo.txt $
|
||||||
|
// $Date: 2026-10-07 01:48:03 +1100 (Wed, 07 Oct 2026) $
|
||||||
|
// $Revision: 2523 $
|
||||||
|
// $Author: Peter $
|
||||||
|
//
|
||||||
|
// Course: ELEC4720(2026s2) Programmable Logic Design
|
||||||
|
// School: Engineering
|
||||||
|
// University: The University of Newcastle
|
||||||
|
// Address: CALLAGHAN NSW 2308 Australia
|
||||||
|
//
|
||||||
|
// Author: Dr Peter Stepien
|
||||||
|
// Email: peter.stepien@newcastle.edu.au
|
||||||
|
// Copyright: 2026
|
||||||
|
|
||||||
|
// Assignment 2 Demonstration Program (all instructions)
|
||||||
|
|
||||||
|
// main:
|
||||||
|
// Initialise some registers
|
||||||
|
01084023 // subu $t0, $t0, $t0
|
||||||
|
25090007 // addiu $t1, $t0, 7
|
||||||
|
|
||||||
|
// Memory operations
|
||||||
|
ad090000 // sw $t1, 0x0000($t0)
|
||||||
|
8d0a0000 // lw $t2, 0x0000($t0)
|
||||||
|
|
||||||
|
// Remaining arithmetic
|
||||||
|
012a5821 // addu $t3, $t1, $t2
|
||||||
|
012b6022 // sub $t4, $t1, $t3
|
||||||
|
212d0003 // addi $t5, $t1, 3
|
||||||
|
018d7020 // add $t6, $t4, $t5
|
||||||
|
|
||||||
|
// Logical
|
||||||
|
012d8024 // and $s0, $t1, $t5
|
||||||
|
012d8825 // or $s1, $t1, $t5
|
||||||
|
012d9026 // xor $s2, $t1, $t5
|
||||||
|
012d9827 // nor $s3, $t1, $t5
|
||||||
|
|
||||||
|
// Comparison
|
||||||
|
018ea02a // slt $s4, $t4, $t6
|
||||||
|
018ea82b // sltu $s5, $t4, $t6
|
||||||
|
|
||||||
|
// Loop to test branch
|
||||||
|
// loop:
|
||||||
|
25080001 // addiu $t0, $t0, 1
|
||||||
|
010db02b // sltu $s6, $t0, $t5
|
||||||
|
12d4fffd // beq $s6, $s4, loop
|
||||||
|
|
||||||
|
// Endless loop at end of program (FPGA)
|
||||||
|
// finish:
|
||||||
|
12d6ffff // beq $s6, $s6, finish
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# $File: NewcastleUniversity/ELEC4720/2026s2/src/Code/Assignment/Ass-02-Demo.s $
|
||||||
|
# $Date: 2026-10-07 01:54:03 +1100 (Wed, 07 Oct 2026) $
|
||||||
|
# $Revision: 2525 $
|
||||||
|
# $Author: Peter $
|
||||||
|
#
|
||||||
|
# Course: ELEC4720(2026s2) Programmable Logic Design
|
||||||
|
# School: Engineering
|
||||||
|
# University: The University of Newcastle
|
||||||
|
# Address: CALLAGHAN NSW 2308 Australia
|
||||||
|
#
|
||||||
|
# Author: Dr Peter Stepien
|
||||||
|
# Email: peter.stepien@newcastle.edu.au
|
||||||
|
# Copyright: 2026
|
||||||
|
|
||||||
|
# Assignment 2 Demonstration Program (all instructions)
|
||||||
|
|
||||||
|
.text
|
||||||
|
.globl main
|
||||||
|
.globl loop
|
||||||
|
.globl finish
|
||||||
|
|
||||||
|
main:
|
||||||
|
# Initialise some registers
|
||||||
|
subu $t0, $t0, $t0 # Set t0 = 0 (R8, modified below)
|
||||||
|
addiu $t1, $t0, 7 # Set t1 = 7 (R9)
|
||||||
|
|
||||||
|
# Memory operations
|
||||||
|
sw $t1, 0x10000000($t0) # Save t1 to memory (change to 0x0000 for FPGA)
|
||||||
|
lw $t2, 0x10000000($t0) # Load t2 from memory (change to 0x0000 for FPGA) (R10)
|
||||||
|
|
||||||
|
# Remaining arithmetic
|
||||||
|
addu $t3, $t1, $t2 # Unsigned t3 = t1 + t2 = 14 (R11)
|
||||||
|
sub $t4, $t1, $t3 # Signed t4 = t1 - t3 = -7 (R12)
|
||||||
|
addi $t5, $t1, 3 # Signed t5 = t1 + 3 = 10 (R13)
|
||||||
|
add $t6, $t4, $t5 # Signed t6 = t4 + t5 = 3 (R14)
|
||||||
|
|
||||||
|
# Logical (t1 = 0000..0111, t5 = 0000..1010)
|
||||||
|
and $s0, $t1, $t5 # s0 = t1 and t5 = 2 (0000..0010) (R16)
|
||||||
|
or $s1, $t1, $t5 # s1 = t1 or t5 = 15 (0000..1111) (R17)
|
||||||
|
xor $s2, $t1, $t5 # s2 = t1 xor t5 = 13 (0000..1101) (R18)
|
||||||
|
nor $s3, $t1, $t5 # s3 = t1 nor t5 = -16 (1111..0000) (R19)
|
||||||
|
|
||||||
|
# Comparison
|
||||||
|
slt $s4, $t4, $t6 # Signed s4 = t4 < t6 = 1 (true) (R20)
|
||||||
|
sltu $s5, $t4, $t6 # Unsigned s5 = t4 < t6 = 0 (false) (R21)
|
||||||
|
|
||||||
|
# Loop to test branch
|
||||||
|
loop:
|
||||||
|
addiu $t0, $t0, 1 # Increment counter
|
||||||
|
sltu $s6, $t0, $t5 # Unsigned s6 = t0 < t5 (Last 0) (R22)
|
||||||
|
beq $s6, $s4, loop # Loop if s6 == s4
|
||||||
|
|
||||||
|
# Endless loop at end of program (FPGA)
|
||||||
|
finish:
|
||||||
|
# beq $s6, $s6, finish # Endless loop
|
||||||
|
|
||||||
|
# Alternative system call to exit program (spim)
|
||||||
|
li $v0, 10
|
||||||
|
syscall
|
||||||
|
|
||||||
|
# END OF FILE
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
`ifndef INSTRUCTION_COUNTER_H
|
||||||
|
`define INSTRUCTION_COUNTER_H
|
||||||
|
|
||||||
|
module instruction_counter #(parameter width=5)(
|
||||||
|
input logic [0:0] clk, input logic [0:0] we,
|
||||||
|
input logic [2**width-1:0] W,
|
||||||
|
output logic [2**width-1:0] addr
|
||||||
|
);
|
||||||
|
|
||||||
|
logic [2**width-1:0] pc;
|
||||||
|
always_ff (@posedge clk) begin
|
||||||
|
if (we) begin
|
||||||
|
pc <= W
|
||||||
|
else
|
||||||
|
pc <= pc + 4;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assign addr = pc;
|
||||||
|
endmodule
|
||||||
|
`endif
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
`ifndef REGISTER_FILE_H
|
||||||
|
`define REGISTER_FILE_H
|
||||||
|
|
||||||
|
module register_file #(parameter width=5, parameter nregs=16)(
|
||||||
|
input logic [0:0] clk, input logic[0:0] we,
|
||||||
|
input logic [$clog(nregs)-1:0] A_W1, input logic [2**width-1:0] W1,
|
||||||
|
input logic [$clog(nregs)-1:0] A_R1, output logic [2**width-1:0] R1,
|
||||||
|
input logic [$clog(nregs)-1:0] A_R2, output logic [2**width-1:0] R2
|
||||||
|
);
|
||||||
|
localparam BW = 2**width;
|
||||||
|
logic [2**width-1:0] regs[nregs];
|
||||||
|
|
||||||
|
always_ff @(posedge clk) begin
|
||||||
|
if (we & (A_W1 != {(2**width){1'b0}} )) begin
|
||||||
|
regs[A_W1] <= W1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assign R1 = regs[A_R1];
|
||||||
|
assign R2 = regs[A_R2];
|
||||||
|
endmodule
|
||||||
|
`endif
|
||||||
Reference in new issue
Block a user