Learn with SHAKTI
My First C program
Open a file in text editor, Lets say hello.c is the C file.
vim hello.c
or
gedit hello.c
Write a simple C program to print Hello world (Copy paste the below content in it and save the file.)
Compile
Before starting compilation, Please check if the shakti-tools are installed.
riscv64-unknown-elf-gcc hello.c -o hello.elf
On successful compilation, a executable binary named hello.elf will be generated.
Run
The executable is ready. Now execute the program using spike and pk. spike is the hardware simulator that simulates RISC-V. pk is the proxy kernel, which provides drivers to use the peripherals.
spike $(which pk) hello.elf
Output:
Hello World
Object dump for the compiled C Program
objdump displays the assembly code contained in an elf file.
riscv64-unknown-elf-objdump -d hello.elf &> hello.dump
Use vim or gedit to view the objdump file created i.e hello.dump
vim hello.dump
or
gedit hello.dump