I added my own instruction for spike RISC-V like this tutorial. It said that I need to rebuild the toolchain which takes too long for me.
So I tried to find out how to use my instruction without rebuild the toolchain, and found from here that this can be used:
This directive permits the numeric representation of an instructions and makes the assembler insert the operands according to one of the instruction formats for ‘.insn’ (RISC-V-Formats). For example, the instruction ‘add a0, a1, a2’ could be written as ‘.insn r 0x33, 0, 0, a0, a1, a2’.
However, I tried the example to call add a0, a1, a2
using .insn r 0x33, 0, 0, a0, a1, a2
and it comes to an error message:
riscv64-unknown-elf-gcc hello.c myasm.S -o hello
myasm.S: Assembler messages:
myasm.S:8: Error: unknown pseudo-op: `.insn'
My assembler version
riscv64-unknown-elf-as --version
GNU assembler (GNU Binutils) 2.29
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `riscv64-unknown-elf'.
Is this because my toolchain? Or am I using the directive wrong?
Any help would be appreciated.
Hello.c
#include <stdio.h>
extern int aw(int x, int y);
int main() {
int result = 0;
result = aw(0xC0, 0x0B); //0xAB
printf("Result 0x%x\n",result);
return result;
}
myasm.S
.section .text
.global aw
.type aw, @function
aw:
.insn r 0x33, 0, 0, a0, a0, a1
ret