Skip to content

poonamkasturi/RISCV_VSD_SquadronMini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 

Repository files navigation

RISCV_VSD_SquadronMini

Lab exercises of RISCV workshop for October 20, 2024 cohort

Instructor : Kunal Ghosh

PRE-REQUISITE: Installing the required applications for the workshop - Virtual Box, Ubuntu on VBBOX and VDI files

TASK-1:

A: Write a simple C code and compile it with gcc comipler.

B: Compile the same code with RISCV comipler to generate the assembly code for the same. Further Evaluate RISCV assembly code for the sample C code with two different options of comiplation.

NECESSARY INSTALLATIONS

Step 1: Setting up the virtual environment to work on

  • Install Oracle Virtual Box, VMBox
  • Launch Virtual Machine on VMBox
  • Attach the VDI file to the Virtual Machine instance in VMBox

Step 2: Install Leafpad - the word editor

$    sudo apt install leafpad <br/>

TASK 1A - COMPILE AND EXECUTE A SIMPLE C CODE USING GCC COMPILER

$   cd <br/>                           Navigate to home directory:<br>
$   leafpad filename.c & <br/>         This opens a blank file with filename.c, type the c code
$   gcc filename.c <br>
$   ./a.out <br>

Change the value of n in filename.c
Recompile and see the results

TASK-1B: ASSEMBLY CODE ON RISCV COMPILER AND GCC COMPILER

$    cat sum1to9.c           --shows the content of the *.c file on the terminal tab <br>
$    riscv64-unknown-elf-gcc -O1 -mabl=lp64 -march=rv64i -o sum1to9.o sum1to9.c <br>       
               .. creates an object file for source file, before linking them together, into the final executable.<br>

To see the contents of the *.o object file

In a new tab (tab 2) execute the commands

$    riscv64-unknown-elf-objdump -d sum1to9.o <br>

To look into the assembly code generated by RISCV compiler execute the command

$    riscv64-unknown-elf-objdump -d sum1to9.o | less <br>

To look for the assembly code corresponding to main ()

type /main
Highlight main and press n to find where all it is

Find the Starting address of main and starting address of the next block
To find the total memory locations (space) taken by main subtract the two values. answer will be in hex
Convert the hex value to decimal (A)
No of instructions = A/4 (divide by 4 because each instruction is taking 4 bytes)

The number of assembly instructions generated is 15 with option -O1 for the c code used

Execute the command with -Ofast option in Tab 1

$    Riscv64-unknown-elf-gcc -Ofast -mabl=lp64 -march=rv64i -o sum1to9.o sum1to9.c <br>

Run the commands again In tab 2 to examine the assembly code generated
$ riscv64-unknown-elf-objdump -d sum1to9.o
$ riscv64-unknown-elf-objdump -d sum1to9.o | less

type /main
Highlight main and press n to find where all it is

Follow the steps to Find the memory space used as before

The number of assembly instructions generated is 12 with option -Ofast

About

Lab exercises of RISCV workshop by Kunal Ghosh

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published