Skip to content

Instantly share code, notes, and snippets.

@rbarzic
Created January 28, 2019 12:08
Show Gist options
  • Save rbarzic/b8482e6e76b6fea4e05720cb6e3da5ee to your computer and use it in GitHub Desktop.
Save rbarzic/b8482e6e76b6fea4e05720cb6e3da5ee to your computer and use it in GitHub Desktop.
riscv custom instruction in inline assembly
From https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/fONrcF2lxhQ/sb2ZN5Q_AQAJ
rohan:2183$ cat tmp.c
int
sub (int a, int b)
{
int result;
asm (".insn r 0x33, 0, 0, %0, %1, %2" : "=r" (result) : "r" (a), "r" (b));
return result;
}
rohan:2184$ riscv32-unknown-elf-gcc -O2 -c tmp.c
rohan:2185$ riscv32-unknown-elf-objdump -dr tmp.o
tmp.o: file format elf32-littleriscv
Disassembly of section .text:
00000000 <sub>:
0: 00b50533 add a0,a0,a1
4: 8082 ret
rohan:2186$
Jim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment