我尝试在一个C程序中实现inline assemble(riscv32)命令,并使用litex在vivado中创建工程并生成bin文件。在模拟中,部分 ASM 确实有效(内存位置 x'10000400 确实具有值 x'40)但是当我在 card digilent basys3 中实现(用 bin 文件替换 bios)时,我发现变量“key”等于 0 但不是 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;
}