PRE-REQUISITE: Installing the required applications for the workshop - Virtual Box, Ubuntu on VBBOX and VDI files
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.
- Install Oracle Virtual Box, VMBox
- Launch Virtual Machine on VMBox
- Attach the VDI file to the Virtual Machine instance in VMBox
$ sudo apt install leafpad <br/>
$ 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
$ 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>
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