Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added week1/little_end_2_big_end-5_stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1/little_end_2_big_end-single_cycle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions week1/week1-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.data
a:.word 0x12345678
.text
la x10,a
lw x11,0(x10)
andi x12,x11,0xFF
slli x12,x12,24

srli x13,x11,8
andi x13,x13,0xFF
slli x13,x13,16
add x12,x12,x13

srli x13,x11,16
andi x13,x13,0xFF
slli x13,x13,8
add x12,x12,x13

srli x13,x11,24
add x12,x12,x13
sw x12,0(x10)

39 changes: 39 additions & 0 deletions week1/week1-2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.data
a_low: .word 0x00000001 # Lower 32 bits of first 64-bit number (1)
a_high: .word 0x00000000 # Upper 32 bits of first 64-bit number (0)
b_low: .word 0x00000002 # Lower 32 bits of second 64-bit number (2)
b_high: .word 0x00000000 # Upper 32 bits of second 64-bit number (0)
result_low: .word 0 # To store the lower 32 bits of the result
result_high: .word 0 # To store the upper 32 bits of the result

.text
li x5, 0 # Start of main code

# Load the lower and higher 32 bits of the first number (a)
la x6, a_low # Load address of a_low into x6
lw x7, 0(x6) # Load a_low into x7 (lower 32 bits of a)
la x6, a_high # Load address of a_high into x6
lw x8, 0(x6) # Load a_high into x8 (upper 32 bits of a)

# Load the lower and higher 32 bits of the second number (b)
la x6, b_low # Load address of b_low into x6
lw x9, 0(x6) # Load b_low into x9 (lower 32 bits of b)
la x6, b_high # Load address of b_high into x6
lw x10, 0(x6) # Load b_high into x10 (upper 32 bits of b)

# Add the lower 32 bits
add x11, x7, x9 # Add lower 32 bits of a and b
mfhi x12 # Move carry (high part) from the addition

# Add the upper 32 bits with carry
add x13, x8, x10 # Add the upper 32 bits of a and b
add x13, x13, x12 # Add the carry from the lower 32-bit addition

# Store the results in result_low and result_high
la x6, result_low # Load address of result_low into x6
sw x11, 0(x6) # Store the lower 32 bits of the result in result_low
la x6, result_high # Load address of result_high into x6
sw x13, 0(x6) # Store the upper 32 bits of the result in result_high

# Exit (typically with an exit system call, but here it is just an infinite loop)
j x5 # Jump to x5 to create an infinite loop, ending the program
Binary file added week10/Alu_control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions week10/Alu_control.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Alu_control( input logic [1:0] ALUOp,
input logic [2:0] funct3,
input logic funct7_5,
output logic [3:0] ALUControl
);

always_comb begin
ALUControl = 4'b1111;

if (ALUOp == 2'b00) begin
ALUControl = 4'b0010; // ADD
end
else if (ALUOp == 2'b01) begin
ALUControl = 4'b0110; // SUB
end
else if (ALUOp == 2'b10) begin
case (funct3)
3'b000: ALUControl = funct7_5 ? 4'b0110 : 4'b0010; // SUB if funct7_5=1, ADD if funct7_5=0
3'b111: ALUControl = 4'b0000; // AND
3'b110: ALUControl = 4'b0001; // OR
default: ALUControl = 4'b1111; // Undefined
endcase
end
end
endmodule
Binary file added week10/Main_control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions week10/Main_control.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Main_control(input logic [6:0] opcode,
output logic regWrite, output logic ALUSrc,
output logic memRead,
output logic memWrite,
output logic branch,
output logic [1:0] ALUOp, output logic mem_reg
);

always_comb begin
regWrite = 0;
mem_reg=0;
ALUSrc = 0;
memRead = 0;
memWrite = 0;
branch = 0;
ALUOp = 2'b00;

case (opcode)
7'b0110011: begin // R-type instructions
regWrite = 1;
ALUOp = 2'b10;

end
7'b0010011: begin // I-type instructions
regWrite = 1;
ALUSrc = 1;
ALUOp = 2'b00;

end
7'b0000011: begin // Load instructions
regWrite = 1;
memRead = 1;
ALUSrc = 1;
mem_reg=1;
end
7'b0100011: begin // Store instructions
memWrite = 1;
ALUSrc = 1;
end
7'b1100011: begin // Branch instructions
branch = 1;
ALUOp = 2'b01;
end
default: begin
regWrite=0;
ALUSrc=0;
memRead=0;
memWrite=0;
branch=0;
ALUOp=0;
end
endcase
end
endmodule
70 changes: 70 additions & 0 deletions week2/Week2_Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Program 1:
### Statement:Write an Assembly Program for the following C code:
main() {
unsigned short int a[11] = {0x1234, 0x5678, ...}, h;
h = 0;
for(i = 0; i < 10; i++)
{
h = h + a[i];
}
a[10] = h;
};
### Name of file:
prog1.s

### Observation - Single Cycle
- The code adds two 64-bit integers stored in an array a. It splits each 64-bit integer into upper and lower 32-bit halves, performs addition on the lower halves, and then on the upper halves, accounting for any carry from the lower half addition. The results are stored back in memory at specified offsets in the array a, with the final carry stored separately.


### Register Mapping
- x11:0xffffffff
x12:0xffffffff
x13:0xffffffff
x14:0xffffffff
x15:0xfffffffe
x16:0x00000001
x17:0xfffffffe
x18:0x00000001
x19:0xffffffff
### Data Mapping
- 0x10000018:0x00000001
0x10000014:0xffffffff
0x10000010:0xfffffffe
0x1000000c:0xffffffff
0x10000008:0xffffffff
0x10000004:0xffffffff
0x10000000:0xffffffff;


# Program 2: Write an Assembly Program for addition of 2 64-bit numbers on RV32I

### Name of file:
prog2.s
### Observation - Single Cycle
*) The elements from two arrays `a` and `b` and stores the results in a third array `c`.
*) It iteratively loads elements from `a` and `b`, performs the addition, and stores the result back into `c`. The code processes five elements, using offsets to access each element in the arrays. The final state of array `c` contains the sums of the respective elements from `a` and `b`.

### Register Mapping
x11:10000014
x12:10000028
x13:10000004
x14:0x200004
x15:0x300008


### Data Mapping
-0x10000038:0x30000008
0x10000034:0x30000006
0x10000030:0x30000004
0x1000002c:0x30000002
0x10000028:0x33333333
0x10000024:0x20000004
0x10000020:0x20000003
0x1000001c:0x20000002
0x10000018:0x20000001
0x10000014:0x22222222
0x10000010:0x10000004
0x1000000c:0x10000003
0x10000008:0x10000002
0x10000004:0x10000001
0x10000000:0x11111111
Binary file added week2/add- 5stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week2/add-single_cycle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions week2/program1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.data
a: .dword 0xffffffffffffffff,0xffffffffffffffff
.text
la x10, a
lw x11,0(x10) #first lower
lw x12,4(x10) #first upper
lw x13,8(x10) #second lower
lw x14,12(x10) #second upper
add x15,x11,x13 #adding uppers
sltu x16,x15,x13 #lower carry
add x17,x12,x14 #adding uppers
sltu x18,x17,x14 #final carry
add x19,x16,x17 #adding uppers and lower carry

sw x15,16(x10) #store LSB of result
sw x19,20(x10) #store MSB of result
sw x18,24(x10) #store final carry
33 changes: 33 additions & 0 deletions week2/program2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.data
a: .word 0x11111111,0x10000001,0x10000002,0x10000003,0x10000004
b: .word 0x22222222,0x20000001,0x20000002,0x20000003,0x20000004
c: .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
.text
la x10,a
la x11,b
la x12,c

lw x13,0(x10)#a[1]
lw x14,0(x11)#b[1]
add x15,x13,x14
sw x15,0(x12)#c[1]

lw x13,4(x10)#a[2]
lw x14,4(x11)#b[2]
add x15,x13,x14
sw x15,4(x12)#c[2]

lw x13,8(x10)#a[3]
lw x14,8(x11)#b[3]
add x15,x13,x14
sw x15,8(x12)#c[3]

lw x13,12(x10)#a[4]
lw x14,12(x11)#b[4]
add x15,x13,x14
sw x15,12(x12)#c[4]

lw x13,16(x10)#a[5]
lw x14,16(x11)#b[5]
add x15,x13,x14
sw x15,16(x12)#c[5]
Binary file added week2/silly_fun-singlecycle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week2/sillyfunc-5stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions week2/week2-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.data
words: .word 5, 10, 15, 20, 25 # Array of 5 words (32-bit)
halfwords: .half 100, 200, 300, 400, 500 # Array of 5 half-words (16-bit)
bytes: .byte 1, 2, 3, 4, 5 # Array of 5 bytes (8-bit)

n: .word 5 # Number of elements (N)

.text
li x5, 0 # Initialize sum to 0 (for words, half-words, and bytes)
la x6, n # Load address of N
lw x7, 0(x6) # Load the value of N into x7 (N = 5)

# Addition of N Words (32-bit)
la x8, words # Load address of words array into x8
li x9, 0 # Initialize sum of words (32-bit) to 0

word_addition_loop:
lw x10, 0(x8) # Load word from address x8
add x9, x9, x10 # Add the word to the sum
addi x8, x8, 4 # Move to the next word (4 bytes)
addi x7, x7, -1 # Decrement N
bnez x7, word_addition_loop # Repeat until N = 0

# Store the result of word addition
la x6, result_word # Store the result in result_word
sw x9, 0(x6)

# Reset N and x7
la x6, n # Load address of N
lw x7, 0(x6) # Reload N

# Addition of N Half-Words (16-bit)
la x8, halfwords # Load address of half-words array into x8
li x9, 0 # Initialize sum of half-words (16-bit) to 0

halfword_addition_loop:
lh x10, 0(x8) # Load half-word from address x8
add x9, x9, x10 # Add the half-word to the sum
addi x8, x8, 2 # Move to the next half-word (2 bytes)
addi x7, x7, -1 # Decrement N
bnez x7, halfword_addition_loop # Repeat until N = 0

# Store the result of half-word addition
la x6, result_halfword # Store the result in result_halfword
sh x9, 0(x6)

# Reset N and x7
la x6, n # Load address of N
lw x7, 0(x6) # Reload N

# Addition of N Bytes (8-bit)
la x8, bytes # Load address of bytes array into x8
li x9, 0 # Initialize sum of bytes (8-bit) to 0

byte_addition_loop:
lb x10, 0(x8) # Load byte from address x8
add x9, x9, x10 # Add the byte to the sum
addi x8, x8, 1 # Move to the next byte (1 byte)
addi x7, x7, -1 # Decrement N
bnez x7, byte_addition_loop # Repeat until N = 0

# Store the result of byte addition
la x6, result_byte # Store the result in result_byte
sb x9, 0(x6)

# End of program, infinite loop
exit:
j exit

.data
result_word: .word 0 # To store the result of word addition
result_halfword: .half 0 # To store the result of half-word addition
result_byte: .byte 0 # To store the result of byte addition
55 changes: 55 additions & 0 deletions week2/week2-2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.data
y: .word 10 # Value of y
m: .word 20 # Value of m
L: .word 30 # Value of L
D: .word 5 # Value of D
Z: .word 50 # Value of Z
C: .word 40 # Value of C
x: .word 0 # To store the result (x)

.text

# Load values into registers
la x1, y # Load address of y
lw x2, 0(x1) # Load value of y into x2

la x3, m # Load address of m
lw x4, 0(x3) # Load value of m into x4

# Calculate y + m
add x5, x2, x4 # x5 = y + m

la x6, L # Load address of L
lw x7, 0(x6) # Load value of L into x7

la x8, D # Load address of D
lw x9, 0(x8) # Load value of D into x9

# Calculate L - D
sub x10, x7, x9 # x10 = L - D

# Calculate (y + m) - (L - D)
sub x11, x5, x10 # x11 = (y + m) - (L - D)

la x12, Z # Load address of Z
lw x13, 0(x12) # Load value of Z into x13

la x14, C # Load address of C
lw x15, 0(x14) # Load value of C into x15

# Calculate Z + C
add x16, x13, x15 # x16 = Z + C

# Calculate ((y + m) - (L - D)) + (Z + C)
add x17, x11, x16 # x17 = ((y + m) - (L - D)) + (Z + C)

# Calculate ((y + m) - (L - D)) + (Z + C) - D
sub x18, x17, x9 # x18 = ((y + m) - (L - D)) + (Z + C) - D

# Store result in x
la x19, x # Load address of x
sw x18, 0(x19) # Store the result of the calculation in x

# Exit the program (system call for exit)
li a7, 10 # Exit system call
ecall
Binary file added week3/2outof5-5stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week3/2outof5-singlestage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week3/hamming 1stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week3/hamming 5stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading