为什么上面这样不可以跳转,而下面这样可以跳转呢?
参数addr被调用的时候传参是0x40036000
离线
reset.c
#include <stdint.h>
void user_reset1(volatile uint32_t addr)
{
__asm("mv a1, a0");
}
void user_reset2(volatile uint32_t addr)
{
__asm("li a1, 0x40036000");
}
编译: riscv64-linux-gnu-gcc -c reset.c -g
反编译: riscv64-linux-gnu-objdump -S reset.o
reset.o: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <user_reset1>:
#include <stdint.h>
void user_reset1(volatile uint32_t addr)
{
0: 1101 addi sp,sp,-32
2: ec22 sd s0,24(sp)
4: 1000 addi s0,sp,32
6: 87aa mv a5,a0
8: fef42623 sw a5,-20(s0)
000000000000000c <.L0 >:
__asm("mv a1, a0");
c: 85aa mv a1,a0
000000000000000e <.L0 >:
}
e: 0001 nop
10: 6462 ld s0,24(sp)
12: 6105 addi sp,sp,32
14: 8082 ret
0000000000000016 <user_reset2>:
void user_reset2(volatile uint32_t addr)
{
16: 1101 addi sp,sp,-32
18: ec22 sd s0,24(sp)
1a: 1000 addi s0,sp,32
000000000000001c <.L0 >:
1c: 87aa mv a5,a0
1e: fef42623 sw a5,-20(s0)
0000000000000022 <.L0 >:
__asm("li a1, 0x40036000");
22: 400365b7 lui a1,0x40036
0000000000000026 <.L0 >:
}
26: 0001 nop
28: 6462 ld s0,24(sp)
000000000000002a <.L0 >:
2a: 6105 addi sp,sp,32
2c: 8082 ret
上面编译为:
__asm("mv a1, a0");
c: 85aa mv a1,a0
下面编译为:
0000000000000022 <.L0 >:
__asm("li a1, 0x40036000");
22: 400365b7 lui a1,0x40036
没看出来有什么区别, 路过的大佬说一说。
离线
__asm("mv a1, a0");测试:
__asm("li a1, 0x40036000");测试:
两种情况下的跳转现象:
1.
2.
离线
离线
还是一样,不能跳转
离线
离线
额,C语言跳转执行,没必要搞汇编,c也是很强大的,来函数强制转换就行,能用C还是用C吧, 不得已才用汇编,或者机器码。
/*
* This function copies SD/MMC card data to memory.
* always use EPLL source clock. this function works at 20Mhz.
*
* @param ch : HSMMC controller channel number
* @param sector : source card(SD/MMC) address (it must block address).
* @param count : number of blocks to copy.
* @param mem : memory to copy to.
* @param init : reinitialize or not.
* @return bool(u8_t) - success or failure.
*/
#define irom_sdmmc_to_mem(ch, sector, count, mem, init) \
(((u8_t(*)(s32_t, u32_t, u16_t, u32_t *, s32_t))(*((u32_t *)(0xd0037f98))))(ch, sector, count, mem, init))
离线