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 control_unit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions week1/Week1_Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Program 1:
### Statement: Write an Assembly Program for addition of 2 words

### Name of file:COD-Lab/week1/program1.s

### Observation - Single Cycle
- 1)loading the data to the memory and storing that address in x10 register
2)loading the data to the register x11 & x12
3)adding the data and storing that result in x13 ans storing back to memory

### Register Mapping
- x10 : 0x10000000
- x11 : 0x12345678
- x12 : 0X23456789
- x13 : 0x3579be01

### Data Mapping
- 0x10000000 : 0x12345678
- 0x10000004 : 0x23456789
- 0x10000008 : 0x3579be01

# Program 2:
### Statement: Write an Assembly Program for addition of 2 half words

### Name of file:COD-Lab/week1/program2.s

### Observation - Single Cycle
- 1)loading the data to the memory and storing that address in x10 register
2)loading the data to the register x11 & x12
3)adding the data and storing that result in x13 ans storing back to memory

### Register Mapping
- x10 : 0x10000000
- x11 : 0x00001234
- x12 : 0X00002345
- x13 : 0x00003579

### Data Mapping
- 0x10000000 : 0x23451234
- 0x10000004 : 0x00003579

# Program 3:
### Statement: Write an Assembly Program for addition of 2 bytes

### Name of file:COD-Lab/week1/program3.s

### Observation - Single Cycle
- 1)loading the data to the memory and storing that address in x10 register
2)loading the data to the register x11 & x12
3)adding the data and storing that result in x13 ans storing back to memory

### Register Mapping
- x10 : 0x10000000
- x11 : 0x00000002
- x12 : 0X0000000a
- x13 : 0x0000000c

### Data Mapping
- 0x10000000 : 0x000c0a02

# Program 4:
### Statement: Write an Assembly Program and analyse the format of storing signed and unsigned words, half words and byte data types

### Name of file:COD-Lab/week1/program4.s

### Observation - Single Cycle
- 1)# loading base address of a and b to x10 and x11
2)loading the unsigned data to the register x12 & x13
3)loading the signed data to the register x14 & x15

### Register Mapping
- x10 : 0x10000000
- x11 : 0x10000002
- x12 : 0X0000ffff
- x13 : 0x00000005
- x14 : 0xffffffff
- x15 : 0x00000005

### Data Mapping
- 0x10000000 : 0x0005ffff
8 changes: 8 additions & 0 deletions week1/program1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.data
a: .word 0x12345678 0x23456789
.text
la x10,a
lw x11,0(x10)
lw x12,4(x10)
add x13,x11,x12
sw x13,8(x10)
8 changes: 8 additions & 0 deletions week1/program2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.data
a: .half 0x1234 0x2345
.text
la x10,a
lh x11,0(x10)
lh x12,2(x10)
add x13,x11,x12
sh x13,4(x10)
8 changes: 8 additions & 0 deletions week1/program3.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.data
a: .byte 0x2 0xa
.text
la x10,a
lb x11,0(x10)
lb x12,1(x10)
add x13,x11,x12
sb x13,2(x10)
12 changes: 12 additions & 0 deletions week1/program4.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.data
a: .half -1 # creating a variable of type halfword
b: .byte 0x05 # creating a variable of byte type


.text
la x10,a # loading base address of a in x5
la x11,b # loading base address of b in x6
lhu x12,0(x10) # loading -1 as an unsignedd number: it gets stored as 0x0000ffff
lbu x13,0(x11) # loading 5 as aan unsigned number: it gets stored as 0x00000005
lh x14,0(x10) # loading -1 as a singned number: it gets stored as 0xffffffff
lb x15,0(x11) # loading 5 as a signed number: it gets stored as 0x00000005
11 changes: 11 additions & 0 deletions week10/PES2UG22EC046_Week10_Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Program 1:
### Statement:
Write a SV program for Control units

### Name of file:
control_unit.sv

### RTL Snapshot
![Screenshot of RTL view, full screen](https://github.com/ChethanReddyGN/COD-Lab/blob/102d07f723508e19992a674f0d8d35d03b4b6609/week10/control_unit.png)


Binary file added week10/control_unit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions week10/control_unit.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module control_unit (
input logic [6:0] opcode,
input logic [2:0] func3,
input logic [6:0] func7,
output logic wr_en,
output logic branch,
output logic alumux,
output logic [2:0] aluop,
output logic mem_read,
output logic mem_write,
output logic mem_reg,
output logic [2:0] width
);

always @(*) begin
wr_en = 1'b0;
branch = 1'b0;
alumux = 1'b0;
aluop = 3'b0000;
mem_read = 1'b0;
mem_write = 1'b0;
mem_reg = 1'b0;

case(opcode)
7'b0110011: begin // R-type
wr_en = 1'b1;
alumux = 1'b0;
mem_reg = 1'b0;
aluop = 3'b000;
mem_read = 1'b0;
mem_write = 1'b0;
branch = 1'b0;

end

7'b0010011: begin // I-type
wr_en = 1'b1;
alumux = 1'b1;
mem_reg = 1'b0;
aluop = 3'b001;
mem_read = 1'b0;
mem_write = 1'b0;
branch = 1'b0;
end

7'b0000011: begin // Load
wr_en = 1'b1;
alumux = 1'b1;
mem_read = 1'b1;
mem_write = 1'b0;
mem_reg = 1'b1;
aluop = 3'b010;
branch = 1'b0;
case (func3)
3'b000: width=3'b000;
3'b001: width=3'b001;
3'b010: width=3'b010;
3'b100: width=3'b011;
3'b101: width=3'b100;
endcase
end

7'b0100011: begin // Store
wr_en = 1'b0;
alumux = 1'b1;
mem_read = 1'b0;
mem_write = 1'b1;
mem_reg = 1'b0;
aluop = 3'b011;
branch = 1'b0;
case (func3)
3'b000: width=3'b000;
3'b001: width=3'b001;
3'b010: width=3'b010;
endcase
end

7'b1100011: begin // Branch
wr_en = 1'b0;
branch = 1'b1;
alumux = 1'b0;
aluop = 3'b100;
mem_read = 1'b0;
mem_write = 1'b0;


end

endcase
end
endmodule
34 changes: 34 additions & 0 deletions week3/PES2UG22EC046_Week3_Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Program 1:

### Statement:
Write an assembly program to check if a given number is a 2-out-of-5 number

### Name of file:
program1.s

### Observation - Explanation
- The program reads a binary number and checks for exactly two bits set to `1` among five bits.
- It uses bitwise operations to count the `1`s in the binary representation.
- Outputs whether the number is a valid 2-out-of-5 number.

### Snapshot
![Screenshot of RIPES window](program1.png)

---

# Program 2:
### Statement:
Write an assembly program to encode a given number using Hamming Code.

### Name of file:
program2.s

### Observation - Explanation
- The program calculates parity bits to ensure error detection and correction.
- It uses the Hamming Code algorithm to generate an encoded number with the appropriate parity bits.
- Outputs the encoded number for transmission or storage.

### Snapshot
![Screenshot of RIPES window](program2.png)

---
36 changes: 36 additions & 0 deletions week3/Week3_Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Program 1:
### Statement:
Convert a 32-bit value from Little Endian to Big Endian format using RISC-V assembly

### Name of file:
COD-Lab/week3/program1.s

### Observation - Single Cycle
- 1) loading the data of array a,b,c to the respective registers x10,x11,x17
- 2) Creating a loop that performs the little edian to big endian conversion
- 3) storing the values back into the memory

### Register Mapping
- x10: 0x10000000
- x11: 0x10000004
- x12: 0x00000000
- x13: 0x000000ff
- x14: 0x00000012
- x15: 0xfffffff8
- x17: 0x10000008
- x18: 0x10000007
- x19: 0xfffffff8

### Data Mapping
- 0x10000000: 0x78
- 0x10000001: 0x56
- 0x10000002: 0x34
- 0x10000003: 0x12
- 0x10000004: 0xff
- 0x10000005: 0x00
- 0x10000006: 0x00
- 0x10000007: 0x00
- 0x10000008: 0x12
- 0x10000009: 0x34
- 0x1000000a: 0x56
- 0x1000000b: 0x78
50 changes: 50 additions & 0 deletions week3/program1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.data
a: .byte 0x7,0xa,0x5,0x3,0x9
b: .byte 0,0,0,0,0

.text
la x10,a
la x11,b
addi x22,x10,0
addi x23,x11,0
addi x25,x0,5
addi x27,x0,1
loop:
addi x24,x0,0
lbu x24,0(x22)
addi x22,x22,1
addi x23,x23,1
addi x25,x25,-1
jal x1,subroutine
bne x20,x27,skip
sb x27,0(x23)
skip:
bne x25,x0,loop
beq x0,x0,exit3

subroutine:
addi x21,x23,0
andi x12,x21,0xE0
bne x12,x0,exit
addi x13,x0,5
addi x14,x0,0
addi x15,x0,2
addi x17,x0,0
back:
andi x16,x21,0x01
beq x16,x0,next
addi x17,x17,1
next:
srli x16,x16,1
addi x13,x13,-1
bne x13,x0,back
bne x17,x15,exit
addi x20,x0,0
addi x20,x20,1
beq x12,x0,exit2
exit:
addi x26,x0,2
exit2:
jalr x0,x1,0
exit3:
nop
32 changes: 32 additions & 0 deletions week3/program2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.data
a: .byte 0x55
.text
la x9,a
lbu x10,0(x9)
addi x11,x10,0
srli x12,x11,1 #x12=d1
srli x13,x11,2 #x13=d2
srli x14,x11,3 #x14=d3
srli x15,x11,4 #x15=d4
srli x16,x11,5 #x16=d5
srli x17,x11,6 #x15=d6
srli x18,x11,7 #x18=d7
xor x11,x11,x12 #d0 xor d1
xor x11,x11,x13 #xor with d3
xor x11,x11,x14 #xor with d4
xor x11,x11,x15 #xor with d6
andi x20,x11,1 #c0
addi x21,x10,0
xor x22,x21,x13 #d0 xor d2
xor x22,x22,x14 #xor with d3
xor x22,x22,x16 #xor with d5
xor x22,x22,x17 #xor with d6
andi x23,x22,1 #c1
xor x25,x12,x13 #d1 xor d2
xor x25,x25,x14 #xor with d3
xor x25,x25,x18 #xor with d7
andi x26,x25,1 #c2
xor x27,x15,x16 #d4 xor d5
xor x27,x27,x17 #xor with x6
xor x27,x27,x18 #xor with x7
andi x28,x27,1 #c3
Loading