I try to realize inline assemble(riscv32) command in one program C and use litex to create the project in vivado and generate bin file. In simulation, part ASM does work (memory position x'10000400 does have value x'40) but when I implement in card digilent basys3(replace bios by bin file), I find variable "key" equals 0 but not 64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <irq.h>
#include <libbase/uart.h>
#include <libbase/console.h>
#include <generated/csr.h>
int main(void)
{
#ifdef CONFIG_CPU_HAS_INTERRUPT
irq_setmask(0);
irq_setie(1);
#endif
uart_init();
int value = 64;
int key = 0;
int try_left;
int provide;
asm volatile (
"li t0, 0x10000400\n"
"sw %0, 0(t0)\n"
:
: "r" (value)
: "t0"
);
asm volatile (
"li t0, 0x10000400\n"
"lw %0, 0(t0)\n"
:
: "r" (key)
: "t0"
);
for (try_left=3;try_left>0;try_left--) {
printf("enter key:\n");
scanf("%d", &provide);
printf("enter %d and the key is %d\n", provide, key);
if (key==provide) {
try_left=3;
printf("good key\n");
return 0;
}
else printf("rest %d tries\n", try_left-1);
}
return 0;
}
I have tried also without inline ASM, code like this.
int key = 0;
volatile unsigned int *mem_ptr = (void*)0x10000000;
volatile unsigned int i;
for (i = 0; i < 2048; i++) {
mem_ptr = &i;
if (i==256) {
key = *mem_ptr;
}
mem_ptr += 4;
}
volatile unsigned int *sram_ptr = (void*)0x40000000;
volatile unsigned int j;
for (j = 0; j < 8192; j++) {
sram_ptr = &j;
sram_ptr+=4;
}
"key" get the value 256 but not associated with address x'10000400, also these two block memories are not initialized.