我想以 BYTE(8 位)或 HALF WORD(16 位)为单位操作内存加载或存储。
所以我制作了如下的C代码并使用“riscv32-unknown-elf-gcc”编译它。
void fun3 (void) {
char i,j;
i = (char)*(volatile unsigned int *) 0xf10007f8;
j = (char)*(volatile unsigned int *) 0xf10007f4;
*(volatile unsigned int *) 0xf10007f0 = (char) i+j;
*(volatile unsigned int *) 0xf10007fc = (int ) 0x4;
}
我编译如下,函数的de-asm代码如下。
riscv32-unknown-elf-gcc -march=rv32im -mabi=ilp32 -nostartfiles -nostdlib -Os -x c -Wl,-T,/work/test5.x -o test5.o test5.c
riscv32-unknown-elf-objdump -d -t test5.o > test5_Os.dump
f100006c <fun3>:
f100006c: f1000737 lui a4,0xf1000
f1000070: 7f872783 lw a5,2040(a4) # f10007f8 <__global_pointer$+0xffffeef0>
f1000074: 7f472683 lw a3,2036(a4)
f1000078: 0ff7f793 andi a5,a5,255
f100007c: 0ff6f693 andi a3,a3,255
f1000080: 00d787b3 add a5,a5,a3
f1000084: 7ef72823 sw a5,2032(a4)
f1000088: 00400793 li a5,4
f100008c: 7ef72e23 sw a5,2044(a4)
f1000090: 00008067 ret
我想在上面的汇编代码中将“lw”和“sw”转换为“lb”和“sb”。
如果你知道,请回答。