Simple RISC-V Assembly Instructions Verification
#1
Hello,

I am new to RISC-V and PULPissimo. So far, using the following Makefile, I have been able to generate C based test cases for verifying general C commands:

PULP_APP = test
PULP_APP_FC_SRCS = test.c
PULP_APP_HOST_SRCS = test.c

PULP_CFLAGS = -O3 -g
include $(PULP_SDK_HOME)/install/rules/pulp_rt.mk


When I am trying to add basic asm code as inline assembly in the C test, it provides error on those specific commands.

I added the following code in the test.c file:

asm( "mov r0, r0\n\t" 
     "mov r0, r0\n\t" 
     "mov r0, r0\n\t" 
     "mov r0, r0" );

I received the following errors:

test.c: Assembler messages:
test.c:15: Error: unrecognized opcode mov r0,r0'
test.c:16: Error: unrecognized opcodemov r0,r0'
test.c:17: Error: unrecognized opcode mov r0,r0'
test.c:18: Error: unrecognized opcodemov r0,r0'

Is there a simple way of adding inline assembly in C test cases, and verifying for example load and store instructions, or more instruction types? The compiler is able to run test.c file using the above Makefile method and I was hoping to keep that constant and work it around the inline assembly in a simple way.
Reply
#2
r0? Did you try x0? Also why would you move x0 to x0. x0 is always zero.
Reply
#3
(08-19-2020, 02:22 PM)bluewww Wrote: r0? Did you try x0? Also why would you move x0 to x0. x0 is always zero.

I think I noticed the problem, it was a simple thing, \n \t were missing, so maybe the console in Linux wasn't working.

I tried the following just a bunch of things, and the C test is now compiling,

asm volatile(
"lw     t0, 0(x2)\n\t"
"lw     t1, 4(x2)\n\t"
"sw     t1, 0(x2)\n\t"
"sw     t0, 4(x2)\n \t"
"add    t0, t1,    0x4\n \t"
"xor    t0, t1,    0x4\n \t"
"sb    t3, 0(a0)\n \t"
"add    x10, x10, x3\n \t"
);


But if try the following, it doesn't 'mov' and shows an error,

"mov    t3, 8(sp)\n \t"

Error: unrecognized opcode 'mov   t3, 8(sp)'

I am trying to maybe compare two register values or one register value to a stored variable value, and print either a pass or fail, so that I can verify the assembly instruction. I am trying to first print string the following way,

".LC0:        \n\t"
"    .string, pass\n\t"
"    .align, 2\n\t" 

But this shows : Error: junk at end of line, first unrecognized character is 'p'

I am still looking into the branch instructions of risc-v that are the C equivalent of if-else. Is there a simple way for the above verification that I mentioned?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)