Skip to content

Reon-02/VSDSquadron-mini-internship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 

Repository files navigation

VSDSquadron-mini-internship

INSTRUCTOR:Kunal Gosh

LAB:1

Objectives

1:To write a C program to calculate the sum of numbers and to verify it using appropriate commands.

2:Compile the same code using the RISC-V compiler to generate its assembly code. Then, evaluate the RISC-V assembly code for the sample C program by using two different compilation options.

Project Setup

  • Install virtualbox
  • Launch the Virual box
  • Create a new Virtual Machine
  • Select Linux as the operating system and under version choose Ubuntu 18.04
  • Attach th VDI files to the machine
  • Start the machine

Task 1: Write and complile a C program

  • open a terminal
  • Install LeafPad,a simple text editor by running the following command
sudo-get install leafpad 
  • To navigate to the home directory,enter the following command
cd
  • To open a blank file for typing C program,enter the following command
leadfpad sum1ton.c

Screenshot from 2024-10-23 00-24-08

  • After writing the program,save it and return to the terminal and enter the following command
gcc sum1ton.c
./a.out

Screenshot from 2024-10-23 18-04-21

  • verify the result using a calculator
  • after verifying it go back to the editor and check the result for different values of n
  • recompile it and verify the output

Screenshot from 2024-10-23 17-58-22

Task 2:To compile the C code using RISC-V compiler

Step:1

  • To display the content of the C code in the terminal,use the following command
cat sum1ton.c

Screenshot from 2024-10-23 18-20-39

Step:2

  • To run the C code using RISC-V compiler and to generate the object file,enter the following command
riscv64-unknown-elf-gcc -O1 -mabi=lp64 -march=rv64i -o sum1ton.o sum1ton.c
ls -ltr sum1ton.o

Screenshot from 2024-10-23 20-24-15

Step:3

  • Create a new tab and enter the following command to generate the assembly code
riscv64 -unknown-elf-onjdump-d sum1ton.o

Screenshot from 2024-10-23 20-26-16

  • the system will generate huge assembly code
  • to get the main parts of the program, enter the following command
riscv64 -unknown-elf-objdump -d sum1ton.o | less

Screenshot from 2024-10-23 20-27-01

step:4

  • to focus on the main code , enter the following command and press"n"
/main

Screenshot from 2024-10-23 20-28-15

  • count the number of instructions and verify using programmable calculator

step:5

  • return to the terminal and enter the following command
riscv64-unknown-elf-gcc -Ofast -mabi=lp64 -march=rv64i -o sum1ton.o sum1ton.c
  • repeat the steps 3&4 Screenshot from 2024-10-23 20-31-40

LAB 03: Debugging RISC-V Assembly Program

Objectives

  • To compile and debug a C code in RISC-V and verify its output.

Step:1

  • Compile the following C code in the terminal
  #include<stdio.h>
  int main(){
  int i,sum=0,n=100;
  for(i=1;i<=n;++i){
  sum+=i;
  }
  printf("sum of numbers from 1  to %d is %d\n",n,sum);
  return 0;
  }

1

Step:2

  • Compile the code using the RISC-V compiler with the following command.
riscv64-unknown-elf-gcc -Ofast -mabi=lp64 -march=rv64i -o sum1ton.c sum1ton.o

Step:3

  • Execute on spike with the following command
  • This should yield the same results as before, verifying that the instructions are functioning correctly.
spike pk sum1ton.o

2

Step:4

  • First, open the objdump of the file using the following command.
riscv64-unknown-elf-objdump -d -sum1ton.o
riscv64-unknown-elf-objdump -d -sum1ton.o | less

3

  • To debug the assembly code, using Spike
spike -d pk sum1ton.o

Step:5

Set Prograam Counter for Debugging

  • To start debugging from a specific address, check the initial memory location of the first instruction. 3 -As indicated in the highlighted code above, this is the initial memory location of the first instruction
  • The command bash "until pc 0 bc100" is used to run the program counter until it reaches the first instruction
  • 4

Step:6

Inspect Register A2 Before and After Execution

-To find the content of a2, use the following command

reg 0 a2
  • It will start from the zero bit and press enter to run the next instruction 5
  • run the following command to get the content o of a2
reg 0 a2

1

  • Press enter to load the next instruction 2 -enter the following command and press enter to load the next instruction
reg 0 a0

4

-To retrieve the content of the stack pointer, enter the following command:

reg 0 sp

1

  • The "addi" instruction updates the stack pointer by adding an immediate value to it.
  • the command "addi sp,sp,16 decreases the stack pointer by 16 in decimal or 10 in hexadecimal

Step:6

-quit and enter the command

spike -d pk sum1ton.o
until pc 0 100b8
reg 0 b8

2 -enter the following command to look into stack pointer

reg 0 sp

-Using a calculator to confirm

0xffffffb50 - 0x10 = 0xffffffb40

Screenshot 2024-10-27 001322

  • the result confirms that the command successfully decrements the stack pointer register by 0*10.

LAB:03

Objectives

1) List various RISC-V instruction type (R, I, S, B, U, J) after going through RISC-V software documentation

2) Identify 15 unique RISC-V instructions from riscv-objdmp of your application code

3) Identify exact 32-bit instruction code in the instruction type format for 15 unique instructions

Task:1

- To list various RISC-V instruction types

  • RISC-V (Reduced Instruction Set Computer - V) instructions are the set of commands used in RISC-V processors to perform various operations, including arithmetic, data movement, control flow, and more. RISC-V instructions are designed to be simple, modular, and extensible, making it easy to customize for specific applications or add new features.
  • RISC-V instructions are divided into different categories based on functionality.

1. R-Type (Register-Register)

  • Purpose: Used for arithmetic and logical operations between two registers.
  • Format: opcode | rd | funct3 | rs1 | rs2 | funct7

Fields:

  • opcode: Operation type (7 bits)
  • rd: Destination register (5 bits)
  • funct3: Specifies the function (3 bits)
  • rs1: First source register (5 bits)
  • rs2: Second source register (5 bits)
  • funct7: Additional function code (7 bits)

2. I-Type (Immediate)

  • Purpose: Used for operations involving an immediate value (constant), such as load and arithmetic with constants.
  • Format: opcode | rd | funct3 | rs1 | immediate

Fields:

  • opcode: Operation type (7 bits)
  • rd: Destination register (5 bits)
  • funct3: Specifies the operation (3 bits)
  • rs1: Source register (5 bits)
  • immediate: Immediate value (12 bits, sign-extended)

3. S-Type (Store)

  • Purpose: Used for store operations, writing data from a register to memory.
  • Format: opcode | immediate[4:0] | funct3 | rs1 | rs2 | immediate[11:5]

Fields:

  • opcode: Operation type (7 bits)
  • funct3: Specifies the store type (3 bits)
  • rs1: Base address register (5 bits)
  • rs2: Source register to store (5 bits)
  • immediate: Split into two parts to form a 12-bit address offset (5+7 bits)

4. B-Type (Branch)

  • Purpose: Used for conditional branching, changing control flow based on comparisons.
  • Format: opcode | immediate[11] | immediate[4:1] | funct3 | rs1 | rs2 | immediate[10:5]

Fields:

  • opcode: Operation type (7 bits)
  • funct3: Specifies the branch condition (3 bits)
  • rs1, rs2: Registers to compare (5 bits each)
  • immediate: Split into multiple parts, sign-extended to 13 bits to specify the branch offset

5. U-Type (Upper Immediate)

  • Purpose: Used to handle large immediate values, mainly for setting the upper 20 bits of a register.
  • Format: opcode | rd | immediate[31:12]

Fields:

  • opcode: Operation type (7 bits)
  • rd: Destination register (5 bits)
  • immediate: Immediate value, upper 20 bits (20 bits)

6. J-Type (Jump)

  • Purpose: Used for unconditional jumps, typically for function calls.
  • Format: opcode | rd | immediate[20 | 10:1 | 11 | 19:12]

Fields:

  • opcode: Operation type (7 bits) rd: Register to store the return address (5 bits) immediate: 20-bit offset, sign-extended and reordered to specify the jump target address.

Task-2:To Identify 15 unique RISC-V instructions from riscv-objdmp of your application code

1.addi sp,sp,16
2.auipc a5, 0xFFFF0
3.sub a2, a2, a0
4.jal ra, 0x102EC
5.lw a0, 0(sp)
6.lbu a5, 1944(gp)
7.bnez a5, 0x1018C
9.sd ra, 8(sp)
10.xori a5, a5, -2000
11.slli a5, a3, 0x30
12.bqez a5, 101f4
13.bltu a3, a5, 138ac
14.ld a3, 16(a2)
15.add s1, s0, s1

Task-3

To Identify exact 32-bit instruction code in the instruction type format for 15 unique instructions

Task: To Identify Exact 32-Bit Instruction Code in Instruction Type Format

SL no Instruction Instruction Type 32-bit Instruction Code
1 addi sp, sp, 16 I-type 0x00108093
2 auipc a5, 0xFFFF0 U-type 0xFFFF0801
3 sub a2, a2, a0 R-type 0x40A30333
4 jal ra, 0x102EC J-type 0x102EC06F
5 lw a0, 0(sp) I-type 0x00010083
6 lbu a5, 1944(gp) I-type 0x79858103
7 bnez a5, 0x1018C B-type 0xF8E58063
8 sd ra, 8(sp) S-type 0x00E12023
9 xori a5, a5, -2000 I-type 0xFFFF8033
10 slli a5, a3, 0x30 R-type 0x03035013
11 bqez a5, 101F4 B-type 0x00128063
12 bltu a3, a5, 138AC B-type 0x02F38063
13 ld a3, 16(a2) I-type 0x01030303
14 add s1, s0, s1 R-type 0x00308233

About

Internship at VSD on RISC-V and VLSI using VSDSquadron Mini Board

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published