Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

QUERY REGARDING ADDING CUSTOM INSTRUCTIONS #355

@BhattSoham

Description

@BhattSoham

Hi all,
Good day. I tried to add custom instructions to RISCV ISA using the following link:
https://nitish2112.github.io/post/adding-instruction-riscv/
But, I have a question, that while running the code using asm volatile, why can't we use immediate operand in it?
Don't know if it's a basic question or not. But thought to ask it.

Suppose, I define a unused instruction:
mod rd rs1 rs2 31..25=1 14..12=0 6..2=0x1A 1..0=3.
So, while running the C code, do we have to write the code like this:
'
#include <stdio.h>

int main(){
int a,b,c;
a = 5;
b = 2;
asm volatile
(
"mod %[z], %[x], %[y]\n\t"
: [z] "=r" (c)
: [x] "r" (a), [y] "r" (b)
);

if ( c != 1 ){
printf("\n[[FAILED]]\n");
return -1;
}

printf("\n[[PASSED]]\n");

return 0;
}
'
Can we use the mod function like this in the code:
asm volatile
(
"mod %[z], %[x], %[y]\n\t"
: [z] "=r" (c)
: [x] "r" (a), [y] "m" (b)
);

RATHER

asm volatile
(
"mod %[z], %[x], %[y]\n\t"
: [z] "=r" (c)
: [x] "r" (a), [y] "r" (b)
);

Actually, my question is that, if the instruction is defined as
addi rd rs1 imm12 14..12=0 6..2=0x04 1..0=3
So, in case of 'imm12', do we need to use immediate operand only in this case, not register one?

And, if the instruction is assigned like this:
mod rd rs1 rs2 31..25=1 14..12=0 6..2=0x1A 1..0=3.
So, in this case of 'rs2', we have to use register operand only in the code, not immediate operand?

Your time and consideration is appreciated.

Thanks in advance!

Sincerely,
Soham.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions