Write an ASM code #3
Replies: 3 comments 3 replies
-
It also seems difficult to pass or receive variables in an in-line assembly. The fundamental problem is that Rust's in-line assembly depends on the platform, and we are building the code somewhere other than Rust's platform. How can we solve this problem...? Rust #[inline(never)]
extern "C" fn test_asm() -> u8 {
return unsafe {
let e: u8;
asm!("ld {}, #0x0000", out(reg) e);
e
}
} LLVM ; out::test_asm
; Function Attrs: noinline nounwind
define internal fastcc noundef i8 @_ZN3out8test_asm17h09c831454c351d2dE() unnamed_addr addrspace(1) #0 {
start:
%0 = tail call addrspace(0) i8 asm sideeffect alignstack "ld ${0}, #0x0000", "=&a,~{sreg},~{memory}"() #5, !srcloc !1
ret i8 %0
} C static uint8_t _ZN3out8test_asm17h09c831454c351d2dE(void) {
__asm__ ("ld %ld ${00}, #0x0000, #0x0000");
return _1; //Error!
} Maybe it have to write an inline function in C and link it to Rust. |
Beta Was this translation helpful? Give feedback.
-
It seems reasonable to abandon the inline assembly, link the assembly file directly to the lcc, and use it like any other GBDK function. The next task is to create a simple assembly function that "writes a value to a particular address" and call it in Rust. If this is possible, all the other tasks dealing with hardware in Rust will be possible. |
Beta Was this translation helpful? Give feedback.
-
The assembly codes in the I will add the feature that can call assembly from inline Rust code with proc_macro, etc. |
Beta Was this translation helpful? Give feedback.
-
Considering the future project direction, it seems necessary to create an in-line assembly.
However, there is a slight difference between the inline assembly for SDCC and the inline assembly for GCC that LLVM-CBE generates, and the inline assembly in Rust cannot be compiled directly for now.
This Rust code, compiled to C in below form.
The problem is
volatile
.:
.So, it seems necessary to parse this phrase and then post-process it.
Beta Was this translation helpful? Give feedback.
All reactions