< 返回版块

QIUZHILEI 发表于 2023-11-30 19:58

Tags:inline-assembly

我想让这个函数能操作指定名称的寄存器,但是似乎asm!宏不支持?

pub fn csr_swap(csr: &str,val:u64) -> u64 {
    let value: u64 = 0;
    unsafe {
        asm!(
            "csrrw {0},{1},{2}",
            out(reg) value,
            csr,
            in(reg) val
        );
    }
    value
}

expected one of clobber_abi, const, in, inlateout, inout, lateout, options, out, or sym, found csr

评论区

写评论
vSylva 2023-12-01 01:57
pub fn csr_swap(csr: &str,val:u64) -> u64 {
    let value: u64 = 0;
    unsafe {
        std::arch::asm!(
            "csrrw {0},{1},{2}",
            out(reg) value,
            out(reg) csr,
            in(reg) val
        );
    }
    value
}

cannot use value of type &str for inline assembly only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assemblyrustcClick for full compiler diagnostic

1 共 1 条评论, 1 页