diff --git a/control_unit.png b/control_unit.png new file mode 100644 index 00000000..6079e7ce Binary files /dev/null and b/control_unit.png differ diff --git a/week1/Week1_Lab.md b/week1/Week1_Lab.md new file mode 100644 index 00000000..62324d4b --- /dev/null +++ b/week1/Week1_Lab.md @@ -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 diff --git a/week1/program1.s b/week1/program1.s new file mode 100644 index 00000000..7e5dd584 --- /dev/null +++ b/week1/program1.s @@ -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) \ No newline at end of file diff --git a/week1/program2.s b/week1/program2.s new file mode 100644 index 00000000..ebe73d4c --- /dev/null +++ b/week1/program2.s @@ -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) \ No newline at end of file diff --git a/week1/program3.s b/week1/program3.s new file mode 100644 index 00000000..2bee84a1 --- /dev/null +++ b/week1/program3.s @@ -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) \ No newline at end of file diff --git a/week1/program4.s b/week1/program4.s new file mode 100644 index 00000000..5d5d0f30 --- /dev/null +++ b/week1/program4.s @@ -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 \ No newline at end of file diff --git a/week10/PES2UG22EC046_Week10_Lab.md b/week10/PES2UG22EC046_Week10_Lab.md new file mode 100644 index 00000000..a9a1f0c5 --- /dev/null +++ b/week10/PES2UG22EC046_Week10_Lab.md @@ -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) + + diff --git a/week10/control_unit.png b/week10/control_unit.png new file mode 100644 index 00000000..6079e7ce Binary files /dev/null and b/week10/control_unit.png differ diff --git a/week10/control_unit.sv b/week10/control_unit.sv new file mode 100644 index 00000000..b3807b85 --- /dev/null +++ b/week10/control_unit.sv @@ -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 diff --git a/week3/PES2UG22EC046_Week3_Lab.md b/week3/PES2UG22EC046_Week3_Lab.md new file mode 100644 index 00000000..49be935b --- /dev/null +++ b/week3/PES2UG22EC046_Week3_Lab.md @@ -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) + +--- diff --git a/week3/Week3_Lab.md b/week3/Week3_Lab.md new file mode 100644 index 00000000..68b8e5eb --- /dev/null +++ b/week3/Week3_Lab.md @@ -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 diff --git a/week3/program1.s b/week3/program1.s new file mode 100644 index 00000000..e90bf0da --- /dev/null +++ b/week3/program1.s @@ -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 \ No newline at end of file diff --git a/week3/program2.s b/week3/program2.s new file mode 100644 index 00000000..db4c58ca --- /dev/null +++ b/week3/program2.s @@ -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 \ No newline at end of file diff --git a/week4/program1.s b/week4/program1.s new file mode 100644 index 00000000..9e3c8ee3 --- /dev/null +++ b/week4/program1.s @@ -0,0 +1,35 @@ +.data +a: .asciz "racecar" # Input string +y: .byte 0 # Output for palindrome or not +.text +la x10,a +la x11,y +addi x25,x0,1 #for yes +addi x26,x0,0 #for no +lb x6,0(x10) +lb x7,1(x10) +lb x28,2(x10) +lb x29,3(x10) +lb x30,4(x10) +lb x31,5(x10) +lb x5,6(x10) +strcpy: + addi sp,sp,-4 + sw x25,0(sp) + add x25,x0,x0 +jal x1,func +func: + bne x6,x5,exit + bne x7,x31,exit + bne x28,x30,exit + addi x25,x25,1 + sb x25,0(x11) + beq x0,x0,exit1 +L2: + lw x25,0(sp) + addi sp,sp,4 + jalr x0,x0,0 +exit: + sb x26,0(x19) +exit1: + nop \ No newline at end of file diff --git a/week4/program2.s b/week4/program2.s new file mode 100644 index 00000000..9ac56c92 --- /dev/null +++ b/week4/program2.s @@ -0,0 +1,24 @@ +.data +a: .word 0x01223113, 0x45362727,0x33434343,0x11211212 +b: .word 0x45362727 + +.text +la x10,a #address of array +la x11,b #address of the no to searched + +lw x16,0(x11) #no to be searched + +addi x20,x0,4 #no o loops +addi x27,x0,0 + +loop: lw x12,0(x10) #loading the values of the array + beq x12,x16,exit #checking if no is present in array + addi x27,x27,1 #incrementing the loop + beq x27,x20,exit2 #cheching for the loop iteration i<4 + addi x10,x10,4 #incrementing the array address + beq x0,x0,loop + + +exit: addi x25,x0,1 #if x25 is 1 the no is present + +exit2: nop \ No newline at end of file diff --git a/week5/program1.s b/week5/program1.s new file mode 100644 index 00000000..0ed192dd --- /dev/null +++ b/week5/program1.s @@ -0,0 +1,42 @@ +.data +n: .word 0x000000009, 0x00009999 # Given number to check divisibility by 9 + +.text + +la x5, n # Load address of the number into x5 +lw x6, 0(x5) # Load the value of n into x6 +addi x7, x0, 0x0F # Mask for the lower 4 bits (0x0F = 00001111) +addi x28, x0, 0 # Initialize sum of digits to 0 +addi x29, x0, 8 # We have 8 digits to process (since 32-bit number, 8 digits of 4-bits) + +loop: + and x18, x7, x6 # Isolate the lower 4 bits of x6 (digit) + add x28, x28, x18 # Add the isolated digit to the sum + srli x6, x6, 4 # Right shift x6 by 4 to process the next digit + addi x29, x29, -1 # Decrement loop counter + bne x29, x0, loop # Repeat the loop if there are more digits to process + +new: + # Now we have the sum of the digits in x28 + # Check divisibility by subtracting 9 repeatedly + addi x30, x0, 9 # Load 9 into x30 for subtraction loop + +check_divisibility: + blt x28, x30, done # If sum is less than 9, exit loop + sub x28, x28, x30 # Subtract 9 from the sum + j check_divisibility # Repeat until sum is less than 9 + +done: + # If the final sum is 0, it's divisible by 9 + beq x28, x0, divisible + +not_divisible: + li x31, 0 # Set x31 to 0 (not divisible by 9) + j end + +divisible: + li x31, 1 # Set x31 to 1 (divisible by 9) + +end: + # x31 contains the result: 1 if divisible by 9, 0 otherwise + nop \ No newline at end of file diff --git a/week5/program2.s b/week5/program2.s new file mode 100644 index 00000000..3ed258fb --- /dev/null +++ b/week5/program2.s @@ -0,0 +1,30 @@ +.data +a: .half 0x1234, 0x5678, 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999 # Array a +b: .half 0x1234, 0x5678, 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999 # Array b +c: .half 0x1234, 0x5678, 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999 # Array c + +.text +main: + la x10, a # Load base address of array a into x10 + la x11, b # Load base address of array b into x11 + la x12, c # Load base address of array c into x12 + li x14, 10 # Loop counter (i = 0 to 9) + li x13, 0 # i = 0, loop index +loop: + beq x13, x14, exit # If i == 10, exit the loop + lh x15, 0(x10) # Load a[i] into x15 + lh x16, 0(x11) # Load b[i] into x16 + mul x17, x15, x16 # Multiply a[i] and b[i], result in x17 + beq x13, x0, first_iter # If i == 0, skip adding c[i-1] + lh x18, -2(x12) # Load c[i-1] into x18 + add x17, x17, x18 # Add c[i-1] to the result +first_iter: + sh x17, 0(x12) # Store result into c[i] + addi x10, x10, 2 # Move to a[i+1] + addi x11, x11, 2 # Move to b[i+1] + addi x12, x12, 2 # Move to c[i+1] + addi x13, x13, 1 # Increment loop index + j loop # Jump back to loop + +exit: + nop # Exit point