k0b0's record.

Computer Engineering, Arts and Books

Try RISC-V ISS (Instruction Set Simulator)(Compiling and assembling and dumping of RISC-V programs)

Compile and execute the program with RISC-V ISS.

Compile, assemble, and dump programs using RISC-V ISS.

The target program to be compiled

#include<stdio.h>
int main()
{
	printf("Hello World\n");
	return 0;
}

Compiling the program.

riscv64-unknown-elf-gcc -o hello hello.c

Execution of the program.

spike pk hello

Execution result

Hello World

Assemble the program with RISC-V ISS.

Assemble the program

riscv64-unknown-elf-gcc -S hello.c

Check the assembled file (hello.s).

	.file	"hello.c"
	.option nopic
	.section	.rodata
	.align	3
.LC0:
	.string	"Hello World"
	.text
	.align	1
	.globl	main
	.type	main, @function
main:
	addi	sp,sp,-16
	sd	ra,8(sp)
	sd	s0,0(sp)
	addi	s0,sp,16
	lui	a5,%hi(.LC0)
	addi	a0,a5,%lo(.LC0)
	call	puts
	li	a5,0
	mv	a0,a5
	ld	ra,8(sp)
	ld	s0,0(sp)
	addi	sp,sp,16
	jr	ra
	.size	main, .-main
	.ident	"GCC: (GNU) 7.2.0"

Dump programs with RISC-V ISS

 riscv64-unknown-elf-objdump -D hello